aboutsummaryrefslogtreecommitdiff
path: root/examples/src/main/resources/io/perfmark/examples/perfetto/index.html
blob: 2576d73fd93d862fe4f88bdac905eede8b41a971 (plain)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name=viewport content="width=device-width, initial-scale=1">
    <title>PerfMark Trace UI</title>
    <base href="/">
</head>
<body>
    <h1>PerfMark Trace Viewer</h1>
    <p>
        This is an example Trace Viewer, using the <a href="https://ui.perfetto.dev">Perfetto UI</a>.
    </p>
    <button id="thebutton">Load</button>
    <br />
    <textarea id="logs" cols="80" rows="24">
    </textarea>
    <script>
        (function() {
          let origin = "https://ui.perfetto.dev";
          let logs = document.getElementById("logs");
          let thebutton = document.getElementById("thebutton");
          let thewindow = undefined;

          thebutton.addEventListener("click", function (evt) {
            logs.innerText += "Loading ...\n";
            fetch("trace.json").then(function(result) {
              result.blob().then(function(blob) {
                blob.arrayBuffer().then(arrayBuffer => {
                    logs.innerText += "Trace JSON fetched.\n";
                    if (thewindow) {
                      thewindow.postMessage(arrayBuffer, origin);
                      return;
                    }
                    loadWindow(arrayBuffer);
                });
              });
            });
          });

          function loadWindow(arrayBuffer) {
              if (thewindow === undefined) {
                thewindow = null;
              } else {
                return;
              }
              logs.innerText += "Loading Perfetto Window\n";
              let win = window.open(origin);
              let thetimer = null;
              window.addEventListener("message", function(evt) {
                if (evt.data !== "PONG") {
                  return;
                }
                window.clearInterval(thetimer);
                logs.innerText += "Perfetto Window Ready\n";
                thewindow = win;
                thewindow.postMessage(arrayBuffer, origin);
              });
              thetimer = setInterval(function() {
                win.postMessage("PING", origin);
              }, 250);
          }
        })();
    </script>
</body>
</html>