Add timestamp to unstable feature usage metrics
This commit is contained in:
parent
60493b8973
commit
ddd04d03d1
2 changed files with 23 additions and 4 deletions
|
@ -1,6 +1,7 @@
|
||||||
//! List of the unstable feature gates.
|
//! List of the unstable feature gates.
|
||||||
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
use std::time::{SystemTime, UNIX_EPOCH};
|
||||||
|
|
||||||
use rustc_data_structures::fx::FxHashSet;
|
use rustc_data_structures::fx::FxHashSet;
|
||||||
use rustc_span::{Span, Symbol, sym};
|
use rustc_span::{Span, Symbol, sym};
|
||||||
|
@ -681,11 +682,13 @@ impl Features {
|
||||||
) -> Result<(), Box<dyn std::error::Error>> {
|
) -> Result<(), Box<dyn std::error::Error>> {
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
struct LibFeature {
|
struct LibFeature {
|
||||||
|
timestamp: u128,
|
||||||
symbol: String,
|
symbol: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
struct LangFeature {
|
struct LangFeature {
|
||||||
|
timestamp: u128,
|
||||||
symbol: String,
|
symbol: String,
|
||||||
since: Option<String>,
|
since: Option<String>,
|
||||||
}
|
}
|
||||||
|
@ -699,10 +702,20 @@ impl Features {
|
||||||
let metrics_file = std::fs::File::create(metrics_path)?;
|
let metrics_file = std::fs::File::create(metrics_path)?;
|
||||||
let metrics_file = std::io::BufWriter::new(metrics_file);
|
let metrics_file = std::io::BufWriter::new(metrics_file);
|
||||||
|
|
||||||
|
let now = || {
|
||||||
|
SystemTime::now()
|
||||||
|
.duration_since(UNIX_EPOCH)
|
||||||
|
.expect("system time should always be greater than the unix epoch")
|
||||||
|
.as_nanos()
|
||||||
|
};
|
||||||
|
|
||||||
let lib_features = self
|
let lib_features = self
|
||||||
.enabled_lib_features
|
.enabled_lib_features
|
||||||
.iter()
|
.iter()
|
||||||
.map(|EnabledLibFeature { gate_name, .. }| LibFeature { symbol: gate_name.to_string() })
|
.map(|EnabledLibFeature { gate_name, .. }| LibFeature {
|
||||||
|
symbol: gate_name.to_string(),
|
||||||
|
timestamp: now(),
|
||||||
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
let lang_features = self
|
let lang_features = self
|
||||||
|
@ -711,6 +724,7 @@ impl Features {
|
||||||
.map(|EnabledLangFeature { gate_name, stable_since, .. }| LangFeature {
|
.map(|EnabledLangFeature { gate_name, stable_since, .. }| LangFeature {
|
||||||
symbol: gate_name.to_string(),
|
symbol: gate_name.to_string(),
|
||||||
since: stable_since.map(|since| since.to_string()),
|
since: stable_since.map(|since| since.to_string()),
|
||||||
|
timestamp: now(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -58,12 +58,17 @@ fn test_metrics_dump() {
|
||||||
);
|
);
|
||||||
|
|
||||||
let message = rfs::read_to_string(json_path);
|
let message = rfs::read_to_string(json_path);
|
||||||
let parsed: serde_json::Value =
|
let mut parsed: serde_json::Value =
|
||||||
serde_json::from_str(&message).expect("metrics should be dumped as json");
|
serde_json::from_str(&message).expect("metrics should be dumped as json");
|
||||||
|
// remove timestamps
|
||||||
|
assert!(parsed["lib_features"][0]["timestamp"].is_number());
|
||||||
|
assert!(parsed["lang_features"][0]["timestamp"].is_number());
|
||||||
|
parsed["lib_features"][0]["timestamp"] = serde_json::json!(null);
|
||||||
|
parsed["lang_features"][0]["timestamp"] = serde_json::json!(null);
|
||||||
let expected = serde_json::json!(
|
let expected = serde_json::json!(
|
||||||
{
|
{
|
||||||
"lib_features":[{"symbol":"ascii_char"}],
|
"lib_features":[{"symbol":"ascii_char", "timestamp":null}],
|
||||||
"lang_features":[{"symbol":"box_patterns","since":null}]
|
"lang_features":[{"symbol":"box_patterns","since":null, "timestamp":null}]
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue