Skip to content

Commit

Permalink
Fall back to a non-hardware event source by default if `perf_event_op…
Browse files Browse the repository at this point in the history
…en` fails
  • Loading branch information
koute committed Jul 28, 2021
1 parent 2d8a5ee commit 609fbaa
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,6 @@ pub struct RecordArgs {
#[structopt(
long,
short = "s",
default_value = "hw_cpu_cycles",
parse(from_str = "parse_event_source"),
raw(possible_values = r#"&[
"hw_cpu_cycles",
Expand All @@ -184,7 +183,7 @@ pub struct RecordArgs {
"sw_dummy"
]"#)
)]
pub event_source: EventSource,
pub event_source: Option< EventSource >,

/// Size of the gathered stack payloads (in bytes)
#[structopt(long, default_value = "24576")]
Expand Down
9 changes: 7 additions & 2 deletions src/cmd_record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use nwind::arch::Registers;
use nwind::DwarfRegs;

use crate::args;
use perf_event_open::{Event, CommEvent, Mmap2Event};
use perf_event_open::{Event, EventSource, CommEvent, Mmap2Event};
use crate::perf_group::PerfGroup;
use crate::perf_arch;
use crate::archive::{ContextSwitchKind, Packet};
Expand Down Expand Up @@ -59,7 +59,12 @@ pub fn main( args: args::RecordArgs ) -> Result< (), Box< dyn Error > > {
});

info!( "Opening perf events for process with PID {}...", controller.pid() );
let mut perf = match PerfGroup::open( controller.pid(), args.frequency, args.stack_size, args.event_source ) {
let mut perf = PerfGroup::open( controller.pid(), args.frequency, args.stack_size, args.event_source.unwrap_or( EventSource::HwCpuCycles ) );
if perf.is_err() && args.event_source.is_none() {
perf = PerfGroup::open( controller.pid(), args.frequency, args.stack_size, args.event_source.unwrap_or( EventSource::SwCpuClock ) );
}

let mut perf = match perf {
Ok( perf ) => perf,
Err( error ) => {
error!( "Failed to start profiling: {}", error );
Expand Down

0 comments on commit 609fbaa

Please sign in to comment.