Skip to content

Commit 9bae170

Browse files
committed
Refactor compile benchmark profiling shortcut into a separate component
1 parent cbdf7fb commit 9bae170

File tree

3 files changed

+93
-62
lines changed

3 files changed

+93
-62
lines changed

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

Lines changed: 7 additions & 61 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,7 @@ 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";
2626
2727
const props = defineProps<{
2828
testCase: CompileTestCase;
@@ -269,31 +269,6 @@ const relativeChartElement: Ref<HTMLElement | null> = ref(null);
269269
const absoluteChartElement: Ref<HTMLElement | null> = ref(null);
270270
const graphRange = computed(() => getGraphRange(props.artifact));
271271
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-
297272
const sectionsDetail: Ref<CompileDetailSections | null> = ref(null);
298273
onMounted(() => {
299274
loadGraphs().then((d) => {
@@ -455,40 +430,11 @@ onMounted(() => {
455430
</div>
456431
</div>
457432
</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"
433+
<div class="shortcut">
434+
<ProfileShortcut
435+
:artifact="props.artifact"
436+
:base-artifact="props.baseArtifact"
437+
:test-case="props.testCase"
492438
/>
493439
</div>
494440
</div>
@@ -521,7 +467,7 @@ onMounted(() => {
521467
align-items: center;
522468
}
523469
}
524-
.command {
470+
.shortcut {
525471
margin-top: 15px;
526472
text-align: left;
527473
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
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+
import {CompileTestCase, Profile} from "../../common";
36
import {computed} from "vue";
47
58
const props = defineProps<{
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<script setup lang="ts">
2+
import {computed, ref, Ref} from "vue";
3+
import {CompileTestCase} from "../../common";
4+
import {ArtifactDescription} from "../../../types";
5+
import Tooltip from "../../../tooltip.vue";
6+
import CachegrindCmd from "./cachegrind-cmd.vue";
7+
8+
const props = defineProps<{
9+
artifact: ArtifactDescription;
10+
baseArtifact: ArtifactDescription;
11+
testCase: CompileTestCase;
12+
}>();
13+
14+
enum ProfileCommand {
15+
Before = "before",
16+
After = "after",
17+
Diff = "diff",
18+
}
19+
20+
function changeProfileCommand(event: Event) {
21+
const target = event.target as HTMLSelectElement;
22+
profileCommand.value = target.value as ProfileCommand;
23+
}
24+
25+
const profileCommand: Ref<ProfileCommand> = ref(ProfileCommand.Diff);
26+
const profileCommit = computed(() => {
27+
if (profileCommand.value === ProfileCommand.Before) {
28+
return props.baseArtifact.commit;
29+
}
30+
return props.artifact.commit;
31+
});
32+
const profileBaselineCommit = computed(() => {
33+
if (profileCommand.value === ProfileCommand.Diff) {
34+
return props.baseArtifact.commit;
35+
}
36+
return undefined;
37+
});
38+
</script>
39+
40+
<template>
41+
<div class="title">
42+
Local profiling command
43+
<Tooltip>
44+
Execute this command in a checkout of
45+
<a href="https://github.com/rust-lang/rustc-perf">rustc-perf</a>, after a
46+
`cargo build --release`, to generate a Cachegrind profile.
47+
</Tooltip>
48+
</div>
49+
50+
<select @change="changeProfileCommand">
51+
<option
52+
:value="ProfileCommand.Diff"
53+
:selected="profileCommand === ProfileCommand.Diff"
54+
>
55+
Diff
56+
</option>
57+
<option
58+
:value="ProfileCommand.Before"
59+
:selected="profileCommand === ProfileCommand.Before"
60+
>
61+
Baseline commit
62+
</option>
63+
<option
64+
:value="ProfileCommand.After"
65+
:selected="profileCommand === ProfileCommand.After"
66+
>
67+
Benchmarked commit
68+
</option>
69+
</select>
70+
71+
<CachegrindCmd
72+
:commit="profileCommit"
73+
:baseline-commit="profileBaselineCommit"
74+
:test-case="props.testCase"
75+
/>
76+
</template>
77+
78+
<style scoped lang="scss">
79+
.title {
80+
font-weight: bold;
81+
}
82+
</style>

0 commit comments

Comments
 (0)