Skip to content

Commit

Permalink
Merge branch 'master' into generic-annotated-palette
Browse files Browse the repository at this point in the history
  • Loading branch information
asherkin committed Feb 26, 2021
2 parents de3f422 + 43ed780 commit 4caf2f3
Show file tree
Hide file tree
Showing 22 changed files with 3,333 additions and 310 deletions.
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Removed

## [0.10.3] - 2021-01-08
### Added
- Support jit annotations in collapse-perf for runtimes using the jitdump format. [#202](https://github.com/jonhoo/inferno/pull/202)

### Changed
- Decreased default minimum width from 0.1% to 0.01%. [#204](https://github.com/jonhoo/inferno/pull/204)
- Detect if STDOUT is a TTY and if it's not, use a `BufWriter` to avoid line buffering. [#206](https://github.com/jonhoo/inferno/pull/206)

## [0.10.2] - 2020-11-30
### Changed
- Support for invalid utf8 data in collapse. [#196](https://github.com/jonhoo/inferno/pull/196)
Expand Down Expand Up @@ -136,7 +144,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Moved to `IndexMap` and FNV hashing ([#127](https://github.com/jonhoo/inferno/pull/127))
- Moved CI to Azure DevOps Pipelines

[Unreleased]: https://github.com/jonhoo/inferno/compare/v0.10.2...HEAD
[Unreleased]: https://github.com/jonhoo/inferno/compare/v0.10.3...HEAD
[0.10.3]: https://github.com/jonhoo/inferno/compare/v0.10.2...v0.10.3
[0.10.2]: https://github.com/jonhoo/inferno/compare/v0.10.1...v0.10.2
[0.10.1]: https://github.com/jonhoo/inferno/compare/v0.10.0...v0.10.1
[0.10.0]: https://github.com/jonhoo/inferno/compare/v0.9.9...v0.10.0
Expand Down
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "inferno"
version = "0.10.2"
version = "0.10.3"
edition = "2018"
authors = ["Jon Gjengset <jon@thesquareplanet.com>"]

Expand Down Expand Up @@ -28,6 +28,7 @@ nameattr = ["indexmap"]

[dependencies]
ahash = "0.6"
atty = "0.2"
crossbeam-utils = { version = "0.8", optional = true }
crossbeam-channel = { version = "0.5", optional = true }
dashmap = { version = "3", optional = true }
Expand Down
2 changes: 1 addition & 1 deletion src/bin/collapse-dtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,5 @@ fn main() -> io::Result<()> {
}

let (infile, options) = opt.into_parts();
Folder::from(options).collapse_file(infile.as_ref(), io::stdout().lock())
Folder::from(options).collapse_file_to_stdout(infile.as_ref())
}
2 changes: 1 addition & 1 deletion src/bin/collapse-guess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,5 @@ fn main() -> io::Result<()> {
}

let (infile, options) = opt.into_parts();
Folder::from(options).collapse_file(infile.as_ref(), io::stdout().lock())
Folder::from(options).collapse_file_to_stdout(infile.as_ref())
}
2 changes: 1 addition & 1 deletion src/bin/collapse-perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,5 +112,5 @@ fn main() -> io::Result<()> {
}

let (infile, options) = opt.into_parts();
Folder::from(options).collapse_file(infile.as_ref(), io::stdout().lock())
Folder::from(options).collapse_file_to_stdout(infile.as_ref())
}
2 changes: 1 addition & 1 deletion src/bin/collapse-sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,5 @@ fn main() -> io::Result<()> {
}

let (infile, options) = opt.into_parts();
Folder::from(options).collapse_file(infile.as_ref(), io::stdout().lock())
Folder::from(options).collapse_file_to_stdout(infile.as_ref())
}
2 changes: 1 addition & 1 deletion src/bin/collapse-vtune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,5 @@ fn main() -> io::Result<()> {
}

let (infile, options) = opt.into_parts();
Folder::from(options).collapse_file(infile.as_ref(), io::stdout().lock())
Folder::from(options).collapse_file_to_stdout(infile.as_ref())
}
12 changes: 11 additions & 1 deletion src/bin/diff-folded.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,15 @@ fn main() -> io::Result<()> {
}

let (folded1, folded2, options) = opt.into_parts();
differential::from_files(options, folded1, folded2, io::stdout().lock())

if atty::is(atty::Stream::Stdout) {
differential::from_files(options, folded1, folded2, io::stdout().lock())
} else {
differential::from_files(
options,
folded1,
folded2,
io::BufWriter::new(io::stdout().lock()),
)
}
}
14 changes: 12 additions & 2 deletions src/bin/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ struct Opt {
)]
height: usize,

/// Omit functions smaller than <FLOAT> pixels
/// Omit functions smaller than <FLOAT> percent
#[structopt(
long = "minwidth",
default_value = &defaults::str::MIN_WIDTH,
Expand Down Expand Up @@ -297,9 +297,19 @@ fn main() -> quick_xml::Result<()> {
};

