Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ members = [
"mistralrs-macros",
# Arc additions
"arc-engine",
"arc-profiler",
"arc-turbo",
"arc-cli",
"arc-cuda-graph",
Expand Down
24 changes: 24 additions & 0 deletions arc-profiler/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[package]
name = "arc-profiler"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
description = "Hierarchical host/device/sync profiler for the Arc token path"
license = "Apache-2.0"

[dependencies]
candle-core.workspace = true
serde = { workspace = true, features = ["derive"] }
serde_json.workspace = true
tracing.workspace = true

[features]
default = []
cuda = ["candle-core/cuda"]

# Turns a run's JSON tree(s) into one self-contained interactive HTML page.
# Deliberately a separate binary: the report is a *view* of the JSON, and the
# JSON is the durable artifact. Never needs a GPU.
[[bin]]
name = "arc-profile-report"
path = "src/bin/arc_profile_report.rs"
90 changes: 90 additions & 0 deletions arc-profiler/src/bin/arc_profile_report.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
//! Turn one or more profile JSONs into one interactive HTML page.
//!
//! ```text
//! arc-profile-report -o batch-sweep.html b1.json b64.json b256.json
//! ```
//!
//! With more than one input the page gains a comparison view keyed by node
//! path, which is how a B=1 / B=64 / B=256 sweep gets read side by side. Never
//! needs a GPU and never touches the network.

use std::path::PathBuf;
use std::process::ExitCode;

use arc_profiler::{html, Profile};

fn main() -> ExitCode {
let mut out = PathBuf::from("arc-profile.html");
let mut inputs: Vec<PathBuf> = Vec::new();
let mut args = std::env::args().skip(1);
while let Some(a) = args.next() {
match a.as_str() {
"-o" | "--out" => match args.next() {
Some(p) => out = PathBuf::from(p),
None => {
eprintln!("--out needs a path");
return ExitCode::FAILURE;
}
},
"-h" | "--help" => {
eprintln!(
"usage: arc-profile-report [-o OUT.html] RUN.json [RUN.json ...]\n\
\n\
Renders arc-profiler JSON into one self-contained interactive page.\n\
Pass several runs (e.g. B=1, B=64, B=256) to get the comparison view."
);
return ExitCode::SUCCESS;
}
_ => inputs.push(PathBuf::from(a)),
}
}

if inputs.is_empty() {
eprintln!("no input JSON given; try --help");
return ExitCode::FAILURE;
}

let mut profiles: Vec<Profile> = Vec::with_capacity(inputs.len());
for path in &inputs {
let bytes = match std::fs::read(path) {
Ok(b) => b,
Err(e) => {
eprintln!("{}: {e}", path.display());
return ExitCode::FAILURE;
}
};
match serde_json::from_slice::<Profile>(&bytes) {
Ok(p) => {
if p.schema != arc_profiler::SCHEMA {
// Refuse rather than render a page whose columns silently
// mean something else.
eprintln!(
"{}: schema is `{}`, this binary reads `{}`",
path.display(),
p.schema,
arc_profiler::SCHEMA
);
return ExitCode::FAILURE;
}
profiles.push(p);
}
Err(e) => {
eprintln!("{}: {e}", path.display());
return ExitCode::FAILURE;
}
}
}

let page = html::render(&profiles);
if let Err(e) = std::fs::write(&out, page.as_bytes()) {
eprintln!("{}: {e}", out.display());
return ExitCode::FAILURE;
}
eprintln!(
"wrote {} ({} runs, {} KiB)",
out.display(),
profiles.len(),
page.len() / 1024
);
ExitCode::SUCCESS
}
Loading
Loading