Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
romange committed Oct 25, 2021
1 parent 0568abe commit 4c44cfd
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions src/collapse/perf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ mod logging {
}

#[derive(PartialEq)]
enum SkipStackOpt {
DontSkip,
Entirely,
Partially,
enum StackFilter {
Keep,
Skip,
SkipRemaining,
}

/// `perf` folder configuration options.
Expand Down Expand Up @@ -124,7 +124,7 @@ pub struct Folder {
pname: String,

/// Whether to skip stack lines in this event.
skip_stack: SkipStackOpt,
stack_filter: StackFilter,

/// Function entries on the stack in this entry thus far.
stack: VecDeque<String>,
Expand All @@ -145,7 +145,7 @@ impl From<Options> for Folder {
in_event: false,
nstacks_per_job: common::DEFAULT_NSTACKS_PER_JOB,
pname: String::default(),
skip_stack: SkipStackOpt::DontSkip,
stack_filter: StackFilter::Keep,
stack: VecDeque::default(),
opt,
}
Expand Down Expand Up @@ -202,7 +202,7 @@ impl CollapsePrivate for Folder {

// Reset state...
self.in_event = false;
self.skip_stack = SkipStackOpt::DontSkip;
self.stack_filter = StackFilter::Keep;
self.stack.clear();
Ok(())
}
Expand Down Expand Up @@ -259,7 +259,7 @@ impl CollapsePrivate for Folder {
in_event: false,
nstacks_per_job: self.nstacks_per_job,
pname: String::new(),
skip_stack: SkipStackOpt::DontSkip,
stack_filter: StackFilter::Keep,
stack: VecDeque::default(),
opt: self.opt.clone(),
}
Expand Down Expand Up @@ -380,7 +380,7 @@ impl Folder {
if let Some(event) = event {
if let Some(ref event_filter) = self.event_filter {
if event != event_filter {
self.skip_stack = SkipStackOpt::Entirely;
self.stack_filter = StackFilter::Skip;
return;
}
} else {
Expand Down Expand Up @@ -478,7 +478,11 @@ impl Folder {
// 7f53389994d0 [unknown] ([unknown])
// 0 [unknown] ([unknown])
fn on_stack_line(&mut self, line: &str) {
if self.skip_stack == SkipStackOpt::Entirely || self.skip_stack == SkipStackOpt::Partially {
let should_omit = matches!(
self.stack_filter,
StackFilter::Skip | StackFilter::SkipRemaining
);
if should_omit {
return;
}

Expand Down Expand Up @@ -546,8 +550,8 @@ impl Folder {
}

if let Some(skip_after) = &self.opt.skip_after {
if rawfunc.eq(skip_after) {
self.skip_stack = SkipStackOpt::Partially;
if rawfunc == *skip_after {
self.stack_filter = StackFilter::SkipRemaining;
}
}
} else {
Expand All @@ -557,7 +561,7 @@ impl Folder {

fn after_event(&mut self, occurrences: &mut Occurrences) {
// end of stack, so emit stack entry
if self.skip_stack == SkipStackOpt::Partially || self.skip_stack == SkipStackOpt::DontSkip {
if !self.stack.is_empty() {
// allocate a string that is long enough to hold the entire stack string
let mut stack_str = String::with_capacity(
self.pname.len() + self.stack.iter().fold(0, |a, s| a + s.len() + 1),
Expand All @@ -577,7 +581,7 @@ impl Folder {

// reset for the next event
self.in_event = false;
self.skip_stack = SkipStackOpt::DontSkip;
self.stack_filter = StackFilter::Keep;
self.stack.clear();
}
}
Expand Down Expand Up @@ -790,6 +794,9 @@ mod tests {
let mut buf_actual = Vec::new();
<Folder as Collapse>::collapse(&mut folder, &bytes[..], &mut buf_actual)?;
let lines = std::str::from_utf8(&buf_actual[..]).unwrap().lines();

// without `skip_after` some collapsed lines would look like:
// go;[unknown];x_cgo_notify_runtime_init_done;runtime.main;main.init;...
for line in lines {
if line.contains("main.init") {
assert!(line.contains("go;main.init;")); // we removed the frames above "main.init"
Expand Down

0 comments on commit 4c44cfd

Please sign in to comment.