Skip to content

Commit dd85271

Browse files
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.
1 parent 3a8a131 commit dd85271

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

src/bootstrap/metrics.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use serde_derive::{Deserialize, Serialize};
1111
use std::cell::RefCell;
1212
use std::fs::File;
1313
use std::io::BufWriter;
14-
use std::time::{Duration, Instant};
14+
use std::time::{Duration, Instant, SystemTime};
1515
use sysinfo::{CpuExt, System, SystemExt};
1616

1717
pub(crate) struct BuildMetrics {
@@ -27,6 +27,7 @@ impl BuildMetrics {
2727
system_info: System::new(),
2828
timer_start: None,
2929
invocation_timer_start: Instant::now(),
30+
invocation_start: SystemTime::now(),
3031
});
3132

3233
BuildMetrics { state }
@@ -124,6 +125,11 @@ impl BuildMetrics {
124125
}
125126
};
126127
invocations.push(JsonInvocation {
128+
start_time: state
129+
.invocation_start
130+
.duration_since(SystemTime::UNIX_EPOCH)
131+
.unwrap()
132+
.as_secs(),
127133
duration_including_children_sec: state.invocation_timer_start.elapsed().as_secs_f64(),
128134
children: steps.into_iter().map(|step| self.prepare_json_step(step)).collect(),
129135
});
@@ -166,6 +172,7 @@ struct MetricsState {
166172
system_info: System,
167173
timer_start: Option<Instant>,
168174
invocation_timer_start: Instant,
175+
invocation_start: SystemTime,
169176
}
170177

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

0 commit comments

Comments
 (0)