Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,10 @@ fn write_flamegraph(
output: Option<PathBuf>,
options: &mut inferno::flamegraph::Options<'_>,
) -> Result<PathBuf> {
// Zero-sized entries are omitted from folded stacks, and inferno writes an error SVG for empty input.
if stacks.is_empty() {
bail!("No disk usage to render as a flame graph");
}
let stacks = String::from_utf8(stacks).expect("folded stacks are valid UTF-8");
if let Some(path) = output {
let file = fs::File::create(&path)
Expand Down Expand Up @@ -1161,6 +1165,24 @@ mod tests {
);
}

#[test]
fn empty_flamegraphs_are_rejected_with_and_without_explicit_output() {
let dir = tempfile::tempdir().expect("temporary directory");
for output in [None, Some(dir.path().join("usage.svg"))] {
let error = write_flamegraph(
Vec::new(),
output,
&mut inferno::flamegraph::Options::default(),
)
.expect_err("empty stacks cannot be rendered");
assert_eq!(
error.to_string(),
"No disk usage to render as a flame graph"
);
}
assert_eq!(fs::read_dir(dir.path()).unwrap().count(), 0);
}

#[test]
fn writes_explicit_and_temporary_flamegraphs() {
let dir = tempfile::tempdir().expect("temporary directory");
Expand Down
Loading