Skip to content

Commit 7fd7bdc

Browse files
committed
feat(callgrind-utils): add to_flamegraph SVG export
Add CallGraph::to_flamegraph / to_flamegraph_file mirroring the existing to_json API, rendering a flamegraph SVG via the inferno crate. To weight frames by cost, the parser now captures per-function self cost and per-edge inclusive cost from the positions:/events: layout (first event column, e.g. Ir); costs live outside Node so identity/dedup is unchanged. redact() re-keys self costs onto redacted identities. Folding walks roots top-down, distributing each function's aggregated self cost across incoming paths in proportion to call inclusive cost; recursion and cycles are terminated via an on-path guard and budget pruning.
1 parent bdc4911 commit 7fd7bdc

9 files changed

Lines changed: 588 additions & 10 deletions

File tree

callgrind-utils/Cargo.lock

Lines changed: 143 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

callgrind-utils/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = "0.1.0"
44
edition = "2024"
55

66
[dependencies]
7+
inferno = { version = "0.12.6", default-features = false }
78
serde = { version = "1", features = ["derive"] }
89
serde_json = "1"
910
thiserror = "2"

callgrind-utils/src/error.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,14 @@ pub enum ToJsonError {
2121
#[error("I/O error: {0}")]
2222
Io(#[from] std::io::Error),
2323
}
24+
25+
/// Errors raised while rendering a `CallGraph` to a flamegraph SVG.
26+
#[derive(Debug, Error)]
27+
pub enum FlamegraphError {
28+
#[error("the graph carries no cost data (all self/inclusive costs are zero)")]
29+
NoCost,
30+
#[error("inferno flamegraph error: {0}")]
31+
Inferno(String),
32+
#[error("I/O error: {0}")]
33+
Io(#[from] std::io::Error),
34+
}

0 commit comments

Comments
 (0)