-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplateOpenWithPerfetto.html
52 lines (41 loc) · 1.34 KB
/
templateOpenWithPerfetto.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<!doctype html>
<html lang="en-us">
<link rel="shortcut icon" href="data:image/x-icon;," type="image/x-icon">
<body>
<p>Opening the trace in a separate window... (please allow popups)</p>
<script type="text/javascript">
const ORIGIN = 'https://ui.perfetto.dev';
function str2ab(str) {
var buf = new ArrayBuffer(str.length); // 2 bytes for each char
var bufView = new Uint8Array(buf);
for (var i=0, strLen=str.length; i<strLen; i++) {
bufView[i] = str.charCodeAt(i);
}
return buf;
}
data = {{ $.Data }};
function openTrace(arrayBuffer, traceUrl) {
const win = window.open(ORIGIN);
if (!win) {
window.alert('Popups blocked! Please unblock them, they are needed to open Perfetto UI');
return;
}
const timer = setInterval(() => win.postMessage('PING', ORIGIN), 50);
const onMessageHandler = (evt) => {
if (evt.data !== 'PONG') return;
// We got a PONG, the UI is ready.
window.clearInterval(timer);
window.removeEventListener('message', onMessageHandler);
win.postMessage({
perfetto: {
buffer: arrayBuffer,
title: 'Timeline-Trace',
url: location.href,
}}, ORIGIN);
};
window.addEventListener('message', onMessageHandler);
}
window.onload = () => openTrace(str2ab(data), "trace.json");
</script>
</body>
</html>