let (infiles, mut options) = opt.into_parts();

options.palette_map = palette_map.as_mut();

flamegraph::from_files(&mut options, &infiles, io::stdout().lock())?;
if atty::is(atty::Stream::Stdout) {
flamegraph::from_files(&mut options, &infiles, io::stdout().lock())?;
} else {
flamegraph::from_files(
&mut options,
&infiles,
io::BufWriter::new(io::stdout().lock()),
)?;
}

save_consistent_palette_if_needed(&palette_map, PALETTE_MAP_FILE).map_err(quick_xml::Error::Io)
}

Expand Down
3 changes: 2 additions & 1 deletion src/collapse/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ impl Occurrences {
}
}
}
writer.flush()?;
Ok(())
}
}
Expand Down Expand Up @@ -510,7 +511,7 @@ pub(crate) fn fix_partially_demangled_rust_symbol(symbol: &str) -> Cow<str> {
demangled.push_str("::");
rest = &rest[2..];
} else {
demangled.push_str(".");
demangled.push('.');
rest = &rest[1..];
}
} else if rest.starts_with('$') {
Expand Down
12 changes: 8 additions & 4 deletions src/collapse/guess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ impl Collapse for Folder {
W: io::Write,
{
let mut dtrace = {
let mut options = dtrace::Options::default();
options.nthreads = self.opt.nthreads;
let options = dtrace::Options {
nthreads: self.opt.nthreads,
..Default::default()
};
dtrace::Folder::from(options)
};
let mut perf = {
let mut options = perf::Options::default();
options.nthreads = self.opt.nthreads;
let options = perf::Options {
nthreads: self.opt.nthreads,
..Default::default()
};
perf::Folder::from(options)
};
let mut sample = sample::Folder::default();
Expand Down
10 changes: 3 additions & 7 deletions src/collapse/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,9 @@
#[inline]
pub fn is_vmlinux(s: &str) -> bool {
if let Some(vm) = s.rfind("vmlinux") {
s[vm..].chars().all(|c| {
c.is_ascii_alphanumeric()
|| match c {
'-' | '.' | '_' => true,
_ => false,
}
})
s[vm..]
.chars()
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '-' | '.' | '_'))
} else {
false
}
Expand Down
19 changes: 16 additions & 3 deletions src/collapse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,27 @@ pub trait Collapse {
self.collapse(reader, writer)
}
None => {
let stdio = io::stdin();
let stdio_guard = stdio.lock();
let reader = io::BufReader::with_capacity(CAPACITY_READER, stdio_guard);
let stdin = io::stdin();
let stdin_guard = stdin.lock();
let reader = io::BufReader::with_capacity(CAPACITY_READER, stdin_guard);
self.collapse(reader, writer)
}
}
}

/// Collapses the contents of the provided file (or of STDIN if `infile` is `None`) and
/// writes folded stack lines to STDOUT.
fn collapse_file_to_stdout<P>(&mut self, infile: Option<P>) -> io::Result<()>
where
P: AsRef<Path>,
{
if atty::is(atty::Stream::Stdout) {
self.collapse_file(infile, io::stdout().lock())
} else {
self.collapse_file(infile, io::BufWriter::new(io::stdout().lock()))
}
}

