about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2023-04-02 19:02:55 -0400
committerMark Rousskov <mark.simulacrum@gmail.com>2023-04-02 19:28:52 -0400
commitdd85271ef5ea61fc4be3cd7607c838b99f8740f5 (patch)
tree31b2a0e6cb4322737481076c9151b5e1f8cce30b /src
parent3a8a131e9509c478ece1c58fe0ea2d49463d2300 (diff)
downloadrust-dd85271ef5ea61fc4be3cd7607c838b99f8740f5.tar.gz
rust-dd85271ef5ea61fc4be3cd7607c838b99f8740f5.zip
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.
Diffstat (limited to 'src')
-rw-r--r--src/bootstrap/metrics.rs13
1 files changed, 12 insertions, 1 deletions
diff --git a/src/bootstrap/metrics.rs b/src/bootstrap/metrics.rs
index 5f254761aa1..82b123ec8a5 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<Instant>,
     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<JsonNode>,
 }