From dd85271ef5ea61fc4be3cd7607c838b99f8740f5 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Sun, 2 Apr 2023 19:02:55 -0400 Subject: [PATCH] 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. --- src/bootstrap/metrics.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/metrics.rs b/src/bootstrap/metrics.rs index 5f254761aa19f..82b123ec8a5e1 100644 --- a/src/bootstrap/metrics.rs +++ b/src/bootstrap/metrics.rs @@ -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 { @@ -27,6 +27,7 @@ impl BuildMetrics { system_info: System::new(), timer_start: None, invocation_timer_start: Instant::now(), + invocation_start: SystemTime::now(), }); BuildMetrics { state } @@ -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(), }); @@ -166,6 +172,7 @@ struct MetricsState { system_info: System, timer_start: Option, invocation_timer_start: Instant, + invocation_start: SystemTime, } struct StepMetrics { @@ -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, }