/// Returns whether this implementation is appropriate for the given input.
///
/// - `None` means "not sure -- need more input"
Expand Down
18 changes: 9 additions & 9 deletions src/collapse/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,12 @@ impl Folder {
// XXX: re-use existing memory in pname if possible
self.pname = comm.replace(' ', "_");
if self.opt.include_tid {
self.pname.push_str("-");
self.pname.push('-');
self.pname.push_str(pid);
self.pname.push_str("/");
self.pname.push('/');
self.pname.push_str(tid);
} else if self.opt.include_pid {
self.pname.push_str("-");
self.pname.push('-');
self.pname.push_str(pid);
}

Expand Down Expand Up @@ -519,8 +519,8 @@ impl Folder {
} else if self.opt.annotate_kernel && is_kernel(module) {
func.push_str("_[k]"); // kernel
} else if self.opt.annotate_jit
&& module.starts_with("/tmp/perf-")
&& module.ends_with(".map")
&& ((module.starts_with("/tmp/perf-") && module.ends_with(".map"))
|| (module.contains("/jitted-") && module.ends_with(".so")))
{
func.push_str("_[j]"); // jitted
}
Expand Down Expand Up @@ -548,7 +548,7 @@ impl Folder {
stack_str.push_str(&self.pname);
// add the other stack entries (if any)
for e in self.stack.drain(..) {
stack_str.push_str(";");
stack_str.push(';');
stack_str.push_str(&e);
}

Expand Down Expand Up @@ -587,15 +587,15 @@ fn with_module_fallback(module: &str, func: &str, pc: &str, include_addrs: bool)
let mut res = String::with_capacity(func.len() + 12);

if include_addrs {
res.push_str("[");
res.push('[');
res.push_str(func);
res.push_str(" <");
res.push_str(pc);
res.push_str(">]");
} else {
res.push_str("[");
res.push('[');
res.push_str(func);
res.push_str("]");
res.push(']');
}

res
Expand Down
6 changes: 3 additions & 3 deletions src/flamegraph/color/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -351,16 +351,16 @@ pub(super) fn color(
let mut hash: u64 = 0xcbf29ce484222325;
// https://github.com/servo/rust-fnv/blob/4b4784ebfd3332dc61f0640764d6f1140e03a9ab/lib.rs#L118-L121
for byte in name.as_bytes() {
hash = hash ^ (*byte as u64);
hash ^= *byte as u64;
hash = hash.wrapping_mul(0x100000001b3);
}
let hash1 = (hash as f64 / std::u64::MAX as f64) as f32;

// Rotate hash so we get two more distinct numbers
hash = hash ^ 0;
hash ^= 0;
hash = hash.wrapping_mul(0x100000001b3);
let hash2 = (hash as f64 / std::u64::MAX as f64) as f32;
hash = hash ^ 0;
hash ^= 0;
hash = hash.wrapping_mul(0x100000001b3);
let hash3 = (hash as f64 / std::u64::MAX as f64) as f32;

Expand Down
4 changes: 2 additions & 2 deletions src/flamegraph/color/palettes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ pub(super) mod java {
if name.contains("::") || name.starts_with("-[") || name.starts_with("+[") {
// C++ or Objective C
BasicPalette::Yellow
} else if java_prefix.contains("/")
|| (java_prefix.contains(".") && !java_prefix.starts_with("["))
} else if java_prefix.contains('/')
|| (java_prefix.contains('.') && !java_prefix.starts_with('['))
|| match java_prefix.chars().next() {
Some(c) => c.is_ascii_uppercase(),
_ => false,
Expand Down
3 changes: 2 additions & 1 deletion src/flamegraph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub mod defaults {
TITLE: &str = "Flame Graph",
CHART_TITLE: &str = "Flame Chart",
FRAME_HEIGHT: usize = 16,
MIN_WIDTH: f64 = 0.1,
MIN_WIDTH: f64 = 0.01,
FONT_TYPE: &str = "Verdana",
FONT_SIZE: usize = 12,
FONT_WIDTH: f64 = 0.59,
Expand Down Expand Up @@ -693,6 +693,7 @@ where
svg.write_event(Event::End(BytesEnd::borrowed(b"svg")))?;
svg.write_event(Event::Eof)?;

svg.into_inner().flush()?;
Ok(())
}

Expand Down
3 changes: 2 additions & 1 deletion tests/collapse-perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,8 @@ collapse_perf_tests! {
collapse_perf_single_event,
collapse_perf_go_stacks,
collapse_perf_java_inline,
collapse_perf_versioned_vmlinux__kernel
collapse_perf_versioned_vmlinux__kernel,
collapse_perf_sourcepawn_jitdump__jit
}

#[test]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
spshell;__libc_start_main;main;Execute;sp::ScriptedInvoker::Invoke;sp::PluginContext::Invoke;sp::Environment::Invoke;<jit invoke stub>_[j];fib.smx::main_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j];fib.smx::fib_[j] 1
36 changes: 36 additions & 0 deletions tests/data/collapse-perf/sourcepawn-jitdump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
spshell 31714 451945.594655: 22145531 cycles:
f719f4a4 fib.smx::fib+0x3c (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f50b fib.smx::fib+0xa3 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f54c fib.smx::fib+0xe4 (/tmp/jitted-31714-4145673320.so)
f719f119 fib.smx::main+0x91 (/tmp/jitted-31714-4145672328.so)
f719f06f <jit invoke stub>+0x27 (/tmp/jitted-31714-4145672264.so)
8059187 sp::Environment::Invoke+0x307 (/root/code/sourcepawn/build/vm/spshell/linux-x86/spshell)
806d5d8 sp::PluginContext::Invoke+0x378 (/root/code/sourcepawn/build/vm/spshell/linux-x86/spshell)
8078bcc sp::ScriptedInvoker::Invoke+0x60c (/root/code/sourcepawn/build/vm/spshell/linux-x86/spshell)
804b413 Execute+0x3d3 (/root/code/sourcepawn/build/vm/spshell/linux-x86/spshell)
804ae7e main+0x61e (/root/code/sourcepawn/build/vm/spshell/linux-x86/spshell)
f7abc8e9 __libc_start_main+0xf9 (/usr/lib/libc-2.29.so)

Loading

0 comments on commit 4caf2f3

Please sign in to comment.