pub struct Graph { /* private fields */ }Expand description
A handle to a computation graph.
Build one with from_yaml, attach output sinks with
add_poller (pull) or observe (push), then
start. Feed packets in through input; terminate by closing
the inputs (close_all_inputs) and waiting for the pipeline to
drain (wait_done).
Every method takes &self — the handle is shared, not cloned. Dropping it shuts the graph down
and joins the worker threads. After termination, reset puts the graph back to
a startable state while keeping already-opened kernel instances alive, so an expensive one-off
such as loading a model is not repeated.
Implementations§
Source§impl Graph
impl Graph
Sourcepub fn start(&self) -> Result<()>
pub fn start(&self) -> Result<()>
Start execution. A fatal Open error is retained and returned on subsequent attempts; missing required side packets may be supplied before retrying.
pub fn reset(&self) -> Result<()>
pub fn wait_done(&self) -> Result<()>
pub fn wait_until_idle(&self) -> Result<()>
Source§impl Graph
impl Graph
pub fn add_poller(&self, port: &str) -> Result<Poller>
Sourcepub fn add_poller_with_timestamp_bounds(&self, port: &str) -> Result<Poller>
pub fn add_poller_with_timestamp_bounds(&self, port: &str) -> Result<Poller>
Add an unbounded poller that also receives timestamp-bound events as empty packets.
pub fn add_poller_with_options( &self, port: &str, options: PollerOptions, ) -> Result<Poller>
Source§impl Graph
impl Graph
pub fn from_yaml(text: &str) -> Result<Self>
pub fn from_yaml_file(path: &str) -> Result<Self>
pub fn from_config(cfg: GraphConfig) -> Result<Self>
pub fn state(&self) -> State
pub fn inner(&self) -> &Arc<GraphInner> ⓘ
pub fn input(&self, port: &str) -> Result<Input>
pub fn close_input(&self, port: &str) -> Result<()>
pub fn close_all_inputs(&self)
pub fn cancel(&self)
Sourcepub fn wait_done_timeout(&self, timeout: Duration) -> Result<()>
pub fn wait_done_timeout(&self, timeout: Duration) -> Result<()>
Wait for completion, checking the timeout between delegated callbacks. A synchronous callback already executing on this thread cannot be preempted. Timing out leaves pending work available for a later wait or cancellation.
Sourcepub fn wait_until_idle_timeout(&self, timeout: Duration) -> Result<()>
pub fn wait_until_idle_timeout(&self, timeout: Duration) -> Result<()>
Wait for idle with a timeout checked between delegated callbacks. A synchronous callback already executing on this thread cannot be preempted.
pub fn pause(&self)
pub fn resume(&self)
pub fn is_paused(&self) -> bool
Sourcepub fn executor_names(&self) -> Vec<&str>
pub fn executor_names(&self) -> Vec<&str>
已定义的线程池名字(按 YAML 顺序)。
Sourcepub fn pump_step(&self) -> bool
pub fn pump_step(&self) -> bool
在当前宿主线程上执行至多一个委托任务,或推进一次关流。
事件循环型宿主可反复调用它主动推进 DelegatingExecutor,而不必进入阻塞接口。
Sourcepub fn pump_steps(&self, max_steps: usize) -> usize
pub fn pump_steps(&self, max_steps: usize) -> usize
在当前宿主线程最多推进 max_steps 个委托任务或关流步骤。
Sourcepub fn set_wakeup_callback<F>(&self, callback: F)
pub fn set_wakeup_callback<F>(&self, callback: F)
Install an edge-triggered event-loop wakeup callback.
The callback may run on any engine thread and must return quickly. It should only schedule
the host loop to call pump_step until it returns false.
§There is only one slot
A graph holds a single callback: installing again replaces the previous one rather than adding to it, and the notification is graph-global — it says “something progressed”, not which port produced output or which queue freed a slot.
So a host that wants several independent wakeup consumers (waiting for the run to finish, for a port to emit, for an input queue to drain) must fan out itself: one owner installs this callback and broadcasts to the waiters, each re-checking its own condition. Calling this a second time from elsewhere silently displaces the first callback, and the symptom is a graph that stops advancing — no error, no log.
Sourcepub fn clear_wakeup_callback(&self)
pub fn clear_wakeup_callback(&self)
Remove the event-loop wakeup callback.
Sourcepub fn observe<F>(&self, port: &str, f: F) -> Result<()>
pub fn observe<F>(&self, port: &str, f: F) -> Result<()>
推模式订阅输出口。回调在派发该包的线程上执行(可能是线程池线程)。
必须在 start 之前注册,否则会漏掉已产出的包。
Sourcepub fn observe_with_timestamp_bounds<F>(&self, port: &str, f: F) -> Result<()>
pub fn observe_with_timestamp_bounds<F>(&self, port: &str, f: F) -> Result<()>
推模式订阅输出口,同时接收以空包编码的时间戳边界事件。
Sourcepub fn counter_value(&self, name: &str) -> i64
pub fn counter_value(&self, name: &str) -> i64
算子自报计数器的当前值(按图隔离)。
Sourcepub fn counter_names(&self) -> Vec<String>
pub fn counter_names(&self) -> Vec<String>
已登记的计数器名。
取出图级共享状态的句柄 —— 它比 Graph 句柄活得久,
因此可以在图销毁之后仍然读取错误与计数器(测试与排障用)。
pub fn node_count(&self) -> usize
pub fn node_name(&self, i: usize) -> Option<&str>
pub fn input_port_names(&self) -> Vec<&str>
pub fn output_port_names(&self) -> Vec<&str>
Sourcepub fn queue_depth(&self, port: &str) -> Option<usize>
pub fn queue_depth(&self, port: &str) -> Option<usize>
指定边的积压包数(该边所有消费者输入队列之和)。
pub fn dropped_count(&self, port: &str) -> Option<u64>
pub fn dump(&self) -> String
Sourcepub fn to_dot(&self) -> String
pub fn to_dot(&self) -> String
导出 Graphviz DOT(拓扑 + 子图命名空间 cluster + 执行器/绑核图例)。见 GraphInner::to_dot。
Sourcepub fn to_dot_with_view(&self, view: DotView) -> String
pub fn to_dot_with_view(&self, view: DotView) -> String
导出指定详细程度的 Graphviz DOT。
Sourcepub fn to_dot_compact(&self) -> String
pub fn to_dot_compact(&self) -> String
带节点状态与核心统计的紧凑视图,适合大型图持续刷新。
Sourcepub fn to_dot_with_stats(&self) -> String
pub fn to_dot_with_stats(&self) -> String
同 to_dot,但在每个节点标签上标出运行统计
(处理数 · 平均延迟 · 收/发包数 · 队列峰值 · 错误数),并把填充色换成
按平均延迟的热力图(绿=快 → 红=慢)—— 一眼看出瓶颈在哪个节点。
可在图运行期间随时调用(统计是原子读的快照),不必等跑完。
注意:热力图占用了「按执行器上色」那一维,执行器仍以标签里的 @name 标出。
Sourcepub fn to_chrome_trace(&self) -> String
pub fn to_chrome_trace(&self) -> String
导出当前 trace 环内容为 Chrome Trace Event Format 的 JSON(chrome://tracing /
perfetto 可直接打开)。需在建图时设 trace_capacity > 0;未开启时返回合法的空
trace。见 GraphInner::to_chrome_trace。