Skip to content

Commit 1ad343e

Browse files
committed
add benchmark metadata for the dev profile
1 parent 35c15ba commit 1ad343e

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

site/build.rs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,11 @@ fn main() -> Result<(), Box<dyn Error>> {
5555
let manifest: toml::Value = toml::from_str(&manifest_contents)?;
5656

5757
let table = manifest.as_table().unwrap();
58-
let profile = table.get("profile");
59-
let release = profile
60-
.and_then(|p| p.as_table())
61-
.and_then(|t| t.get("release"))
62-
.and_then(|t| t.as_table());
63-
let debug = release.and_then(|t| t.get("debug"));
64-
let lto = release.and_then(|t| t.get("lto"));
65-
let codegen_units = release.and_then(|t| t.get("codegen-units"));
66-
58+
let profiles = table.get("profile");
6759
let metadata = CompileBenchmarkMetadata {
6860
perf_config: config,
69-
release_metadata: ProfileMetadata {
70-
debug: debug.map(|v| v.to_string()),
71-
lto: lto.map(|v| v.to_string()),
72-
codegen_units: codegen_units.and_then(|v| v.as_integer().map(|v| v as u32)),
73-
},
61+
release_metadata: read_profile_metadata(profiles, "release"),
62+
dev_metadata: read_profile_metadata(profiles, "dev"),
7463
};
7564
suite.insert(benchmark_name, metadata);
7665
}
@@ -82,3 +71,23 @@ fn main() -> Result<(), Box<dyn Error>> {
8271

8372
Ok(())
8473
}
74+
75+
/// If the manifest has `profile.*` entries, read some of the compilation metadata from a built-in
76+
/// profile with the given `profile` name, if it exists (for example, the options for cargo's
77+
/// optimized profile is named `release`).
78+
/// Note that some, or all, of the metadata that we want to display may be missing from the
79+
/// manifest: it just won't be shown in the UI in that case.
80+
fn read_profile_metadata(profiles: Option<&toml::Value>, profile: &str) -> ProfileMetadata {
81+
let profile = profiles
82+
.and_then(|p| p.as_table())
83+
.and_then(|t| t.get(profile))
84+
.and_then(|t| t.as_table());
85+
let debug = profile.and_then(|t| t.get("debug"));
86+
let lto = profile.and_then(|t| t.get("lto"));
87+
let codegen_units = profile.and_then(|t| t.get("codegen-units"));
88+
ProfileMetadata {
89+
debug: debug.map(|v| v.to_string()),
90+
lto: lto.map(|v| v.to_string()),
91+
codegen_units: codegen_units.and_then(|v| v.as_integer().map(|v| v as u32)),
92+
}
93+
}

site/src/benchmark_metadata/metadata.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ pub struct ProfileMetadata {
2222
pub struct CompileBenchmarkMetadata {
2323
pub perf_config: serde_json::Value,
2424
pub release_metadata: ProfileMetadata,
25+
pub dev_metadata: ProfileMetadata,
2526
}
2627

2728
#[derive(serde::Serialize, serde::Deserialize)]

site/src/benchmark_metadata/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub use metadata::ProfileMetadata;
1313
pub struct CompileBenchmarkMetadata {
1414
pub perf_config: BenchmarkConfig,
1515
pub release_metadata: ProfileMetadata,
16+
pub dev_metadata: ProfileMetadata,
1617
}
1718

1819
/// The metadata of compile-time benchmarks is embedded directly within the binary using
@@ -50,6 +51,7 @@ fn load_compile_benchmark_metadata() -> HashMap<String, CompileBenchmarkMetadata
5051
let metadata::CompileBenchmarkMetadata {
5152
perf_config,
5253
release_metadata,
54+
dev_metadata,
5355
} = metadata;
5456
let perf_config: BenchmarkConfig =
5557
serde_json::from_value(perf_config).unwrap_or_else(|error| {
@@ -62,6 +64,7 @@ fn load_compile_benchmark_metadata() -> HashMap<String, CompileBenchmarkMetadata
6264
let metadata = CompileBenchmarkMetadata {
6365
perf_config,
6466
release_metadata,
67+
dev_metadata,
6568
};
6669
(name, metadata)
6770
})

0 commit comments

Comments
 (0)