summaryrefslogtreecommitdiffstats
path: root/chromium/third_party/catapult/tracing/tracing/ui/extras/deep_reports/main.html
blob: 88af3f292d34c38d9a7ea175ea9206ddaba9dfd9 (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
<!DOCTYPE html>
<!--
Copyright (c) 2015 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.
-->

<link rel="import" href="/tracing/base/base.html">
<link rel="import" href="/tracing/base/iteration_helpers.html">
<link rel="import" href="/tracing/base/xhr.html">
<link rel="import" href="/tracing/ui/extras/deep_reports/scalar_value.html">

<script>
'use strict';

tr.exportTo('tr.ui.e.deep_reports', function() {
  /**
   * Runs deep reports on the provided files, and pushes telemetry-style
   * values to the results object.
   */
  function main(results, filesInDir) {
    var lastP = new Promise(function(resolve) { resolve(); });

    filesInDir.forEach(function(filename) {
      // TODO(nduca): Make this like telemetry page.
      var page = {
        url: filename
      };
      lastP = lastP.then(function() {
        return loadModelFromFileAsync(filename);
      });
      lastP = lastP.then(function(model) {
        processModel(results, page, model);
      });
    });
    return lastP;
  }

  function loadModelFromFileAsync(filename) {
    return tr.b.getAsync(filename).then(function(trace) {
      var io = new tr.ImportOptions();
      io.shiftWorldToZero = true;
      io.pruneEmptyContainers = false;

      var m = new tr.Model();
      try {
        m.importTraces([trace], io);
      } catch (e) {
        throw new Error('While loading ' + filename + ' got: ' + e.toString());
      }
      return m;
    });
  }

  function processModel(results, page, model) {
    results.addValue(
        new tr.ui.e.deep_reports.ScalarValue(
            page, 'numRailIRs', 'ms', model.userModel.expectations.length));
  }

  return {
    main: main
  };
});
</script>