Skip to content

Commit d6b653b

Browse files
committed
Add timestamp to unstable feature usage metrics
1 parent 60493b8 commit d6b653b

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

compiler/rustc_feature/src/unstable.rs

+15-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
//! List of the unstable feature gates.
22
33
use std::path::PathBuf;
4+
use std::time::{SystemTime, UNIX_EPOCH};
45

56
use rustc_data_structures::fx::FxHashSet;
67
use rustc_span::{Span, Symbol, sym};
@@ -681,11 +682,13 @@ impl Features {
681682
) -> Result<(), Box<dyn std::error::Error>> {
682683
#[derive(serde::Serialize)]
683684
struct LibFeature {
685+
timestamp: u128,
684686
symbol: String,
685687
}
686688

687689
#[derive(serde::Serialize)]
688690
struct LangFeature {
691+
timestamp: u128,
689692
symbol: String,
690693
since: Option<String>,
691694
}
@@ -699,10 +702,20 @@ impl Features {
699702
let metrics_file = std::fs::File::create(metrics_path)?;
700703
let metrics_file = std::io::BufWriter::new(metrics_file);
701704

705+
let now = || {
706+
SystemTime::now()
707+
.duration_since(UNIX_EPOCH)
708+
.expect("system time should always be greater than the unix epoch")
709+
.as_nanos()
710+
};
711+
702712
let lib_features = self
703713
.enabled_lib_features
704714
.iter()
705-
.map(|EnabledLibFeature { gate_name, .. }| LibFeature { symbol: gate_name.to_string() })
715+
.map(|EnabledLibFeature { gate_name, .. }| LibFeature {
716+
symbol: gate_name.to_string(),
717+
timestamp: now(),
718+
})
706719
.collect();
707720

708721
let lang_features = self
@@ -711,6 +724,7 @@ impl Features {
711724
.map(|EnabledLangFeature { gate_name, stable_since, .. }| LangFeature {
712725
symbol: gate_name.to_string(),
713726
since: stable_since.map(|since| since.to_string()),
727+
timestamp: now(),
714728
})
715729
.collect();
716730

tests/run-make/unstable-feature-usage-metrics/rmake.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,15 @@ fn test_metrics_dump() {
5858
);
5959

6060
let message = rfs::read_to_string(json_path);
61-
let parsed: serde_json::Value =
61+
let mut parsed: serde_json::Value =
6262
serde_json::from_str(&message).expect("metrics should be dumped as json");
63+
// remove timestamps, index ops act as asserts
64+
parsed["lib_features"][0]["timestamp"] = serde_json::json!(null);
65+
parsed["lang_features"][0]["timestamp"] = serde_json::json!(null);
6366
let expected = serde_json::json!(
6467
{
65-
"lib_features":[{"symbol":"ascii_char"}],
66-
"lang_features":[{"symbol":"box_patterns","since":null}]
68+
"lib_features":[{"symbol":"ascii_char", "timestamp":null}],
69+
"lang_features":[{"symbol":"box_patterns","since":null, "timestamp":null}]
6770
}
6871
);
6972

0 commit comments

Comments
 (0)