diff --git a/flamegraph b/flamegraph index 57207afb..759b2108 160000 --- a/flamegraph +++ b/flamegraph @@ -1 +1 @@ -Subproject commit 57207afbe114e3d50c6c7aef93d3206ef76cf6e2 +Subproject commit 759b2108ac2f0b3e789bba79e63036737753ff4d diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index fb85459b..052a4784 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -616,21 +616,30 @@ where "{} ({} {}, {:.2}%)", function, samples_txt, opt.count_name, pct ), - // Special case delta == 0 so we don't format percentage with a + sign. - Some(delta) if delta == 0 => write!( - buffer, - "{} ({} {}, {:.2}%; 0.00%)", - function, samples_txt, opt.count_name, pct, - ), - Some(mut delta) => { - if opt.negate_differentials { - delta = -delta; - } - let delta_pct = (100 * delta) as f64 / (timemax as f64 * opt.factor); + Some(delta) => { + let samples = frame.end_time as isize - frame.start_time as isize; + let (old, new) = if opt.negate_differentials { + (samples, samples - delta) + } else { + (samples - delta, samples) + }; + let change = match (old, new) { + (0, _) => "all newly added".to_string(), + (_, 0) => "were all removed".to_string(), + (x, y) if x == y => "".to_string(), + (old, new) => { + let (ratio, compared_to) = if opt.negate_differentials { + (old as f64 / new as f64, "new") + } else { + (new as f64 / old as f64, "old") + }; + format!(" = {ratio:.3} × {compared_to} {}", opt.count_name) + } + }; write!( buffer, - "{} ({} {}, {:.2}%; {:+.2}%)", - function, samples_txt, opt.count_name, pct, delta_pct + "{} ({} {} {}, {:.2}%)", + function, samples_txt, opt.count_name, change, pct ) } }