Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --total option. See https://github.com/brendangregg/FlameGraph/pu… #154

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions src/bin/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ struct Opt {
)]
title: String,

/// Set total width to this many samples
#[structopt(long = "total", value_name = "UINT")]
total: Option<usize>,

/// Width of image
#[structopt(long = "width", value_name = "UINT")]
width: Option<usize>,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
24 changes: 23 additions & 1 deletion src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ pub struct Options<'a> {
/// Defaults to None.
pub subtitle: Option<String>,

/// # 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<usize>,

/// Width of the flame graph
///
/// Defaults to None, which means the width will be "fluid".
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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;

Expand Down