Skip to content

Commit 4866c36

Browse files
authored
Merge pull request #1967 from s7tya/integrate-perfetto
dynamically use perfetto
2 parents af1e9af + d309b2c commit 4866c36

File tree

8 files changed

+79
-4
lines changed

8 files changed

+79
-4
lines changed

site/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
frontend/node_modules
44
frontend/dist/**/
55
frontend/.parcel-cache
6+
frontend/static/perfetto

site/frontend/download_perfetto.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/bin/bash
2+
3+
commit_hash="c74251226a8caa0b43377902ee06d2570faa0c15"
4+
git clone https://github.com/google/perfetto.git perfetto_tmp
5+
6+
cd perfetto_tmp
7+
git checkout $commit_hash || exit 1
8+
9+
function allow_url_in_csp() {
10+
url=$1
11+
sed -i.bak "1,/^[[:space:]]*'blob:'/s/^\([[:space:]]*\)'blob:'/\1'$(echo "$url" | sed 's/\//\\\//g')',\n\1'blob:'/" ui/src/frontend/index.ts
12+
}
13+
14+
allow_url_in_csp 'https://perf.rust-lang.org'
15+
allow_url_in_csp 'http://localhost:2346'
16+
17+
patch -u ui/src/frontend/trace_url_handler.ts < ../perfetto_trace_url_handler.patch
18+
19+
tools/install-build-deps --ui
20+
ui/build
21+
22+
cd ..
23+
24+
rm -rf static/perfetto
25+
mkdir -p static/perfetto
26+
mv perfetto_tmp/out/ui/ui/dist/* static/perfetto/
27+
28+
if [ "$DEBUG_EMBEDDED_PERFETTO" != true ] ; then
29+
echo "Removing temporal perfetto repository"
30+
rm -rf perfetto_tmp
31+
fi

site/frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"description": "",
55
"scripts": {
6+
"install-perfetto": "./download_perfetto.sh",
67
"watch": "parcel watch --no-hmr",
78
"build": "parcel build",
89
"fmt": "prettier --write src",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
--- ui/src/frontend/trace_url_handler.ts.bak 2024-09-15 21:20:31
2+
+++ ui/src/frontend/trace_url_handler.ts 2024-09-15 21:34:02
3+
@@ -217,11 +217,7 @@
4+
}
5+
6+
function loadTraceFromUrl(url: string) {
7+
- const isLocalhostTraceUrl = ['127.0.0.1', 'localhost'].includes(
8+
- new URL(url).hostname,
9+
- );
10+
-
11+
- if (isLocalhostTraceUrl) {
12+
+ if (false) {
13+
// This handles the special case of tools/record_android_trace serving the
14+
// traces from a local webserver and killing it immediately after having
15+
// seen the HTTP GET request. In those cases store the trace as a file, so

site/frontend/src/components/perfetto-link.vue

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import {computed} from "vue";
2+
import {computed, inject} from "vue";
33
import {openTraceInPerfetto} from "../perfetto";
44
import {chromeProfileUrl} from "../self-profile";
55
import {CompileTestCase} from "../pages/compare/compile/common";
@@ -22,14 +22,23 @@ const link = computed(() => {
2222
const traceTitle = computed(() => {
2323
return `${props.testCase.benchmark}-${props.testCase.profile}-${props.testCase.scenario} (${props.artifact.commit})`;
2424
});
25+
26+
const isEmbeddedPerfettoEnabled = inject("isEmbeddedPerfettoEnabled");
2527
</script>
2628

2729
<template>
2830
<a
29-
@click="openTraceInPerfetto(link, traceTitle)"
30-
title="Open the self-profile query trace in Perfetto. You have to wait a bit for the profile to be downloaded after clicking on the link."
31+
:href="`/perfetto/index.html?url=${encodeURIComponent(link)}`"
32+
v-if="isEmbeddedPerfettoEnabled"
3133
><slot></slot
3234
></a>
35+
<a
36+
@click="openTraceInPerfetto(link, traceTitle)"
37+
title="Open the self-profile query trace in Perfetto. You have to wait a bit for the profile to be downloaded after clicking on the link."
38+
v-else
39+
>
40+
<slot></slot>
41+
</a>
3342
</template>
3443

3544
<style scoped lang="scss">

site/frontend/src/pages/compare.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import Compare from "./compare/page.vue";
2-
import {createApp} from "vue";
2+
import {createApp, ref} from "vue";
33
import WithSuspense from "../components/with-suspense.vue";
4+
import {checkIsEmbeddedPerfettoEnabled} from "../perfetto";
5+
6+
const isEmbeddedPerfettoEnabled = ref(false);
7+
checkIsEmbeddedPerfettoEnabled().then((res) => {
8+
isEmbeddedPerfettoEnabled.value = res;
9+
});
410

511
const app = createApp(WithSuspense, {
612
component: Compare,
713
});
14+
app.provide("isEmbeddedPerfettoEnabled", isEmbeddedPerfettoEnabled);
815
app.mount("#app");

site/frontend/src/perfetto.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,9 @@ function openTrace(arrayBuffer: ArrayBuffer, title: string) {
3939

4040
window.addEventListener("message", onMessageHandler);
4141
}
42+
43+
export async function checkIsEmbeddedPerfettoEnabled(): Promise<boolean> {
44+
const result = await fetch(`/perfetto/index.html`);
45+
46+
return result.status === 200;
47+
}

site/src/resources.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@ use rust_embed::RustEmbed;
1111
#[include = "*.css"]
1212
#[include = "*.svg"]
1313
#[include = "*.png"]
14+
#[include = "*.html"]
15+
#[include = "*.woff2"]
16+
#[include = "*.map"]
17+
#[include = "*.json"]
18+
#[include = "*.wasm"]
1419
struct StaticAssets;
1520

1621
/// Frontend source files compiled by `npm`.

0 commit comments

Comments
 (0)