Skip to content

Commit

Permalink
xctrace support
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Apr 2, 2023
1 parent 6326ced commit 8988028
Show file tree
Hide file tree
Showing 10 changed files with 19,900 additions and 1 deletion.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ itoa = "1"
log = "0.4"
num-format = { version = "0.4.3", default-features = false }
quick-xml = { version = "0.26", default-features = false }
quick-xml_28 = { package = "quick-xml", version = "0.28.1", default-features = false }
rgb = "0.8.13"
str_stack = "0.1"
clap = { version = "4.0.1", optional = true, features = ["derive"] }
Expand Down Expand Up @@ -82,6 +83,11 @@ name = "inferno-collapse-dtrace"
path = "src/bin/collapse-dtrace.rs"
required-features = ["cli"]

[[bin]]
name = "inferno-collapse-xctrace"
path = "src/bin/collapse-xctrace.rs"
required-features = ["cli"]

[[bin]]
name = "inferno-collapse-sample"
path = "src/bin/collapse-sample.rs"
Expand Down
55 changes: 55 additions & 0 deletions src/bin/collapse-xctrace.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
use std::io;
use std::path::PathBuf;

use clap::{ArgAction, Parser};
use env_logger::Env;
use inferno::collapse::xctrace::Folder;
use inferno::collapse::Collapse;

#[derive(Debug, Parser)]
#[clap(
name = "inferno-collapse-xctrace",
about,
after_help = r#"\
[1] This processes the result of the xctrace with `Timer Profiler` profile as run with:
`xctrace record --template 'Time Profiler' --launch <executable> --output tmp.trace`
or
`xctrace record --template 'Time Profiler' --attach <pid|proc_name> --output tmp.trace`
then
xctrace export --input tmp.trace --xpath '/trace-toc/run[@number="1"]/data/table[@schema="time-profile"]' > tmp.xml
"#
)]
struct Opt {
/// Silence all log output
#[clap(short = 'q', long = "quiet")]
quiet: bool,

/// Verbose logging mode (-v, -vv, -vvv)
#[clap(short = 'v', long = "verbose", action = ArgAction::Count)]
verbose: u8,

// ************ //
// *** ARGS *** //
// ************ //
/// xctrace output file, or STDIN if not specified
#[clap(value_name = "PATH")]
infile: Option<PathBuf>,
}

fn main() -> io::Result<()> {
let opt = Opt::parse();

// Initialize logger
if !opt.quiet {
env_logger::Builder::from_env(Env::default().default_filter_or(match opt.verbose {
0 => "warn",
1 => "info",
2 => "debug",
_ => "trace",
}))
.format_timestamp(None)
.init();
}

Folder.collapse_file_to_stdout(opt.infile.as_ref())
}
7 changes: 7 additions & 0 deletions src/collapse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ pub mod vtune;
/// [crate-level documentation]: ../../index.html
pub mod vsprof;

/// Stack collapsing for the output of the [xctrace](https://developer.apple.com/xcode/features/).
///
/// See the [crate-level documentation] for details.
///
/// [crate-level documentation]: ../../index.html
pub mod xctrace;

use is_terminal::IsTerminal;

// DEFAULT_NTHREADS is public because we use it in the help text of the binaries,
Expand Down
Loading

0 comments on commit 8988028

Please sign in to comment.