Skip to content

Commit

Permalink
Add additional flamegraph tests (#67)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonrhansen authored and jonhoo committed Mar 1, 2019
1 parent 53ac6a5 commit 59a9dac
Show file tree
Hide file tree
Showing 21 changed files with 2,209 additions and 20 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Expand Up @@ -37,6 +37,7 @@ rand = "0.6.5"

[dev-dependencies]
pretty_assertions = "0.5"
testing_logger = "0.1.1"

[profile.release]
debug = true
Expand Down
4 changes: 4 additions & 0 deletions src/bin/flamegraph.rs
Expand Up @@ -22,6 +22,7 @@ struct Opt {
/// Collapsed perf output files. With no INFILE, or INFILE is -, read STDIN.
#[structopt(name = "INFILE", parse(from_os_str))]
infiles: Vec<PathBuf>,

/// Set color palette
#[structopt(
short = "c",
Expand All @@ -32,12 +33,15 @@ struct Opt {
)
)]
colors: Palette,

/// Set background colors. Gradient choices are yellow (default), blue, green, grey; flat colors use "#rrggbb"
#[structopt(long = "bgcolors")]
bgcolors: Option<BackgroundColor>,

/// Colors are keyed by function name hash
#[structopt(long = "hash")]
hash: bool,

/// Use consistent palette (palette.map)
#[structopt(long = "cp")]
cp: bool,
Expand Down
11 changes: 8 additions & 3 deletions src/flamegraph/mod.rs
Expand Up @@ -26,7 +26,6 @@ const YPAD1: usize = FONTSIZE * 3; // pad top, include title
const YPAD2: usize = FONTSIZE * 2 + 10; // pad bottom, include labels
const XPAD: usize = 10; // pad lefm and right
const FRAMEPAD: usize = 1; // vertical padding for frames
const PALETTE_FILE: &str = "palette.map";

/// Configure the flame graph.
#[derive(Debug)]
Expand Down Expand Up @@ -56,6 +55,11 @@ pub struct Options {
/// Sterling](https://github.com/brendangregg/FlameGraph/pull/25).
pub consistent_palette: bool,

/// If `consistent_palette` is set to `true` the palette will be stored in this file.
///
/// Defaults to "palette.map"
pub palette_file: String,

/// Assign extra attributes to particular functions.
///
/// In particular, if a function appears in the given map, it will have extra attributes set in
Expand Down Expand Up @@ -94,6 +98,7 @@ impl Default for Options {
fn default() -> Self {
Options {
title: "Flame Graph".to_string(),
palette_file: "palette.map".to_string(),
factor: 1.0,
colors: Default::default(),
bgcolors: Default::default(),
Expand Down Expand Up @@ -241,7 +246,7 @@ where
W: Write,
{
let mut palette_map = if opt.consistent_palette {
Some(color::PaletteMap::load(PALETTE_FILE)?)
Some(color::PaletteMap::load(&opt.palette_file)?)
} else {
None
};
Expand Down Expand Up @@ -510,7 +515,7 @@ where

if let Some(palette_map) = palette_map {
palette_map
.save(PALETTE_FILE)
.save(&opt.palette_file)
.map_err(quick_xml::Error::Io)?;
}

Expand Down
7 changes: 7 additions & 0 deletions tests/data/bad-lines/bad-lines.txt
@@ -0,0 +1,7 @@
cksum;_start;__libc_start_main;main;cksum 31
cksum;cksum 6
THIS IS A BAD LINE
cksum;cksum;__GI___fread_unlocked;_IO_file_xsgetn;_IO_file_read;entry_SYSCALL_64_fastpath_[k];sys_read_[k];vfs_read_[k];__vfs_read_[k];ext4_file_read_iter_[k] 1
cksum;main;cksum 19
noploop;[unknown] 2
noploop;main 274
1 change: 1 addition & 0 deletions tests/data/empty/empty.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added tests/data/empty/empty.txt
Empty file.
6 changes: 6 additions & 0 deletions tests/data/fractional-samples/fractional.txt
@@ -0,0 +1,6 @@
cksum;_start;__libc_start_main;main;cksum 31.23
cksum;cksum 6.1
cksum;cksum;__GI___fread_unlocked;_IO_file_xsgetn;_IO_file_read;entry_SYSCALL_64_fastpath_[k];sys_read_[k];vfs_read_[k];__vfs_read_[k];ext4_file_read_iter_[k] 1.4
cksum;main;cksum 19.0
noploop;[unknown] 2.567
noploop;main 274.321
6 changes: 6 additions & 0 deletions tests/data/fractional-samples/no-fractionals.txt
@@ -0,0 +1,6 @@
cksum;_start;__libc_start_main;main;cksum 31
cksum;cksum 6
cksum;cksum;__GI___fread_unlocked;_IO_file_xsgetn;_IO_file_read;entry_SYSCALL_64_fastpath_[k];sys_read_[k];vfs_read_[k];__vfs_read_[k];ext4_file_read_iter_[k] 1
cksum;main;cksum 19
noploop;[unknown] 2
noploop;main 274
6 changes: 6 additions & 0 deletions tests/data/fractional-samples/zero-fractionals.txt
@@ -0,0 +1,6 @@
cksum;_start;__libc_start_main;main;cksum 31.0
cksum;cksum 6.
cksum;cksum;__GI___fread_unlocked;_IO_file_xsgetn;_IO_file_read;entry_SYSCALL_64_fastpath_[k];sys_read_[k];vfs_read_[k];__vfs_read_[k];ext4_file_read_iter_[k] 1
cksum;main;cksum 19
noploop;[unknown] 2.0
noploop;main 274

0 comments on commit 59a9dac

Please sign in to comment.