aboutsummaryrefslogtreecommitdiff
path: root/traceviewer/src/main/resources/io/perfmark/traceviewer/third_party/catapult/index.html
blob: e0abd7e098a570047e0b8c3c354bb07361beefa0 (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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<!DOCTYPE html>
<!--
Copyright (c) 2014 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<head>
    <meta charset="utf-8">
    <script>
        // IO_PERFMARK_WEBCOMPONENTS
    </script>
    <script>
'use strict';

function onTraceViewerImportFail() {
  document.addEventListener('DOMContentLoaded', function() {
    document.body.textContent =
        'tracing/bin/trace_viewer_full.html is missing. ' +
        'Run vulcanize_trace_viewer from $TRACE_VIEWER and reload.';
  });
}
</script>
<!-- IO_PERFMARK_TRACE_IMPORT -->
    <link rel="import" href="trace_viewer_full.html"
          onerror="onTraceViewerImportFail(event)">

    <style>
  html, body {
    box-sizing: border-box;
    overflow: hidden;
    margin: 0px;
    padding: 0;
    width: 100%;
    height: 100%;
  }
  #trace-viewer {
    width: 100%;
    height: 100%;
  }
  #trace-viewer:focus {
    outline: none;
  }
</style>
    <script>
'use strict';

(function() {
  let viewer;
  let url;
  let model;

  // You can set this to true if you want to hide the WebComponentsV0 polyfill
  // warning.
  window.__hideTraceViewerPolyfillWarning = false;

  function load() {
    const req = new XMLHttpRequest();
    const isBinary = /[.]gz$/.test(url) || /[.]zip$/.test(url);
    req.overrideMimeType('text/plain; charset=x-user-defined');
    req.open('GET', url, true);
    if (isBinary) req.responseType = 'arraybuffer';

    req.onreadystatechange = function(event) {
      if (req.readyState !== 4) return;

      window.setTimeout(function() {
        if (req.status === 200) {
          onResult(isBinary ? req.response : req.responseText);
        } else {
          onResultFail(req.status);
        }
      }, 0);
    };
    req.send(null);
  }

  function onResultFail(err) {
    const overlay = new tr.ui.b.Overlay();
    overlay.textContent = err + ': ' + url + ' could not be loaded';
    overlay.title = 'Failed to fetch data';
    overlay.visible = true;
  }

  function onResult(result) {
    model = new tr.Model();
    const i = new tr.importer.Import(model);
    const p = i.importTracesWithProgressDialog([result]);
    p.then(onModelLoaded, onImportFail);
  }

  function onModelLoaded() {
    viewer.model = model;
    viewer.viewTitle = url;
  }

  function onImportFail() {
    const overlay = new tr.ui.b.Overlay();
    overlay.textContent = tr.b.normalizeException(err).message;
    overlay.title = 'Import error';
    overlay.visible = true;
  }

  document.addEventListener('WebComponentsReady', function() {
    const container = document.createElement('track-view-container');
    container.id = 'track_view_container';

    viewer = document.createElement('tr-ui-timeline-view');
    viewer.track_view_container = container;
    Polymer.dom(viewer).appendChild(container);

    viewer.id = 'trace-viewer';
    viewer.globalMode = true;
    Polymer.dom(document.body).appendChild(viewer);

    // IO_PERFMARK_TRACE_URL
    url = './trace.json';
    load();
  });
}());
</script>
</head>
<body>
</body>
</html>