tracing_calltree/
snapshot.rs1use crate::display::SnapshotDisplay;
2use crate::sample::TimingSample;
3use crate::stats::TimingStats;
4
5#[derive(Clone, Debug, Default, PartialEq, Eq)]
6#[cfg_attr(feature = "serde", derive(serde::Serialize))]
7#[non_exhaustive]
8pub struct CallTreeSnapshot {
9 pub roots: Vec<NodeSnapshot>,
10}
11
12impl CallTreeSnapshot {
13 pub fn display(&self) -> SnapshotDisplay<'_> {
14 SnapshotDisplay(self)
15 }
16}
17
18#[derive(Clone, Debug, PartialEq, Eq)]
19#[cfg_attr(feature = "serde", derive(serde::Serialize))]
20#[non_exhaustive]
21pub struct NodeSnapshot {
22 pub name: String,
23 pub target: String,
24 pub module_path: Option<String>,
25 pub line: Option<u32>,
26 pub total_calls: u64,
27 pub wall: TimingStats,
28 pub active: TimingStats,
29 pub suspended: TimingStats,
30 pub children: Vec<NodeSnapshot>,
31}
32
33impl NodeSnapshot {
34 pub(crate) fn from_samples(
35 name: String,
36 target: String,
37 module_path: Option<String>,
38 line: Option<u32>,
39 total_calls: u64,
40 samples: &[TimingSample],
41 children: Vec<NodeSnapshot>,
42 ) -> Self {
43 Self {
44 name,
45 target,
46 module_path,
47 line,
48 total_calls,
49 wall: TimingStats::from_nanos(samples.iter().map(|sample| sample.wall_ns)),
50 active: TimingStats::from_nanos(samples.iter().map(|sample| sample.active_ns)),
51 suspended: TimingStats::from_nanos(samples.iter().map(|sample| sample.suspended_ns())),
52 children,
53 }
54 }
55}