Skip to content

Commit

Permalink
dynamically use perfetto
Browse files Browse the repository at this point in the history
  • Loading branch information
s7tya committed Sep 16, 2024
1 parent af1e9af commit d309b2c
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 4 deletions.
1 change: 1 addition & 0 deletions site/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
frontend/node_modules
frontend/dist/**/
frontend/.parcel-cache
frontend/static/perfetto
31 changes: 31 additions & 0 deletions site/frontend/download_perfetto.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

commit_hash="c74251226a8caa0b43377902ee06d2570faa0c15"
git clone https://github.com/google/perfetto.git perfetto_tmp

cd perfetto_tmp
git checkout $commit_hash || exit 1

function allow_url_in_csp() {
url=$1
sed -i.bak "1,/^[[:space:]]*'blob:'/s/^\([[:space:]]*\)'blob:'/\1'$(echo "$url" | sed 's/\//\\\//g')',\n\1'blob:'/" ui/src/frontend/index.ts
}

allow_url_in_csp 'https://perf.rust-lang.org'
allow_url_in_csp 'http://localhost:2346'

patch -u ui/src/frontend/trace_url_handler.ts < ../perfetto_trace_url_handler.patch

tools/install-build-deps --ui
ui/build

cd ..

rm -rf static/perfetto
mkdir -p static/perfetto
mv perfetto_tmp/out/ui/ui/dist/* static/perfetto/

if [ "$DEBUG_EMBEDDED_PERFETTO" != true ] ; then
echo "Removing temporal perfetto repository"
rm -rf perfetto_tmp
fi
1 change: 1 addition & 0 deletions site/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "1.0.0",
"description": "",
"scripts": {
"install-perfetto": "./download_perfetto.sh",
"watch": "parcel watch --no-hmr",
"build": "parcel build",
"fmt": "prettier --write src",
Expand Down
15 changes: 15 additions & 0 deletions site/frontend/perfetto_trace_url_handler.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
--- ui/src/frontend/trace_url_handler.ts.bak 2024-09-15 21:20:31
+++ ui/src/frontend/trace_url_handler.ts 2024-09-15 21:34:02
@@ -217,11 +217,7 @@
}

function loadTraceFromUrl(url: string) {
- const isLocalhostTraceUrl = ['127.0.0.1', 'localhost'].includes(
- new URL(url).hostname,
- );
-
- if (isLocalhostTraceUrl) {
+ if (false) {
// This handles the special case of tools/record_android_trace serving the
// traces from a local webserver and killing it immediately after having
// seen the HTTP GET request. In those cases store the trace as a file, so
15 changes: 12 additions & 3 deletions site/frontend/src/components/perfetto-link.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup lang="ts">
import {computed} from "vue";
import {computed, inject} from "vue";
import {openTraceInPerfetto} from "../perfetto";
import {chromeProfileUrl} from "../self-profile";
import {CompileTestCase} from "../pages/compare/compile/common";
Expand All @@ -22,14 +22,23 @@ const link = computed(() => {
const traceTitle = computed(() => {
return `${props.testCase.benchmark}-${props.testCase.profile}-${props.testCase.scenario} (${props.artifact.commit})`;
});
const isEmbeddedPerfettoEnabled = inject("isEmbeddedPerfettoEnabled");
</script>

<template>
<a
@click="openTraceInPerfetto(link, traceTitle)"
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."
:href="`/perfetto/index.html?url=${encodeURIComponent(link)}`"
v-if="isEmbeddedPerfettoEnabled"
><slot></slot
></a>
<a
@click="openTraceInPerfetto(link, traceTitle)"
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."
v-else
>
<slot></slot>
</a>
</template>

<style scoped lang="scss">
Expand Down
9 changes: 8 additions & 1 deletion site/frontend/src/pages/compare.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import Compare from "./compare/page.vue";
import {createApp} from "vue";
import {createApp, ref} from "vue";
import WithSuspense from "../components/with-suspense.vue";
import {checkIsEmbeddedPerfettoEnabled} from "../perfetto";

const isEmbeddedPerfettoEnabled = ref(false);
checkIsEmbeddedPerfettoEnabled().then((res) => {
isEmbeddedPerfettoEnabled.value = res;
});

const app = createApp(WithSuspense, {
component: Compare,
});
app.provide("isEmbeddedPerfettoEnabled", isEmbeddedPerfettoEnabled);
app.mount("#app");
6 changes: 6 additions & 0 deletions site/frontend/src/perfetto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,9 @@ function openTrace(arrayBuffer: ArrayBuffer, title: string) {

window.addEventListener("message", onMessageHandler);
}

export async function checkIsEmbeddedPerfettoEnabled(): Promise<boolean> {
const result = await fetch(`/perfetto/index.html`);

return result.status === 200;
}
5 changes: 5 additions & 0 deletions site/src/resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ use rust_embed::RustEmbed;
#[include = "*.css"]
#[include = "*.svg"]
#[include = "*.png"]
#[include = "*.html"]
#[include = "*.woff2"]
#[include = "*.map"]
#[include = "*.json"]
#[include = "*.wasm"]
struct StaticAssets;

/// Frontend source files compiled by `npm`.
Expand Down

0 comments on commit d309b2c

Please sign in to comment.