summaryrefslogtreecommitdiff
path: root/chromium/third_party/catapult/tracing/tracing/model/helpers/chrome_browser_helper.html
blob: d958d69f4d1b58823e70582ab2f3647051d7e110 (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
125
126
127
128
129
130
131
132
133
<!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.
-->

<link rel="import" href="/tracing/base/iteration_helpers.html">
<link rel="import" href="/tracing/model/helpers/chrome_process_helper.html">

<script>
'use strict';

/**
 * @fileoverview Utilities for accessing trace data about the Chrome browser.
 */
tr.exportTo('tr.model.helpers', function() {
  function ChromeBrowserHelper(modelHelper, process) {
    tr.model.helpers.ChromeProcessHelper.call(this, modelHelper, process);
    this.mainThread_ = process.findAtMostOneThreadNamed('CrBrowserMain');
    if (!process.name)
      process.name = ChromeBrowserHelper.PROCESS_NAME;
  }

  ChromeBrowserHelper.PROCESS_NAME = 'Browser';

  ChromeBrowserHelper.isBrowserProcess = function(process) {
    return !!process.findAtMostOneThreadNamed('CrBrowserMain');
  };

  ChromeBrowserHelper.prototype = {
    __proto__: tr.model.helpers.ChromeProcessHelper.prototype,

    // TODO(petrcermak): Pass browser name in a metadata event (see
    // crbug.com/605088).
    get browserName() {
      var hasInProcessRendererThread = this.process.findAllThreadsNamed(
          'Chrome_InProcRendererThread').length > 0;
      return hasInProcessRendererThread ? 'webview' : 'chrome';
    },

    get rendererHelpers() {
      return this.modelHelper.rendererHelpers;
    },

    getLoadingEventsInRange: function(rangeOfInterest) {
      return this.getAllAsyncSlicesMatching(function(slice) {
        return slice.title.indexOf('WebContentsImpl Loading') === 0 &&
            rangeOfInterest.intersectsExplicitRangeInclusive(
                slice.start, slice.end);
      });
    },

    getCommitProvisionalLoadEventsInRange: function(rangeOfInterest) {
      return this.getAllAsyncSlicesMatching(function(slice) {
        return slice.title === 'RenderFrameImpl::didCommitProvisionalLoad' &&
            rangeOfInterest.intersectsExplicitRangeInclusive(
                slice.start, slice.end);
      });
    },

    get hasLatencyEvents() {
      var hasLatency = false;
      for (var thread of this.modelHelper.model.getAllThreads())
        for (var event of thread.getDescendantEvents()) {
          if (!event.isTopLevel)
            continue;
          if (!(event instanceof tr.e.cc.InputLatencyAsyncSlice))
            continue;
          hasLatency = true;
        }
      return hasLatency;
    },

    getLatencyEventsInRange: function(rangeOfInterest) {
      return this.getAllAsyncSlicesMatching(function(slice) {
        return (slice.title.indexOf('InputLatency') === 0) &&
            rangeOfInterest.intersectsExplicitRangeInclusive(
                slice.start, slice.end);
      });
    },

    getAllAsyncSlicesMatching: function(pred, opt_this) {
      var events = [];
      this.iterAllThreads(function(thread) {
        for (var slice of thread.getDescendantEvents())
          if (pred.call(opt_this, slice))
            events.push(slice);
      });
      return events;
    },

    getAllNetworkEventsInRange: function(rangeOfInterest) {
      var networkEvents = [];
      this.modelHelper.model.getAllThreads().forEach(function(thread) {
        thread.asyncSliceGroup.slices.forEach(function(slice) {
          var match = false;
          if (slice.category === 'net' ||  // old-style URLRequest/Resource
              slice.category === 'disabled-by-default-netlog' ||
              slice.category === 'netlog') {
            match = true;
          }

          if (!match)
            return;

          if (rangeOfInterest.intersectsExplicitRangeInclusive(
                slice.start, slice.end))
            networkEvents.push(slice);
        });
      });
      return networkEvents;
    },

    iterAllThreads: function(func, opt_this) {
      tr.b.iterItems(this.process.threads, function(tid, thread) {
        func.call(opt_this, thread);
      });

      tr.b.iterItems(this.rendererHelpers, function(pid, rendererHelper) {
        var rendererProcess = rendererHelper.process;
        tr.b.iterItems(rendererProcess.threads, function(tid, thread) {
          func.call(opt_this, thread);
        });
      }, this);
    }
  };

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