From 73da14d9522dfeee53cfdba7a835657a7cfb3054 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Sat, 30 Nov 2019 18:53:43 -0600 Subject: [PATCH 1/4] add --total option. See https://github.com/brendangregg/FlameGraph/pull/14 and https://github.com/jonhoo/inferno/issues/17. The use case for this option is comparing multiple perf runs directly against one another. Specifying the # of samples to use for the total width means the individual rectangles in each graph can be directly compared to each other rather than being resized differently if one run finished more quickly than another. --- src/bin/flamegraph.rs | 5 +++++ src/flamegraph/mod.rs | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/bin/flamegraph.rs b/src/bin/flamegraph.rs index 0d895db4..76961d98 100644 --- a/src/bin/flamegraph.rs +++ b/src/bin/flamegraph.rs @@ -173,6 +173,10 @@ struct Opt { )] title: String, + /// Set total width to this many samples + #[structopt(long = "total", value_name = "UINT")] + total: Option, + /// Width of image #[structopt(long = "width", value_name = "UINT")] width: Option, @@ -210,6 +214,7 @@ impl<'a> Opt { // set style options options.subtitle = self.subtitle; + options.total_samples = self.total; options.image_width = self.width; options.frame_height = self.height; options.min_width = self.minwidth; diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 029202fe..19f3c5d4 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -12,6 +12,7 @@ mod merge; mod rand; mod svg; +use std::cmp; use std::fs::File; use std::io::prelude::*; use std::io::{self, BufReader}; @@ -142,6 +143,11 @@ pub struct Options<'a> { /// Defaults to None. pub subtitle: Option, + /// # of samples to size the flame graph width to + /// + /// Defaults to None, which means it will be determined by the input being charted. + pub total_samples: Option, + /// Width of the flame graph /// /// Defaults to None, which means the width will be "fluid". @@ -255,6 +261,7 @@ impl<'a> Default for Options<'a> { count_name: defaults::COUNT_NAME.to_string(), name_type: defaults::NAME_TYPE.to_string(), factor: defaults::FACTOR, + total_samples: Default::default(), image_width: Default::default(), notes: Default::default(), subtitle: Default::default(), @@ -408,8 +415,12 @@ where ))); } + let timemax = cmp::max(opt.total_samples.unwrap_or(time), time); + if opt.total_samples.unwrap_or(time) < time { + warn!("Specified --total {} is less than actual total {}, so ignored", opt.total_samples.unwrap(), time); + } + let image_width = opt.image_width.unwrap_or(DEFAULT_IMAGE_WIDTH) as f64; - let timemax = time; let widthpertime_pct = 100.0 / timemax as f64; let minwidth_time = opt.min_width / widthpertime_pct; From 7178a6701c42d26b488f3b557108378f08808723 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Sat, 30 Nov 2019 18:53:43 -0600 Subject: [PATCH 2/4] add --total option. See https://github.com/brendangregg/FlameGraph/pull/14 and https://github.com/jonhoo/inferno/issues/17. The use case for this option is comparing multiple perf runs directly against one another. Specifying the # of samples to use for the total width means the individual rectangles in each graph can be directly compared to each other rather than being resized differently if one run finished more quickly than another. --- src/bin/flamegraph.rs | 6 ++++++ src/flamegraph/mod.rs | 22 +++++++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/bin/flamegraph.rs b/src/bin/flamegraph.rs index 0d895db4..93b8d130 100644 --- a/src/bin/flamegraph.rs +++ b/src/bin/flamegraph.rs @@ -173,6 +173,10 @@ struct Opt { )] title: String, + /// Set total width to this many samples + #[structopt(long = "total", value_name = "UINT")] + total: Option, + /// Width of image #[structopt(long = "width", value_name = "UINT")] width: Option, @@ -210,6 +214,7 @@ impl<'a> Opt { // set style options options.subtitle = self.subtitle; + options.total_samples = self.total; options.image_width = self.width; options.frame_height = self.height; options.min_width = self.minwidth; @@ -365,6 +370,7 @@ mod tests { colors: Palette::from_str("purple").unwrap(), search_color: color::SearchColor::from_str("#203040").unwrap(), title: "Test Title".to_string(), + total_samples: None, image_width: Some(100), frame_height: 500, min_width: 90.1, diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 029202fe..55f14db6 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -142,6 +142,12 @@ pub struct Options<'a> { /// Defaults to None. pub subtitle: Option, + /// # of samples to size the flame graph width to. This is useful for comparing flame graphs + /// with different amounts of samples so the contents are sized relative to each other. + /// + /// Defaults to None, which means it will be determined by the input being charted. + pub total_samples: Option, + /// Width of the flame graph /// /// Defaults to None, which means the width will be "fluid". @@ -255,6 +261,7 @@ impl<'a> Default for Options<'a> { count_name: defaults::COUNT_NAME.to_string(), name_type: defaults::NAME_TYPE.to_string(), factor: defaults::FACTOR, + total_samples: Default::default(), image_width: Default::default(), notes: Default::default(), subtitle: Default::default(), @@ -408,8 +415,21 @@ where ))); } + // set # of samples used for the full width if argument specified is greater than the amount from the input provided + let timemax = match opt.total_samples { + None => time, + Some(total) => { + if total < time { + warn!("Specified --total {} is less than actual total {}, so ignored", total, time); + time + } + else { + total + } + } + }; + let image_width = opt.image_width.unwrap_or(DEFAULT_IMAGE_WIDTH) as f64; - let timemax = time; let widthpertime_pct = 100.0 / timemax as f64; let minwidth_time = opt.min_width / widthpertime_pct; From 41b0a6e51bc2f8dcd7ab2fdaf441018442a19976 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Sun, 1 Dec 2019 18:29:08 -0600 Subject: [PATCH 3/4] fix formatting --- src/flamegraph/mod.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 55f14db6..cc8d2540 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -142,7 +142,7 @@ pub struct Options<'a> { /// Defaults to None. pub subtitle: Option, - /// # of samples to size the flame graph width to. This is useful for comparing flame graphs + /// # of samples to size the flame graph width to. This is useful for comparing flame graphs /// with different amounts of samples so the contents are sized relative to each other. /// /// Defaults to None, which means it will be determined by the input being charted. @@ -420,10 +420,12 @@ where None => time, Some(total) => { if total < time { - warn!("Specified --total {} is less than actual total {}, so ignored", total, time); + warn!( + "Specified --total {} is less than actual total {}, so ignored", + total, time + ); time - } - else { + } else { total } } From 14f41683107a4fd7fea2314d4fefeb85a1f07781 Mon Sep 17 00:00:00 2001 From: Matthew Smith Date: Sun, 1 Dec 2019 18:36:48 -0600 Subject: [PATCH 4/4] fix formatting take 2 --- 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 cc8d2540..d0fa7f14 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -421,7 +421,7 @@ where Some(total) => { if total < time { warn!( - "Specified --total {} is less than actual total {}, so ignored", + "Specified --total {} is less than actual total {}, so ignored", total, time ); time