summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/metrics/system_health/webview_startup_metric.html
blob: 7d47baf0d9cb871b4ff38874470c57754d15e6dc (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 2016 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/metrics/metric_registry.html">
<link rel="import" href="/tracing/metrics/system_health/utils.html">
<link rel="import" href="/tracing/value/histogram.html">

<script>
'use strict';

tr.exportTo('tr.metrics.sh', function() {
  function webviewStartupMetric(values, model) {
    var startupWallHist = new tr.v.Histogram('webview_startup_wall_time',
        tr.b.Unit.byName.timeDurationInMs_smallerIsBetter);
    startupWallHist.description = 'WebView startup wall time';
    var startupCPUHist = new tr.v.Histogram('webview_startup_cpu_time',
        tr.b.Unit.byName.timeDurationInMs_smallerIsBetter);
    startupCPUHist.description = 'WebView startup CPU time';
    var loadWallHist = new tr.v.Histogram('webview_url_load_wall_time',
        tr.b.Unit.byName.timeDurationInMs_smallerIsBetter);
    loadWallHist.description = 'WebView blank URL load wall time';
    var loadCPUHist = new tr.v.Histogram('webview_url_load_cpu_time',
        tr.b.Unit.byName.timeDurationInMs_smallerIsBetter);
    loadCPUHist.description = 'WebView blank URL load CPU time';

    // TODO(alexandermont): Only iterate over the processes and threads that
    // could contain these events.
    for (var slice of model.getDescendantEvents()) {
      if (!(slice instanceof tr.model.ThreadSlice))
        continue;

      // WebViewStartupInterval is the title of the section of code that is
      // entered (via android.os.Trace.beginSection) when WebView is started
      // up. This value is defined in TelemetryActivity.java.
      if (slice.title === 'WebViewStartupInterval') {
        startupWallHist.addSample(slice.duration);
        startupCPUHist.addSample(slice.cpuDuration);
      }

      // WebViewBlankUrlLoadInterval is the title of the section of code
      // that is entered (via android.os.Trace.beginSection) when WebView
      // is started up. This value is defined in TelemetryActivity.java.
      if (slice.title === 'WebViewBlankUrlLoadInterval') {
        loadWallHist.addSample(slice.duration);
        loadCPUHist.addSample(slice.cpuDuration);
      }
    }

    values.addHistogram(startupWallHist);
    values.addHistogram(startupCPUHist);
    values.addHistogram(loadWallHist);
    values.addHistogram(loadCPUHist);
  }

  tr.metrics.MetricRegistry.register(webviewStartupMetric);

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