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

Remove demangle option from collapsers #144

Merged
merged 2 commits into from
Sep 6, 2019
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: 0 additions & 1 deletion .cirrus.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ task:
- curl https://sh.rustup.rs -sSf --output rustup.sh
- sh rustup.sh -y
- . $HOME/.cargo/env
- rustup component add rustfmt
submodule_script:
- git submodule sync --recursive
- git submodule update --init --recursive
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ rand = "0.7"
rgb = "0.8.13"
str_stack = "0.1"
structopt = { version = "0.2", optional = true }
symbolic-demangle = "6.1.3"

[dev-dependencies]
assert_cmd = "0.11"
Expand Down
5 changes: 0 additions & 5 deletions src/bin/collapse-dtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ struct Opt {
// ************* //
// *** FLAGS *** //
// ************* //
/// Demangle function names
#[structopt(long = "demangle")]
demangle: bool,

/// Include offsets
#[structopt(long = "includeoffset")]
includeoffset: bool,
Expand Down Expand Up @@ -67,7 +63,6 @@ impl Opt {
(
self.infile,
Options {
demangle: self.demangle,
includeoffset: self.includeoffset,
nthreads: self.nthreads,
},
Expand Down
5 changes: 0 additions & 5 deletions src/bin/collapse-perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ struct Opt {
#[structopt(long = "all")]
all: bool,

/// Demangle function names
#[structopt(long = "demangle")]
demangle: bool,

/// Annotate jit functions with a _[j]
#[structopt(long = "jit")]
jit: bool,
Expand Down Expand Up @@ -96,7 +92,6 @@ impl Opt {
include_addrs: self.addrs,
annotate_jit: self.jit || self.all,
annotate_kernel: self.kernel || self.all,
demangle: self.demangle,
event_filter: self.event_filter,
nthreads: self.nthreads,
},
Expand Down
32 changes: 6 additions & 26 deletions src/collapse/dtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ use crate::collapse::common::{self, CollapsePrivate, Occurrences};
/// `dtrace` folder configuration options.
#[derive(Clone, Debug)]
pub struct Options {
/// Demangle function names.
///
/// Default is `false`.
pub demangle: bool,

/// Include function offset (except leafs).
///
/// Default is `false`.
Expand All @@ -28,7 +23,6 @@ pub struct Options {
impl Default for Options {
fn default() -> Self {
Self {
demangle: false,
includeoffset: false,
nthreads: *common::DEFAULT_NTHREADS,
}
Expand Down Expand Up @@ -301,42 +295,31 @@ impl Folder {
)
}

// Transforms the function part of a frame with the given function.
fn transform_function_name<'a, F>(&self, frame: &'a str, transform: F) -> Cow<'a, str>
where
F: Fn(&'a str) -> Cow<'a, str>,
{
// DTrace doesn't properly demangle Rust function names, so fix those.
fn fix_rust_symbol<'a>(&self, frame: &'a str) -> Cow<'a, str> {
let mut parts = frame.splitn(2, '`');
if let (Some(pname), Some(func)) = (parts.next(), parts.next()) {
if self.opt.includeoffset {
let mut parts = func.rsplitn(2, '+');
if let (Some(offset), Some(func)) = (parts.next(), parts.next()) {
if let Cow::Owned(func) = transform(func.trim_end()) {
if let Cow::Owned(func) =
common::fix_partially_demangled_rust_symbol(func.trim_end())
{
return Cow::Owned(format!("{}`{}+{}", pname, func, offset));
} else {
return Cow::Borrowed(frame);
}
}
}

if let Cow::Owned(func) = transform(func.trim_end()) {
if let Cow::Owned(func) = common::fix_partially_demangled_rust_symbol(func.trim_end()) {
return Cow::Owned(format!("{}`{}", pname, func));
}
}

Cow::Borrowed(frame)
}

// Demangle the function name if it's mangled.
fn demangle<'a>(&self, frame: &'a str) -> Cow<'a, str> {
self.transform_function_name(frame, symbolic_demangle::demangle)
}

// DTrace doesn't properly demangle Rust function names, so fix those.
fn fix_rust_symbol<'a>(&self, frame: &'a str) -> Cow<'a, str> {
self.transform_function_name(frame, common::fix_partially_demangled_rust_symbol)
}

// we have a stack line that shows one stack entry from the preceeding event, like:
//
// unix`tsc_gethrtimeunscaled+0x21
Expand All @@ -357,8 +340,6 @@ impl Folder {

let frame = if frame.is_empty() {
Cow::Borrowed("-")
} else if self.opt.demangle {
self.demangle(frame)
} else {
self.fix_rust_symbol(frame)
};
Expand Down Expand Up @@ -546,7 +527,6 @@ mod tests {
loop {
let nstacks_per_job = rng.gen_range(1, 500 + 1);
let options = Options {
demangle: rng.gen(),
includeoffset: rng.gen(),
nthreads: rng.gen_range(2, 32 + 1),
};
Expand Down
19 changes: 3 additions & 16 deletions src/collapse/perf.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use std::collections::VecDeque;
use std::io::{self, BufRead};

use symbolic_demangle::demangle;

use crate::collapse::common::{self, CollapsePrivate, Occurrences};

const TIDY_GENERIC: bool = true;
Expand Down Expand Up @@ -37,11 +35,6 @@ pub struct Options {
/// Default is `false`.
pub annotate_kernel: bool,

/// Demangle function names.
///
/// Default is `false`.
pub demangle: bool,

/// Only consider samples of the given event type (see `perf list`). If this option is
/// set to `None`, it will be set to the first encountered event type.
///
Expand Down Expand Up @@ -75,7 +68,6 @@ impl Default for Options {
Self {
annotate_jit: false,
annotate_kernel: false,
demangle: false,
event_filter: None,
include_addrs: false,
include_pid: false,
Expand Down Expand Up @@ -443,13 +435,9 @@ impl Folder {
return;
}

let rawfunc = if self.opt.demangle {
demangle(rawfunc)
} else {
// perf mostly demangles Rust symbols,
// but this will fix the things it gets wrong
common::fix_partially_demangled_rust_symbol(rawfunc)
};
// perf mostly demangles Rust symbols,
// but this will fix the things it gets wrong
let rawfunc = common::fix_partially_demangled_rust_symbol(rawfunc);

// Support Java inlining by splitting on "->". After the first func, the
// rest are annotated with "_[i]" to mark them as inlined.
Expand Down Expand Up @@ -705,7 +693,6 @@ mod tests {
let options = Options {
annotate_jit: rng.gen(),
annotate_kernel: rng.gen(),
demangle: rng.gen(),
event_filter: None,
include_addrs: rng.gen(),
include_pid: rng.gen(),
Expand Down
31 changes: 0 additions & 31 deletions tests/collapse-dtrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,37 +125,6 @@ fn collapse_dtrace_rust_names() {
test_collapse_dtrace(test_file, result_file, Options::default()).unwrap()
}

#[test]
fn collapse_dtrace_demangle() {
let test_file = "./tests/data/collapse-dtrace/mangled.txt";
let result_file = "./tests/data/collapse-dtrace/results/demangled.txt";
test_collapse_dtrace(
test_file,
result_file,
Options {
demangle: true,
..Default::default()
},
)
.unwrap()
}

#[test]
fn collapse_dtrace_demangle_includeoffset() {
let test_file = "./tests/data/collapse-dtrace/mangled.txt";
let result_file = "./tests/data/collapse-dtrace/results/demangled_with_offsets.txt";
test_collapse_dtrace(
test_file,
result_file,
Options {
demangle: true,
includeoffset: true,
..Default::default()
},
)
.unwrap()
}

#[test]
fn collapse_dtrace_cli() {
let input_file = "./flamegraph/example-dtrace-stacks.txt";
Expand Down
16 changes: 0 additions & 16 deletions tests/collapse-perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,22 +283,6 @@ fn collapse_perf_should_warn_about_weird_input_lines() {
);
}

#[test]
fn collapse_perf_demangle() {
let test_file = "./tests/data/collapse-perf/mangled.txt";
let result_file = "./tests/data/collapse-perf/results/demangled.txt";
test_collapse_perf(
test_file,
result_file,
Options {
demangle: true,
..Default::default()
},
false,
)
.unwrap()
}

#[test]
fn collapse_perf_cli() {
let input_file = "./flamegraph/test/perf-vertx-stacks-01.txt";
Expand Down
87 changes: 0 additions & 87 deletions tests/data/collapse-dtrace/mangled.txt

This file was deleted.

4 changes: 0 additions & 4 deletions tests/data/collapse-dtrace/results/demangled.txt

This file was deleted.

Loading