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

xctrace support #286

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added

- Support for collapsing the xml output of the xctrace tool. [#286](https://github.com/jonhoo/inferno/pull/286)

### Changed

### Deprecated
Expand Down
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,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/*/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())
}
6 changes: 4 additions & 2 deletions src/collapse/guess.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::io::{self, Cursor};

use log::{error, info};

use crate::collapse::{self, dtrace, ghcprof, perf, sample, vsprof, vtune, Collapse};
use crate::collapse::{self, dtrace, ghcprof, perf, sample, vsprof, vtune, xctrace, Collapse};

const LINES_PER_ITERATION: usize = 10;

Expand Down Expand Up @@ -70,11 +70,12 @@ impl Collapse for Folder {
let mut sample = sample::Folder::default();
let mut vtune = vtune::Folder::default();
let mut vsprof = vsprof::Folder::default();
let mut xctrace = xctrace::Folder::default();
let mut ghcprof = ghcprof::Folder::default();

// Each Collapse impl gets its own flag in this array.
// It gets set to true when the impl has been ruled out.
let mut not_applicable = [false; 6];
let mut not_applicable = [false; 7];

let mut buffer = String::new();
loop {
Expand Down Expand Up @@ -110,6 +111,7 @@ impl Collapse for Folder {
try_collapse_impl!(vtune, 3);
try_collapse_impl!(vsprof, 4);
try_collapse_impl!(ghcprof, 5);
try_collapse_impl!(xctrace, 6);

if eof {
break;
Expand Down
7 changes: 7 additions & 0 deletions src/collapse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ pub mod recursive;
/// [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;

/// Stack collapsing for the output of the [GHC's built-in profiler](https://downloads.haskell.org/ghc/latest/docs/users_guide/profiling.html).
///
/// See the [crate-level documentation] for details.
Expand Down
Loading