Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 234a68f

Browse files
authoredMar 6, 2025
Rollup merge of #137827 - yaahc:timestamp-metrics, r=estebank
Add timestamp to unstable feature usage metrics part of #129485 with this we should be able to temporarily enable metrics on docs.rs to gather a nice test dataset for the initial PoC dashboard r? ```@estebank```
2 parents e6af292 + ddd04d0 commit 234a68f

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-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};
@@ -685,11 +686,13 @@ impl Features {
685686
) -> Result<(), Box<dyn std::error::Error>> {
686687
#[derive(serde::Serialize)]
687688
struct LibFeature {
689+
timestamp: u128,
688690
symbol: String,
689691
}
690692

691693
#[derive(serde::Serialize)]
692694
struct LangFeature {
695+
timestamp: u128,
693696
symbol: String,
694697
since: Option<String>,
695698
}
@@ -703,10 +706,20 @@ impl Features {
703706
let metrics_file = std::fs::File::create(metrics_path)?;
704707
let metrics_file = std::io::BufWriter::new(metrics_file);
705708

709+
let now = || {
710+
SystemTime::now()
711+
.duration_since(UNIX_EPOCH)
712+
.expect("system time should always be greater than the unix epoch")
713+
.as_nanos()
714+
};
715+
706716
let lib_features = self
707717
.enabled_lib_features
708718
.iter()
709-
.map(|EnabledLibFeature { gate_name, .. }| LibFeature { symbol: gate_name.to_string() })
719+
.map(|EnabledLibFeature { gate_name, .. }| LibFeature {
720+
symbol: gate_name.to_string(),
721+
timestamp: now(),
722+
})
710723
.collect();
711724

712725
let lang_features = self
@@ -715,6 +728,7 @@ impl Features {
715728
.map(|EnabledLangFeature { gate_name, stable_since, .. }| LangFeature {
716729
symbol: gate_name.to_string(),
717730
since: stable_since.map(|since| since.to_string()),
731+
timestamp: now(),
718732
})
719733
.collect();
720734

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

+8-3
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,17 @@ 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
64+
assert!(parsed["lib_features"][0]["timestamp"].is_number());
65+
assert!(parsed["lang_features"][0]["timestamp"].is_number());
66+
parsed["lib_features"][0]["timestamp"] = serde_json::json!(null);
67+
parsed["lang_features"][0]["timestamp"] = serde_json::json!(null);
6368
let expected = serde_json::json!(
6469
{
65-
"lib_features":[{"symbol":"ascii_char"}],
66-
"lang_features":[{"symbol":"box_patterns","since":null}]
70+
"lib_features":[{"symbol":"ascii_char", "timestamp":null}],
71+
"lang_features":[{"symbol":"box_patterns","since":null, "timestamp":null}]
6772
}
6873
);
6974

0 commit comments

Comments
 (0)
Failed to load comments.