Skip to main content

nuclei/rt/runtime/
stats.rs

1//! A snapshot of one runtime's counters: [`Runtime::stats`] and
2//! [`RuntimeHandle::stats`].
3
4use super::{Inner, Runtime, RuntimeHandle};
5use crate::stats::Stats;
6
7impl Inner {
8    /// The counts of this runtime's workers, by place, and of its blocking
9    /// pool.
10    fn stats(&self) -> Stats {
11        crate::rt::counters::runtime_snapshot(
12            self.workers.shards().map(|shard| shard.stats()),
13            self.pool.threads_now(),
14            self.pool.queued(),
15        )
16    }
17}
18
19impl Runtime {
20    /// A snapshot of this runtime's counters: [`Stats::shards`] lists its
21    /// workers (stopped ones included) by place, and the blocking counts are
22    /// its pool's. The errors of threads that run no shard and the receive
23    /// buffers missing are the process's, as in [`stats()`](crate::stats()):
24    /// they belong to no runtime. The shard of a thread inside this
25    /// runtime's `block_on` serves every runtime the thread enters, so only
26    /// [`stats()`](crate::stats()) lists it.
27    pub fn stats(&self) -> Stats {
28        self.inner.stats()
29    }
30}
31
32impl RuntimeHandle {
33    /// A snapshot of the counters of the handle's runtime; see
34    /// [`Runtime::stats`].
35    pub fn stats(&self) -> Stats {
36        self.inner.stats()
37    }
38}