Skip to content

Commit 5367aad

Browse files
authored
Merge pull request #1773 from Kobzol/binary-size-cmd-shortcut
Add binary size local command shortcut to benchmark detail
2 parents cbdf7fb + 0fdfc9e commit 5367aad

File tree

5 files changed

+195
-78
lines changed

5 files changed

+195
-78
lines changed

site/frontend/src/pages/compare/compile/table/benchmark-detail.vue

Lines changed: 26 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import {daysBetweenDates, getFutureDate, getPastDate} from "./utils";
1212
import {GraphRenderOpts, renderPlots} from "../../../../graph/render";
1313
import {GraphData, GraphKind, GraphsSelector} from "../../../../graph/data";
1414
import uPlot from "uplot";
15-
import CachegrindCmd from "../../../../components/cachegrind-cmd.vue";
1615
import {
1716
COMPILE_DETAIL_GRAPHS_RESOLVER,
1817
COMPILE_DETAIL_SECTIONS_RESOLVER,
@@ -23,6 +22,8 @@ import {
2322
} from "./detail-resolver";
2423
import CompileSectionsChart from "./sections-chart.vue";
2524
import PerfettoLink from "../../../../components/perfetto-link.vue";
25+
import ProfileShortcut from "./shortcuts/profile-shortcut.vue";
26+
import BinarySizeShortcut from "./shortcuts/binary-size-shortcut.vue";
2627
2728
const props = defineProps<{
2829
testCase: CompileTestCase;
@@ -32,6 +33,8 @@ const props = defineProps<{
3233
benchmarkMap: CompileBenchmarkMap;
3334
}>();
3435
36+
const BINARY_SIZE_METRIC: string = "size:linked_artifact";
37+
3538
type GraphRange = {
3639
start: string;
3740
end: string;
@@ -269,31 +272,6 @@ const relativeChartElement: Ref<HTMLElement | null> = ref(null);
269272
const absoluteChartElement: Ref<HTMLElement | null> = ref(null);
270273
const graphRange = computed(() => getGraphRange(props.artifact));
271274
272-
enum ProfileCommand {
273-
Before = "before",
274-
After = "after",
275-
Diff = "diff",
276-
}
277-
278-
const profileCommand: Ref<ProfileCommand> = ref(ProfileCommand.Diff);
279-
const profileCommit = computed(() => {
280-
if (profileCommand.value === ProfileCommand.Before) {
281-
return props.baseArtifact.commit;
282-
}
283-
return props.artifact.commit;
284-
});
285-
const profileBaselineCommit = computed(() => {
286-
if (profileCommand.value === ProfileCommand.Diff) {
287-
return props.baseArtifact.commit;
288-
}
289-
return undefined;
290-
});
291-
292-
function changeProfileCommand(event: Event) {
293-
const target = event.target as HTMLSelectElement;
294-
profileCommand.value = target.value as ProfileCommand;
295-
}
296-
297275
const sectionsDetail: Ref<CompileDetailSections | null> = ref(null);
298276
onMounted(() => {
299277
loadGraphs().then((d) => {
@@ -373,17 +351,17 @@ onMounted(() => {
373351
<PerfettoLink
374352
:artifact="props.baseArtifact"
375353
:test-case="props.testCase"
376-
>query trace</PerfettoLink
377-
>
354+
>query trace
355+
</PerfettoLink>
378356
</li>
379357
<li>
380358
After:
381359
<a :href="detailedQueryLink(props.artifact)" target="_blank"
382360
>self-profile</a
383361
>,
384362
<PerfettoLink :artifact="props.artifact" :test-case="props.testCase"
385-
>query trace</PerfettoLink
386-
>
363+
>query trace
364+
</PerfettoLink>
387365
</li>
388366
<li>
389367
<a
@@ -455,40 +433,20 @@ onMounted(() => {
455433
</div>
456434
</div>
457435
</div>
458-
<div class="command">
459-
<div class="title bold">
460-
Local profiling command<Tooltip>
461-
Execute this command in a checkout of
462-
<a href="https://github.com/rust-lang/rustc-perf">rustc-perf</a>,
463-
after a `cargo build --release`, to generate a Cachegrind profile.
464-
</Tooltip>
465-
</div>
466-
467-
<select @change="changeProfileCommand">
468-
<option
469-
:value="ProfileCommand.Diff"
470-
:selected="profileCommand === ProfileCommand.Diff"
471-
>
472-
Diff
473-
</option>
474-
<option
475-
:value="ProfileCommand.Before"
476-
:selected="profileCommand === ProfileCommand.Before"
477-
>
478-
Baseline commit
479-
</option>
480-
<option
481-
:value="ProfileCommand.After"
482-
:selected="profileCommand === ProfileCommand.After"
483-
>
484-
Benchmarked commit
485-
</option>
486-
</select>
487-
488-
<CachegrindCmd
489-
:commit="profileCommit"
490-
:baseline-commit="profileBaselineCommit"
491-
:test-case="testCase"
436+
<div class="shortcut">
437+
<template v-if="props.metric === BINARY_SIZE_METRIC">
438+
<BinarySizeShortcut
439+
v-if="testCase.profile === 'debug' || testCase.profile === 'opt'"
440+
:artifact="props.artifact"
441+
:base-artifact="props.baseArtifact"
442+
:test-case="props.testCase"
443+
/>
444+
</template>
445+
<ProfileShortcut
446+
v-else
447+
:artifact="props.artifact"
448+
:base-artifact="props.baseArtifact"
449+
:test-case="props.testCase"
492450
/>
493451
</div>
494452
</div>
@@ -509,9 +467,11 @@ onMounted(() => {
509467
flex-wrap: nowrap;
510468
}
511469
}
470+
512471
.graphs {
513472
margin-top: 15px;
514473
}
474+
515475
.rows {
516476
display: flex;
517477
flex-direction: column;
@@ -521,7 +481,8 @@ onMounted(() => {
521481
align-items: center;
522482
}
523483
}
524-
.command {
484+
485+
.shortcut {
525486
margin-top: 15px;
526487
text-align: left;
527488
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<script setup lang="ts">
2+
/**
3+
* This component displays a rustc-perf command for analyzing binary size diff between the baseline
4+
* and the new commit.
5+
**/
6+
7+
import {CompileTestCase} from "../../common";
8+
import {ArtifactDescription} from "../../../types";
9+
import Tooltip from "../../../tooltip.vue";
10+
import {normalizeProfile} from "./utils";
11+
12+
const props = defineProps<{
13+
artifact: ArtifactDescription;
14+
baseArtifact: ArtifactDescription;
15+
testCase: CompileTestCase;
16+
}>();
17+
18+
function normalizeBackend(backend: string): string {
19+
if (backend === "llvm") {
20+
return "Llvm";
21+
} else if (backend == "cranelift") {
22+
return "Cranelift";
23+
}
24+
return "<invalid backend>";
25+
}
26+
</script>
27+
28+
<template>
29+
<div class="title">
30+
Command for analyzing binary size locally
31+
<Tooltip>
32+
Execute this command in a checkout of
33+
<a href="https://github.com/rust-lang/rustc-perf">rustc-perf</a>, after a
34+
`cargo build --release`, to compare binary sizes.
35+
</Tooltip>
36+
</div>
37+
38+
<pre><code>./target/release/collector binary_stats \
39+
+{{ props.baseArtifact.commit }} \
40+
--rustc2 +{{ props.artifact.commit }} \
41+
--include {{ testCase.benchmark }} \
42+
--profile {{ normalizeProfile(testCase.profile) }} \
43+
--backend {{ normalizeBackend(testCase.backend) }}</code></pre>
44+
</template>
45+
46+
<style scoped lang="scss">
47+
.title {
48+
font-weight: bold;
49+
}
50+
51+
pre {
52+
background-color: #eeeeee;
53+
}
54+
55+
code {
56+
user-select: all;
57+
}
58+
</style>

site/frontend/src/components/cachegrind-cmd.vue renamed to site/frontend/src/pages/compare/compile/table/shortcuts/cachegrind-cmd.vue

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
<script setup lang="ts">
2-
import {CompileTestCase, Profile} from "../pages/compare/compile/common";
2+
/**
3+
* This component displays a rustc-perf command for profiling a compile benchmark with Cachegrind.
4+
**/
5+
6+
import {CompileTestCase} from "../../common";
37
import {computed} from "vue";
8+
import {normalizeProfile} from "./utils";
49
510
const props = defineProps<{
611
commit: string;
@@ -16,18 +21,6 @@ const firstCommit = computed(() => {
1621
}
1722
});
1823
19-
function normalizeProfile(profile: Profile): string {
20-
if (profile === "opt") {
21-
return "Opt";
22-
} else if (profile === "debug") {
23-
return "Debug";
24-
} else if (profile === "check") {
25-
return "Check";
26-
} else if (profile === "doc") {
27-
return "Doc";
28-
}
29-
return "<invalid profile>";
30-
}
3124
function normalizeScenario(scenario: string): string {
3225
if (scenario === "full") {
3326
return "Full";
@@ -55,6 +48,7 @@ function normalizeScenario(scenario: string): string {
5548
pre {
5649
background-color: #eeeeee;
5750
}
51+
5852
code {
5953
user-select: all;
6054
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<script setup lang="ts">
2+
/**
3+
* This component displays a select box that allows users to choose between three variants
4+
* of the `CachegrindCmd` component with a local `rustc-perf` profiling command.
5+
* Users can choose either to profile the baseline commit, the new commit, or to profile both
6+
* and display a diff.
7+
**/
8+
9+
import {computed, ref, Ref} from "vue";
10+
import {CompileTestCase} from "../../common";
11+
import {ArtifactDescription} from "../../../types";
12+
import Tooltip from "../../../tooltip.vue";
13+
import CachegrindCmd from "./cachegrind-cmd.vue";
14+
15+
const props = defineProps<{
16+
artifact: ArtifactDescription;
17+
baseArtifact: ArtifactDescription;
18+
testCase: CompileTestCase;
19+
}>();
20+
21+
enum ProfileCommand {
22+
Before = "before",
23+
After = "after",
24+
Diff = "diff",
25+
}
26+
27+
function changeProfileCommand(event: Event) {
28+
const target = event.target as HTMLSelectElement;
29+
profileCommand.value = target.value as ProfileCommand;
30+
}
31+
32+
const profileCommand: Ref<ProfileCommand> = ref(ProfileCommand.Diff);
33+
const profileCommit = computed(() => {
34+
if (profileCommand.value === ProfileCommand.Before) {
35+
return props.baseArtifact.commit;
36+
}
37+
return props.artifact.commit;
38+
});
39+
const profileBaselineCommit = computed(() => {
40+
if (profileCommand.value === ProfileCommand.Diff) {
41+
return props.baseArtifact.commit;
42+
}
43+
return undefined;
44+
});
45+
</script>
46+
47+
<template>
48+
<div class="title">
49+
Command for profiling locally
50+
<Tooltip>
51+
Execute this command in a checkout of
52+
<a href="https://github.com/rust-lang/rustc-perf">rustc-perf</a>, after a
53+
`cargo build --release`, to generate a Cachegrind profile.
54+
</Tooltip>
55+
</div>
56+
57+
<select @change="changeProfileCommand">
58+
<option
59+
:value="ProfileCommand.Diff"
60+
:selected="profileCommand === ProfileCommand.Diff"
61+
>
62+
Diff
63+
</option>
64+
<option
65+
:value="ProfileCommand.Before"
66+
:selected="profileCommand === ProfileCommand.Before"
67+
>
68+
Baseline commit
69+
</option>
70+
<option
71+
:value="ProfileCommand.After"
72+
:selected="profileCommand === ProfileCommand.After"
73+
>
74+
Benchmarked commit
75+
</option>
76+
</select>
77+
78+
<CachegrindCmd
79+
:commit="profileCommit"
80+
:baseline-commit="profileBaselineCommit"
81+
:test-case="props.testCase"
82+
/>
83+
</template>
84+
85+
<style scoped lang="scss">
86+
.title {
87+
font-weight: bold;
88+
}
89+
</style>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {Profile} from "../../common";
2+
3+
// Normalize profile from a test case to a CLI value for collector.
4+
export function normalizeProfile(profile: Profile): string {
5+
if (profile === "opt") {
6+
return "Opt";
7+
} else if (profile === "debug") {
8+
return "Debug";
9+
} else if (profile === "check") {
10+
return "Check";
11+
} else if (profile === "doc") {
12+
return "Doc";
13+
}
14+
return "<invalid profile>";
15+
}

0 commit comments

Comments
 (0)