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 flame chart mode #125

Merged
merged 5 commits into from
Jun 20, 2020
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]
### Added
- Flame chart mode. Flame charts put the passage of time on the x-axis instead of the alphabet. [#125](https://github.com/jonhoo/inferno/pull/125)

### Changed

Expand Down
15 changes: 15 additions & 0 deletions src/bin/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,14 @@ struct Opt {
/// Collapsed perf output files. With no PATH, or PATH is -, read STDIN.
#[structopt(name = "PATH", parse(from_os_str))]
infiles: Vec<PathBuf>,

/// Produce a flame chart (sort by time, do not merge stacks)
#[structopt(
long = "flamechart",
conflicts_with = "no-sort",
jonhoo marked this conversation as resolved.
Show resolved Hide resolved
conflicts_with = "reverse"
)]
flame_chart: bool,
}

impl<'a> Opt {
Expand Down Expand Up @@ -219,6 +227,11 @@ impl<'a> Opt {
options.no_javascript = self.no_javascript;
options.color_diffusion = self.color_diffusion;
options.reverse_stack_order = self.reverse;
options.flame_chart = self.flame_chart;

if self.flame_chart && self.title == defaults::TITLE {
options.title = defaults::CHART_TITLE.to_owned();
}

// set style options
options.subtitle = self.subtitle;
Expand Down Expand Up @@ -393,6 +406,7 @@ mod tests {
bgcolors: Some(color::BackgroundColor::Blue),
hash: true,
palette_map: Default::default(),
#[cfg(feature = "nameattr")]
jonhoo marked this conversation as resolved.
Show resolved Hide resolved
func_frameattrs: Default::default(),
direction: Direction::Inverted,
negate_differentials: true,
Expand All @@ -401,6 +415,7 @@ mod tests {
reverse_stack_order: true,
no_javascript: true,
color_diffusion: false,
flame_chart: false,
};

assert_eq!(options, expected_options);
Expand Down
15 changes: 9 additions & 6 deletions src/flamegraph/merge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ fn flow<'a, LI, TI>(

pub(super) fn frames<'a, I>(
lines: I,
suppress_sort_check: bool,
) -> quick_xml::Result<(Vec<TimedFrame<'a>>, usize, usize, usize)>
where
I: IntoIterator<Item = &'a str>,
Expand All @@ -127,12 +128,14 @@ where
continue;
}

if let Some(prev_line) = prev_line {
if prev_line > line {
return Err(quick_xml::Error::Io(io::Error::new(
io::ErrorKind::InvalidData,
"unsorted input lines detected",
)));
if !suppress_sort_check {
if let Some(prev_line) = prev_line {
if prev_line > line {
return Err(quick_xml::Error::Io(io::Error::new(
io::ErrorKind::InvalidData,
"unsorted input lines detected",
)));
}
}
}

Expand Down
20 changes: 16 additions & 4 deletions src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ pub mod defaults {
COLORS: &str = "hot",
SEARCH_COLOR: &str = "#e600e6",
TITLE: &str = "Flame Graph",
CHART_TITLE: &str = "Flame Chart",
FRAME_HEIGHT: usize = 16,
MIN_WIDTH: f64 = 0.1,
FONT_TYPE: &str = "Verdana",
Expand Down Expand Up @@ -238,12 +239,17 @@ pub struct Options<'a> {
/// useful visual cue of what to focus on, especially if you are showing
/// flamegraphs to someone for the first time.
pub color_diffusion: bool,

/// Produce a flame chart (sort by time, do not merge stacks)
///
/// Note that stack is not sorted and will be reversed
pub flame_chart: bool,
}

impl<'a> Options<'a> {
/// Calculate pad top, including title and subtitle
pub(super) fn ypad1(&self) -> usize {
let subtitle_height = if let Some(_) = self.subtitle {
let subtitle_height = if self.subtitle.is_some() {
self.font_size * 2
} else {
0
Expand Down Expand Up @@ -298,6 +304,7 @@ impl<'a> Default for Options<'a> {
reverse_stack_order: Default::default(),
no_javascript: Default::default(),
color_diffusion: Default::default(),
flame_chart: Default::default(),

#[cfg(feature = "nameattr")]
func_frameattrs: Default::default(),
Expand Down Expand Up @@ -408,15 +415,20 @@ where
}
let mut reversed: Vec<&str> = reversed.iter().collect();
reversed.sort_unstable();
merge::frames(reversed)?
merge::frames(reversed, false)?
} else if opt.flame_chart {
// In flame chart mode, just reverse the data so time moves from left to right.
let mut lines: Vec<&str> = lines.into_iter().collect();
lines.reverse();
merge::frames(lines, true)?
} else if opt.no_sort {
// Lines don't need sorting.
merge::frames(lines)?
merge::frames(lines, false)?
} else {
// Sort lines by default.
let mut lines: Vec<&str> = lines.into_iter().collect();
lines.sort_unstable();
merge::frames(lines)?
merge::frames(lines, false)?
};

if ignored != 0 {
Expand Down
Loading