Skip to content

Commit

Permalink
xctrace support
Browse files Browse the repository at this point in the history
  • Loading branch information
ldm0 committed Sep 17, 2023
1 parent 4555880 commit 49ff175
Show file tree
Hide file tree
Showing 12 changed files with 19,908 additions and 2 deletions.
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())
}
4 changes: 3 additions & 1 deletion 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,6 +70,7 @@ 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.
Expand Down Expand Up @@ -109,6 +110,7 @@ impl Collapse for Folder {
try_collapse_impl!(sample, 2);
try_collapse_impl!(vtune, 3);
try_collapse_impl!(vsprof, 4);
try_collapse_impl!(xctrace, 5);
try_collapse_impl!(ghcprof, 5);

if eof {
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

0 comments on commit 49ff175

Please sign in to comment.