Encapsulating now so it is easier to build functionality that uses the timings data through a common interface, for example getting the total duration spent on a specific PackageId
.
T34OV3YQGRFMXYWEFLBCFMX3U2TVXF552B5B3S6HMBJZU66PDMYAC
pub fn generate() -> Vec<Message> {
// TODO: `cargo build --timings=json` seems to only work on a clean build
Command::new("cargo")
.arg("clean")
.args(CARGO_CUSTOM_PROFILE)
.args(&["--profile", "depwiz"])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.unwrap();
pub struct Output {
repr: HashMap<PackageId, Vec<Message>>,
}
let timings_ouput = Command::new("cargo")
.arg("build")
.args(CARGO_CUSTOM_PROFILE)
.args(&[
"--profile",
"depwiz",
"-Zunstable-options",
"--timings=json",
])
.stderr(Stdio::inherit())
.output()
.unwrap();
impl Output {
pub fn new() -> Self {
// TODO: `cargo build --timings=json` seems to only work on a clean build
Command::new("cargo")
.arg("clean")
.args(CARGO_CUSTOM_PROFILE)
.args(&["--profile", "depwiz"])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.output()
.unwrap();
let timings_ouput = Command::new("cargo")
.arg("build")
.args(CARGO_CUSTOM_PROFILE)
.args(&[
"--profile",
"depwiz",
"-Zunstable-options",
"--timings=json",
])
.stderr(Stdio::inherit())
.output()
.unwrap();
let mut timings = Vec::new();
let mut timings_buffer = BufReader::new(timings_ouput.stdout.as_slice());
let mut message_buffer = Vec::new();
let mut timings = HashMap::new();
let mut timings_buffer = BufReader::new(timings_ouput.stdout.as_slice());
let mut message_buffer = Vec::new();
let json_message: Message = match serde_json::from_slice(&message_buffer) {
Ok(message) => message,
Err(err) => {
use serde_json::error::Category;
match err.classify() {
Category::Eof => break,
Category::Data => todo!(
"JSON object not properly handled, got `{err:?}` for message: `{}`",
String::from_utf8(message_buffer.clone()).unwrap()
),
_ => {
panic!("Unexpected error while parsing: {err:?}");
let json_message: Message = match serde_json::from_slice(&message_buffer) {
Ok(message) => message,
Err(err) => {
use serde_json::error::Category;
match err.classify() {
Category::Eof => break,
Category::Data => todo!(
"JSON object not properly handled, got `{err:?}` for message: `{}`",
String::from_utf8(message_buffer.clone()).unwrap()
),
_ => {
panic!("Unexpected error while parsing: {err:?}");
}