Skip to content

Commit 79dd74d

Browse files
authored
Merge pull request #1678 from lqd/debug-metadata
Show `dev` profile metadata for benchmarks
2 parents b904a5c + 78d4650 commit 79dd74d

File tree

7 files changed

+36
-16
lines changed

7 files changed

+36
-16
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/frontend/src/pages/compare/compile/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export interface CompileBenchmarkMetadata {
6767
binary: boolean | null;
6868
iterations: number | null;
6969
release_profile: CargoProfileMetadata;
70+
dev_profile: CargoProfileMetadata;
7071
}
7172

7273
export interface CompileBenchmarkComparison {

site/frontend/src/pages/compare/compile/comparisons-table.vue

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ Category: ${metadata.category}
7373
if (metadata.iterations !== null) {
7474
tooltip += `Iterations: ${metadata.iterations}\n`;
7575
}
76-
if (testCase.profile === "opt" && metadata.release_profile !== null) {
77-
const {lto, debug, codegen_units} = metadata.release_profile;
76+
const addMetadata = ({lto, debug, codegen_units}) => {
7877
if (lto !== null) {
7978
tooltip += `LTO: ${lto}\n`;
8079
}
@@ -84,6 +83,11 @@ Category: ${metadata.category}
8483
if (codegen_units !== null) {
8584
tooltip += `Codegen units: ${codegen_units}\n`;
8685
}
86+
};
87+
if (testCase.profile === "opt" && metadata.release_profile !== null) {
88+
addMetadata(metadata.release_profile);
89+
} else if (testCase.profile === "debug" && metadata.dev_profile !== null) {
90+
addMetadata(metadata.dev_profile);
8791
}
8892
8993
return tooltip;

site/src/api.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub mod comparison {
159159
pub binary: Option<bool>,
160160
pub iterations: Option<u32>,
161161
pub release_profile: Option<ProfileMetadata>,
162+
pub dev_profile: Option<ProfileMetadata>,
162163
}
163164

164165
#[derive(Debug, Clone, Serialize)]

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
})

site/src/comparison.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ pub async fn handle_compare(
185185
binary: metadata.map(|m| m.perf_config.artifact() == ArtifactType::Binary),
186186
iterations: metadata.map(|m| m.perf_config.iterations() as u32),
187187
release_profile: metadata.map(|m| m.release_metadata.clone()),
188+
dev_profile: metadata.map(|m| m.dev_metadata.clone()),
188189
}
189190
})
190191
.collect();

0 commit comments

Comments
 (0)