use std::fs::File;
use std::io::{self, BufReader};
use structopt::StructOpt;
use inferno::collapse::perf::{handle_file, Options};
#[derive(Debug, StructOpt)]
#[structopt(
name = "inferno-collapse-perf",
author = "",
after_help = "\
[1] perf script must emit both PID and TIDs for these to work; eg, Linux < 4.1:
perf script -f comm,pid,tid,cpu,time,event,ip,sym,dso,trace
for Linux >= 4.1:
perf script -F comm,pid,tid,cpu,time,event,ip,sym,dso,trace
If you save this output add --header on Linux >= 3.14 to include perf info."
)]
struct Opt {
#[structopt(long = "pid")]
include_pid: bool,
#[structopt(long = "tid")]
include_tid: bool,
#[structopt(long = "addrs")]
include_addrs: bool,
#[structopt(long = "jit")]
annotate_jit: bool,
#[structopt(long = "kernel")]
annotate_kernel: bool,
#[structopt(long = "all")]
annotate_all: bool,
#[structopt(name = "inline", long = "inline")]
show_inline: bool,
#[structopt(long = "context", requires = "inline")]
show_context: bool,
#[structopt(long = "event-filter", value_name = "EVENT")]
event_filter: Option<String>,
infile: Option<String>,
}
impl Into<Options> for Opt {
fn into(self) -> Options {
Options {
include_pid: self.include_pid,
include_tid: self.include_tid,
include_addrs: self.include_addrs,
annotate_jit: self.annotate_jit || self.annotate_all,
annotate_kernel: self.annotate_kernel || self.annotate_all,
show_inline: self.show_inline,
show_context: self.show_context,
event_filter: self.event_filter,
}
}
}
fn main() -> io::Result<()> {
let (infile, options) = {
let opt = Opt::from_args();
(opt.infile.clone(), opt.into())
};
match infile {
Some(ref f) => {
let r = BufReader::with_capacity(128 * 1024, File::open(f)?);
handle_file(options, r, io::stdout().lock())
}
None => {
let stdin = io::stdin();
let r = BufReader::with_capacity(128 * 1024, stdin.lock());
handle_file(options, r, io::stdout().lock())
}
}
}