aboutsummaryrefslogtreecommitdiff
path: root/catapult/trace_processor/experimental/mappers/v8_callstats_dump.html
blob: 4756869e59184c004238f712845e17a7e5aed5f3 (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
<!DOCTYPE html>
<!--
Copyright 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/iteration_helpers.html">
<link rel="import" href="/tracing/metrics/system_health/loading_metric.html">
<link rel="import" href="/tracing/mre/function_handle.html">
<link rel="import" href="/tracing/value/value_set.html">

<script>
'use strict';


tr.exportTo('tr.mre', function() {
  function v8CallStatsDump(result, model) {
    var v8_runtime_map = {};
    var totalCount = 0;
    var totalTime = 0;
    var values = new tr.v.ValueSet();

    tr.metrics.sh.loadingMetric(values, model);
    var ttiEntries = values.valueDicts.filter(
        (dict) => dict.name === 'timeToFirstInteractive');
    var numeric = ttiEntries[0].numeric;
    if (numeric.running.count > 1) {
      throw 'Unable to work with a trace that has more than one navigation';
    }

    var binsWithSampleDiagnosticMaps = numeric.centralBins.filter(
        (bin) => bin.diagnosticMaps.length > 0);
    var diagnostic = binsWithSampleDiagnosticMaps[0]
        .diagnosticMaps[0]['breakdown'];

    var tti = diagnostic.value.interactive;

    for (var event of model.getDescendantEvents()) {
      if (!(event instanceof tr.model.ThreadSlice) || event.start > tti)
        continue;
      var v8_runtime = event.args['runtime-call-stats'];

      // For older traces, check if we had an arg called 'runtime-call-stat'
      // instead.
      if (v8_runtime === undefined)
        v8_runtime = event.args['runtime-call-stat'];

      if (v8_runtime !== undefined) {
        try {
          var v8_runtime_object = JSON.parse(v8_runtime);
          for (var runtime_call in v8_runtime_object) {
            // exclude "END" and malformed entries.
            if (v8_runtime_object[runtime_call].length == 2) {
              if (v8_runtime_map[runtime_call] === undefined) {
                v8_runtime_map[runtime_call] = {count: 0, time: 0};
              }
              var runtime_count = v8_runtime_object[runtime_call][0];
              v8_runtime_map[runtime_call].count += runtime_count;
              var runtime_time = v8_runtime_object[runtime_call][1] / 1000;
              v8_runtime_map[runtime_call].time += runtime_time;
              totalCount += runtime_count;
              totalTime += runtime_time;
            }
          }
        } catch (e) {
           console.warn(e);
        }
      }
    }
    for (var i in v8_runtime_map) {
      result.addPair(i, {time: Number(v8_runtime_map[i].time).toFixed(2),
                         count: v8_runtime_map[i].count});
    }
    result.addPair('Total', {time: Number(totalTime).toFixed(2),
                             count: totalCount});
  }

  tr.mre.FunctionRegistry.register(v8CallStatsDump);

  // Exporting for tests.
  return {
    v8CallStatsDump: v8CallStatsDump
  };
});

</script>