Skip to content

Commit 1428f44

Browse files
committed
Add link to Perfetto UI trace visualization in benchmark detail
1 parent e764f2c commit 1428f44

File tree

5 files changed

+139
-10
lines changed

5 files changed

+139
-10
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<script setup lang="ts">
2+
import {computed} from "vue";
3+
import {openTraceInPerfetto} from "../perfetto";
4+
import {croxTraceUrl} from "../self-profile";
5+
import {CompileTestCase} from "../pages/compare/compile/common";
6+
import {ArtifactDescription} from "../pages/compare/types";
7+
8+
const props = defineProps<{
9+
label: string;
10+
artifact: ArtifactDescription;
11+
testCase: CompileTestCase;
12+
}>();
13+
14+
const link = computed(() => {
15+
return croxTraceUrl(
16+
props.artifact.commit,
17+
`${props.testCase.benchmark}-${props.testCase.profile.toLowerCase()}`,
18+
props.testCase.scenario
19+
);
20+
});
21+
const traceTitle = computed(() => {
22+
return `${props.testCase.benchmark}-${props.testCase.profile}-${props.testCase.scenario} (${props.artifact.commit})`;
23+
});
24+
</script>
25+
26+
<template>
27+
<a @click="openTraceInPerfetto(link, traceTitle)">{{ props.label }}</a>
28+
</template>
29+
30+
<style scoped lang="scss">
31+
a {
32+
cursor: pointer;
33+
}
34+
</style>

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

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import {GraphData, GraphKind, GraphsSelector} from "../../../../graph/data";
1414
import uPlot from "uplot";
1515
import CachegrindCmd from "../../../../components/cachegrind-cmd.vue";
1616
import {COMPILE_DETAIL_RESOLVER} from "./detail-resolver";
17+
import {openTraceInPerfetto} from "../../../../perfetto";
18+
import {croxTraceUrl} from "../../../../self-profile";
19+
import PerfettoLink from "../../../../components/perfetto-link.vue";
1720
1821
const props = defineProps<{
1922
testCase: CompileTestCase;
@@ -263,6 +266,27 @@ function changeProfileCommand(event: Event) {
263266
profileCommand.value = target.value as ProfileCommand;
264267
}
265268
269+
const traceLinkBefore = computed(() => {
270+
return croxTraceUrl(
271+
props.artifact.commit,
272+
`${props.testCase.benchmark}-${props.testCase.profile.toLowerCase()}`,
273+
props.testCase.scenario
274+
);
275+
});
276+
const traceLinkAfter = computed(() => {
277+
return croxTraceUrl(
278+
props.baseArtifact.commit,
279+
`${props.testCase.benchmark}-${props.testCase.profile.toLowerCase()}`,
280+
props.testCase.scenario
281+
);
282+
});
283+
const traceLinkTitleBefore = computed(() => {
284+
return `${props.testCase.benchmark}-${props.testCase.profile}-${props.testCase.scenario} (${props.baseArtifact.commit})`;
285+
});
286+
const traceLinkTitleAfter = computed(() => {
287+
return `${props.testCase.benchmark}-${props.testCase.profile}-${props.testCase.scenario} (${props.artifact.commit})`;
288+
});
289+
266290
onMounted(() => renderGraphs());
267291
</script>
268292

@@ -339,11 +363,25 @@ onMounted(() => renderGraphs());
339363
Self-profile (before)
340364
</a>
341365
</li>
366+
<li>
367+
<PerfettoLink
368+
:artifact="props.baseArtifact"
369+
label="Query trace (before)"
370+
:test-case="props.testCase"
371+
/>
372+
</li>
342373
<li>
343374
<a :href="detailedQueryLink(props.artifact)" target="_blank">
344375
Self-profile (after)
345376
</a>
346377
</li>
378+
<li>
379+
<PerfettoLink
380+
:artifact="props.artifact"
381+
label="Query trace (after)"
382+
:test-case="props.testCase"
383+
/>
384+
</li>
347385
<li>
348386
<a :href="benchmarkLink(testCase.benchmark)" target="_blank">
349387
Benchmark source code

site/frontend/src/pages/detailed-query.ts

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {createUrlWithAppendedParams, getUrlParams} from "../utils/navigation";
22
import {postMsgpack} from "../utils/requests";
33
import {SELF_PROFILE_DATA_URL} from "../urls";
4+
import {processedSelfProfileUrl} from "../self-profile";
45

56
function to_seconds(time) {
67
return time / 1000000000;
@@ -59,20 +60,12 @@ function populate_data(data, state: Selector) {
5960
let url = `/perf/download-raw-self-profile?commit=${commit}&benchmark=${bench}&scenario=${run}`;
6061
return `<a href="${url}">raw</a>`;
6162
};
62-
let processed_url = (commit, bench, run, ty) => {
63-
return `/perf/processed-self-profile?commit=${commit}&benchmark=${bench}&scenario=${run}&type=${ty}`;
64-
};
6563
let processed_link = (commit, {benchmark, scenario}, ty) => {
66-
let url = processed_url(commit, benchmark, scenario, ty);
64+
let url = processedSelfProfileUrl(commit, benchmark, scenario, ty);
6765
return `<a href="${url}">${ty}</a>`;
6866
};
69-
let processed_crox_url = (commit, bench, run) => {
70-
let crox_url =
71-
window.location.origin + processed_url(commit, bench, run, "crox");
72-
return encodeURIComponent(crox_url);
73-
};
7467
let firefox_profiler_link = (commit, bench, run) => {
75-
let crox_url = processed_crox_url(commit, bench, run);
68+
let crox_url = encodeURIComponent(croxTraceUrl(commit, bench, run));
7669
let ff_url = `https://profiler.firefox.com/from-url/${crox_url}/marker-chart/?v=5`;
7770
return `<a href="${ff_url}">Firefox profiler</a>`;
7871
};

site/frontend/src/perfetto.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// Code for displaying post-processed self-profile traces in perfetto.dev.
2+
// The process of linking to perfetto is explained at
3+
// https://perfetto.dev/docs/visualization/deep-linking-to-perfetto-ui.
4+
// This code is adapted from https://llvm-compile-time-tracker.com/compare.php
5+
const ORIGIN = "https://ui.perfetto.dev";
6+
7+
export async function openTraceInPerfetto(traceUrl: string, title: string) {
8+
const resp = await fetch(traceUrl);
9+
const blob = await resp.blob();
10+
const arrayBuffer = await blob.arrayBuffer();
11+
openTrace(arrayBuffer, title);
12+
}
13+
14+
function openTrace(arrayBuffer: ArrayBuffer, title: string) {
15+
const win = window.open(ORIGIN);
16+
if (win === null) {
17+
return;
18+
}
19+
20+
const timer = setInterval(() => win.postMessage("PING", ORIGIN), 50);
21+
22+
const onMessageHandler = (evt) => {
23+
if (evt.data !== "PONG") return;
24+
25+
// We got a PONG, the UI is ready.
26+
window.clearInterval(timer);
27+
window.removeEventListener("message", onMessageHandler);
28+
29+
win.postMessage(
30+
{
31+
perfetto: {
32+
buffer: arrayBuffer,
33+
title,
34+
},
35+
},
36+
ORIGIN
37+
);
38+
};
39+
40+
window.addEventListener("message", onMessageHandler);
41+
}

site/frontend/src/self-profile.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Returns the URL to a processed Crox format of a self-profile query.
2+
export function croxTraceUrl(
3+
commit: string,
4+
benchmarkAndProfile: string,
5+
scenario: string
6+
): string {
7+
const relativeUrl = processedSelfProfileUrl(
8+
commit,
9+
benchmarkAndProfile,
10+
scenario,
11+
"crox"
12+
);
13+
return window.location.origin + relativeUrl;
14+
}
15+
16+
export function processedSelfProfileUrl(
17+
commit: string,
18+
benchmarkAndProfile: string,
19+
scenario: string,
20+
type: string
21+
): string {
22+
return `/perf/processed-self-profile?commit=${commit}&benchmark=${benchmarkAndProfile}&scenario=${scenario}&type=${type}`;
23+
}

0 commit comments

Comments
 (0)