Skip to content

Commit

Permalink
Rollup merge of #109871 - Mark-Simulacrum:metrics-timestamp, r=ozkanonur
Browse files Browse the repository at this point in the history
Include invocation start times

For multi-invocation builders (e.g., dist-x86_64-linux) this timestamp is necessary to correlate the data in the metrics JSON with other data sources (e.g., logs, cpu-usage CSV, etc.). Such correlation may not be perfect but is sometimes helpful and awkward to do otherwise.
  • Loading branch information
matthiaskrgr committed Apr 3, 2023
2 parents 9007ee9 + dd85271 commit 41cd454
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/bootstrap/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use serde_derive::{Deserialize, Serialize};
use std::cell::RefCell;
use std::fs::File;
use std::io::BufWriter;
use std::time::{Duration, Instant};
use std::time::{Duration, Instant, SystemTime};
use sysinfo::{CpuExt, System, SystemExt};

pub(crate) struct BuildMetrics {
Expand All @@ -27,6 +27,7 @@ impl BuildMetrics {
system_info: System::new(),
timer_start: None,
invocation_timer_start: Instant::now(),
invocation_start: SystemTime::now(),
});

BuildMetrics { state }
Expand Down Expand Up @@ -124,6 +125,11 @@ impl BuildMetrics {
}
};
invocations.push(JsonInvocation {
start_time: state
.invocation_start
.duration_since(SystemTime::UNIX_EPOCH)
.unwrap()
.as_secs(),
duration_including_children_sec: state.invocation_timer_start.elapsed().as_secs_f64(),
children: steps.into_iter().map(|step| self.prepare_json_step(step)).collect(),
});
Expand Down Expand Up @@ -166,6 +172,7 @@ struct MetricsState {
system_info: System,
timer_start: Option<Instant>,
invocation_timer_start: Instant,
invocation_start: SystemTime,
}

struct StepMetrics {
Expand Down Expand Up @@ -194,6 +201,10 @@ struct JsonRoot {
#[derive(Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
struct JsonInvocation {
// Unix timestamp in seconds
//
// This is necessary to easily correlate this invocation with logs or other data.
start_time: u64,
duration_including_children_sec: f64,
children: Vec<JsonNode>,
}
Expand Down

0 comments on commit 41cd454

Please sign in to comment.