Skip to main content

Graph

Struct Graph 

Source
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

Source

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.

Source

pub fn reset(&self) -> Result<()>

Source

pub fn wait_done(&self) -> Result<()>

Source

pub fn wait_until_idle(&self) -> Result<()>

Source§

impl Graph

Source

pub fn add_poller(&self, port: &str) -> Result<Poller>

Source

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.

Source

pub fn add_poller_with_options( &self, port: &str, options: PollerOptions, ) -> Result<Poller>

Source§

impl Graph

Source

pub fn from_yaml(text: &str) -> Result<Self>

Source

pub fn from_yaml_file(path: &str) -> Result<Self>

Source

pub fn from_config(cfg: GraphConfig) -> Result<Self>

Source

pub fn state(&self) -> State

Source

pub fn inner(&self) -> &Arc<GraphInner> ⓘ

Source

pub fn set_side_packet(&self, name: &str, pkt: Packet) -> Result<()>

注入常量输入。必须在 start 之前。

Source

pub fn input(&self, port: &str) -> Result<Input>

Source

pub fn close_input(&self, port: &str) -> Result<()>

Source

pub fn close_all_inputs(&self)

Source

pub fn cancel(&self)

Source

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.

Source

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.

Source

pub fn pause(&self)

Source

pub fn resume(&self)

Source

pub fn is_paused(&self) -> bool

Source

pub fn executor_names(&self) -> Vec<&str>

已定义的线程池名字(按 YAML 顺序)。

Source

pub fn is_idle(&self) -> bool

是否空闲:委托队列为空且所有执行器无在飞任务。

Source

pub fn pump_step(&self) -> bool

在当前宿主线程上执行至多一个委托任务,或推进一次关流。

事件循环型宿主可反复调用它主动推进 DelegatingExecutor,而不必进入阻塞接口。

Source

pub fn pump_steps(&self, max_steps: usize) -> usize

在当前宿主线程最多推进 max_steps 个委托任务或关流步骤。

Source

pub fn set_wakeup_callback<F>(&self, callback: F)
where F: Fn() + Send + Sync + 'static,

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.

Source

pub fn clear_wakeup_callback(&self)

Remove the event-loop wakeup callback.

Source

pub fn observe<F>(&self, port: &str, f: F) -> Result<()>
where F: Fn(&Packet) + Send + Sync + 'static,

推模式订阅输出口。回调在派发该包的线程上执行(可能是线程池线程)。

必须在 start 之前注册,否则会漏掉已产出的包。

Source

pub fn observe_with_timestamp_bounds<F>(&self, port: &str, f: F) -> Result<()>
where F: Fn(&Packet) + Send + Sync + 'static,

推模式订阅输出口,同时接收以空包编码的时间戳边界事件。

Source

pub fn counter_value(&self, name: &str) -> i64

算子自报计数器的当前值(按图隔离)。

Source

pub fn counter_names(&self) -> Vec<String>

已登记的计数器名。

Source

pub fn shared_for_inspection(&self) -> Arc<GraphShared> ⓘ

取出图级共享状态的句柄 —— 它比 Graph 句柄活得久, 因此可以在图销毁之后仍然读取错误与计数器(测试与排障用)。

Source

pub fn node_count(&self) -> usize

Source

pub fn node_name(&self, i: usize) -> Option<&str>

Source

pub fn input_port_names(&self) -> Vec<&str>

Source

pub fn output_port_names(&self) -> Vec<&str>

Source

pub fn queue_depth(&self, port: &str) -> Option<usize>

指定边的积压包数(该边所有消费者输入队列之和)。

Source

pub fn dropped_count(&self, port: &str) -> Option<u64>

Source

pub fn dump(&self) -> String

Source

pub fn to_dot(&self) -> String

导出 Graphviz DOT(拓扑 + 子图命名空间 cluster + 执行器/绑核图例)。见 GraphInner::to_dot。

Source

pub fn to_dot_with_view(&self, view: DotView) -> String

导出指定详细程度的 Graphviz DOT。

Source

pub fn to_dot_compact(&self) -> String

带节点状态与核心统计的紧凑视图,适合大型图持续刷新。

Source

pub fn to_dot_with_stats(&self) -> String

同 to_dot,但在每个节点标签上标出运行统计 (处理数 · 平均延迟 · 收/发包数 · 队列峰值 · 错误数),并把填充色换成 按平均延迟的热力图(绿=快 → 红=慢)—— 一眼看出瓶颈在哪个节点。

可在图运行期间随时调用(统计是原子读的快照),不必等跑完。 注意:热力图占用了「按执行器上色」那一维,执行器仍以标签里的 @name 标出。

Source

pub fn to_chrome_trace(&self) -> String

导出当前 trace 环内容为 Chrome Trace Event Format 的 JSON(chrome://tracing / perfetto 可直接打开)。需在建图时设 trace_capacity > 0;未开启时返回合法的空 trace。见 GraphInner::to_chrome_trace。

Source

pub fn node_stats(&self, i: usize) -> Option<NodeStatsSnapshot>

Source

pub fn input_queue_stats( &self, node: usize, port: usize, ) -> Option<InputQueueStatsSnapshot>

Trait Implementations§

Source§

impl Debug for Graph

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Drop for Graph

Source§

fn drop(&mut self)

在宿主放开句柄时就地关停线程池并 join。

必须在这里做,不能只依赖 GraphInner::drop:工作线程为了执行节点会 Weak::upgrade 出一个临时强引用,若宿主的 Arc 已先释放,最后一个引用就落在 工作线程手上 —— 于是 GraphInner::drop 在工作线程上运行,shutdown 变成 join 自己,得到 EDEADLK。先在宿主线程 join 完,worker 就不存在了。

Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Graph

§

impl !UnwindSafe for Graph

§

impl Freeze for Graph

§

impl Send for Graph

§

impl Sync for Graph

§

impl Unpin for Graph

§

impl UnsafeUnpin for Graph

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.