From 8973a5c74083a1ef2cff1903ac9d6f05d6296997 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Fri, 26 May 2023 14:21:50 -0400 Subject: [PATCH 1/3] A better explanation for change in differentials. --- src/flamegraph/mod.rs | 32 +++++++++++++++++++------------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 0e0ee68d..073f74fe 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -626,21 +626,27 @@ 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, _) => "↑ added in new".to_string(), + (_, 0) => "↓ removed in new".to_string(), + (x, y) if x == y => "unchanged".to_string(), + (old, new) => { + let ratio = new as f64 / old as f64; + let direction = if ratio > 1.0 { '↑' } else { '↓' }; + format!("{} new = {:.3} × old", direction, ratio) + } + }; write!( buffer, - "{} ({} {}, {:.2}%; {:+.2}%)", - function, samples_txt, opt.count_name, pct, delta_pct + "{} ({} {}, {:.2}%; {})", + function, samples_txt, opt.count_name, pct, change ) } } From 4c6b42be0a4ca37c37feefca9957a1dbc8d09600 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 31 May 2023 14:25:58 -0400 Subject: [PATCH 2/3] Tweak to output. --- src/flamegraph/mod.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 073f74fe..0e3c42e7 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -634,19 +634,22 @@ where (samples - delta, samples) }; let change = match (old, new) { - (0, _) => "↑ added in new".to_string(), - (_, 0) => "↓ removed in new".to_string(), + (0, _) => "all newly added".to_string(), + (_, 0) => "were all removed".to_string(), (x, y) if x == y => "unchanged".to_string(), (old, new) => { - let ratio = new as f64 / old as f64; - let direction = if ratio > 1.0 { '↑' } else { '↓' }; - format!("{} new = {:.3} × old", direction, ratio) + 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}%; {})", - function, samples_txt, opt.count_name, pct, change + "{} ({} {} {}, {:.2}%)", + function, samples_txt, opt.count_name, change, pct ) } } From 3f7ed4233a0752377e1aaea771a65cfb723b5d5c Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Wed, 31 May 2023 14:40:10 -0400 Subject: [PATCH 3/3] "unchanged" is inaccurate for non-final frames, since Inferno doesn't calculate diff there for some reason. --- src/flamegraph/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 0e3c42e7..6357552d 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -636,7 +636,7 @@ where let change = match (old, new) { (0, _) => "all newly added".to_string(), (_, 0) => "were all removed".to_string(), - (x, y) if x == y => "unchanged".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")