Skip to main content

trellis_core/
debug.rs

1use crate::Graph;
2use core::fmt::Write;
3
4impl<C, O> Graph<C, O> {
5    /// Returns a deterministic text dump of graph metadata.
6    pub fn debug_dump(&self) -> String {
7        let mut out = String::new();
8        writeln!(&mut out, "Graph(revision={})", self.revision().get())
9            .expect("writing to String cannot fail");
10
11        writeln!(&mut out, "Scopes:").expect("writing to String cannot fail");
12        for scope in self.scopes() {
13            writeln!(
14                &mut out,
15                "  {:?} name={:?} parent={:?} closed={}",
16                scope.id(),
17                scope.debug_name(),
18                scope.parent(),
19                scope.is_closed()
20            )
21            .expect("writing to String cannot fail");
22        }
23
24        writeln!(&mut out, "Nodes:").expect("writing to String cannot fail");
25        for node in self.nodes() {
26            writeln!(
27                &mut out,
28                "  {:?} kind={:?} name={:?} scope={:?} deps={:?}",
29                node.id(),
30                node.kind(),
31                node.debug_name(),
32                node.owning_scope(),
33                node.dependencies().as_slice()
34            )
35            .expect("writing to String cannot fail");
36        }
37
38        writeln!(&mut out, "Dependency paths:").expect("writing to String cannot fail");
39        for node in self.nodes() {
40            for dependency in node.dependencies().as_slice() {
41                writeln!(&mut out, "  {dependency:?} -> {:?}", node.id())
42                    .expect("writing to String cannot fail");
43            }
44        }
45
46        writeln!(&mut out, "Resources:").expect("writing to String cannot fail");
47        for (key, owners) in &self.resource_owners {
48            writeln!(&mut out, "  {key:?} owners={owners:?}")
49                .expect("writing to String cannot fail");
50        }
51
52        writeln!(&mut out, "Outputs:").expect("writing to String cannot fail");
53        for output in self.outputs.values() {
54            writeln!(
55                &mut out,
56                "  {:?} name={:?} scope={:?} deps={:?}",
57                output.key(),
58                output.debug_name(),
59                output.scope(),
60                output.dependencies().as_slice()
61            )
62            .expect("writing to String cannot fail");
63        }
64
65        writeln!(&mut out, "Audit:").expect("writing to String cannot fail");
66        for entry in &self.audit.log {
67            writeln!(
68                &mut out,
69                "  tx={:?} revision={:?} event={:?}",
70                entry.transaction_id, entry.revision, entry.event
71            )
72            .expect("writing to String cannot fail");
73        }
74
75        out
76    }
77}