Skip to content

Commit 8455ee8

Browse files
authored
xctrace support (#286)
1 parent 8e691e6 commit 8455ee8

File tree

13 files changed

+20031
-2
lines changed

13 files changed

+20031
-2
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
### Added
1010

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

1315
### Deprecated

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ name = "inferno-collapse-dtrace"
8383
path = "src/bin/collapse-dtrace.rs"
8484
required-features = ["cli"]
8585

86+
[[bin]]
87+
name = "inferno-collapse-xctrace"
88+
path = "src/bin/collapse-xctrace.rs"
89+
required-features = ["cli"]
90+
8691
[[bin]]
8792
name = "inferno-collapse-sample"
8893
path = "src/bin/collapse-sample.rs"

src/bin/collapse-xctrace.rs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
use std::io;
2+
use std::path::PathBuf;
3+
4+
use clap::{ArgAction, Parser};
5+
use env_logger::Env;
6+
use inferno::collapse::xctrace::Folder;
7+
use inferno::collapse::Collapse;
8+
9+
#[derive(Debug, Parser)]
10+
#[clap(
11+
name = "inferno-collapse-xctrace",
12+
about,
13+
after_help = r#"\
14+
[1] This processes the result of the xctrace with `Timer Profiler` profile as run with:
15+
`xctrace record --template 'Time Profiler' --launch <executable> --output tmp.trace`
16+
or
17+
`xctrace record --template 'Time Profiler' --attach <pid|proc_name> --output tmp.trace`
18+
then
19+
xctrace export --input tmp.trace --xpath '/trace-toc/*/data/table[@schema="time-profile"]' > tmp.xml
20+
"#
21+
)]
22+
struct Opt {
23+
/// Silence all log output
24+
#[clap(short = 'q', long = "quiet")]
25+
quiet: bool,
26+
27+
/// Verbose logging mode (-v, -vv, -vvv)
28+
#[clap(short = 'v', long = "verbose", action = ArgAction::Count)]
29+
verbose: u8,
30+
31+
// ************ //
32+
// *** ARGS *** //
33+
// ************ //
34+
/// xctrace output file, or STDIN if not specified
35+
#[clap(value_name = "PATH")]
36+
infile: Option<PathBuf>,
37+
}
38+
39+
fn main() -> io::Result<()> {
40+
let opt = Opt::parse();
41+
42+
// Initialize logger
43+
if !opt.quiet {
44+
env_logger::Builder::from_env(Env::default().default_filter_or(match opt.verbose {
45+
0 => "warn",
46+
1 => "info",
47+
2 => "debug",
48+
_ => "trace",
49+
}))
50+
.format_timestamp(None)
51+
.init();
52+
}
53+
54+
Folder.collapse_file_to_stdout(opt.infile.as_ref())
55+
}

src/collapse/guess.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::io::{self, Cursor};
33

44
use log::{error, info};
55

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

88
const LINES_PER_ITERATION: usize = 10;
99

@@ -70,11 +70,12 @@ impl Collapse for Folder {
7070
let mut sample = sample::Folder::default();
7171
let mut vtune = vtune::Folder::default();
7272
let mut vsprof = vsprof::Folder::default();
73+
let mut xctrace = xctrace::Folder::default();
7374
let mut ghcprof = ghcprof::Folder::default();
7475

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

7980
let mut buffer = String::new();
8081
loop {
@@ -110,6 +111,7 @@ impl Collapse for Folder {
110111
try_collapse_impl!(vtune, 3);
111112
try_collapse_impl!(vsprof, 4);
112113
try_collapse_impl!(ghcprof, 5);
114+
try_collapse_impl!(xctrace, 6);
113115

114116
if eof {
115117
break;

src/collapse/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,13 @@ pub mod recursive;
6060
/// [crate-level documentation]: ../../index.html
6161
pub mod vsprof;
6262

63+
/// Stack collapsing for the output of the [xctrace](https://developer.apple.com/xcode/features/).
64+
///
65+
/// See the [crate-level documentation] for details.
66+
///
67+
/// [crate-level documentation]: ../../index.html
68+
pub mod xctrace;
69+
6370
/// Stack collapsing for the output of the [GHC's built-in profiler](https://downloads.haskell.org/ghc/latest/docs/users_guide/profiling.html).
6471
///
6572
/// See the [crate-level documentation] for details.

0 commit comments

Comments
 (0)