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..d0fa7f14 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,23 @@ 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;