Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 5 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
13 changes: 12 additions & 1 deletion src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -142,6 +143,11 @@ pub struct Options<'a> {
/// Defaults to None.
pub subtitle: Option<String>,

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

Expand Down