blob: 9407a2e73f390fa64a3695c40c8eaf9439085b56 [file] [log] [blame]
Chris Craik93216d02015-03-05 13:58:42 -08001<!DOCTYPE html>
2<!--
3Copyright (c) 2014 The Chromium Authors. All rights reserved.
4Use of this source code is governed by a BSD-style license that can be
5found in the LICENSE file.
6-->
Chris Craikf516a622015-04-01 17:52:39 -07007<link rel="import" href="/extras/audits/chrome_process_helper.html">
Chris Craik44c28202015-05-12 17:25:16 -07008<link rel="import" href="/extras/cc/input_latency_async_slice.html">
Chris Craik93216d02015-03-05 13:58:42 -08009
10<script>
11'use strict';
12
13/**
14 * @fileoverview Utilities for accessing trace data about the Chrome browser.
15 */
16tv.exportTo('tv.e.audits', function() {
Chris Craikf516a622015-04-01 17:52:39 -070017 function ChromeBrowserHelper(modelHelper, process) {
18 tv.e.audits.ChromeProcessHelper.call(this, modelHelper, process);
Chris Craik44c28202015-05-12 17:25:16 -070019 this.mainThread_ = process.findAtMostOneThreadNamed('CrBrowserMain');
Chris Craik93216d02015-03-05 13:58:42 -080020 }
21
Chris Craik44c28202015-05-12 17:25:16 -070022 ChromeBrowserHelper.isBrowserProcess = function(process) {
23 if (!process.findAtMostOneThreadNamed('CrBrowserMain'))
24 return false;
25 return true;
26 };
27
Chris Craikf516a622015-04-01 17:52:39 -070028 ChromeBrowserHelper.prototype = {
29 __proto__: tv.e.audits.ChromeProcessHelper.prototype,
Chris Craik93216d02015-03-05 13:58:42 -080030
Chris Craik44c28202015-05-12 17:25:16 -070031 get rendererProcesses() {
32 return this.modelHelper.rendererProcesses;
33 },
34
Chris Craik93216d02015-03-05 13:58:42 -080035 getLoadingEventsInRange: function(rangeOfInterest) {
36 var loadingEvents = [];
37 tv.b.iterItems(this.process.threads, function(tid, thread) {
38 thread.iterateAllEvents(function(event) {
39 if (event.title.indexOf('WebContentsImpl Loading') !== 0)
40 return;
41 if (rangeOfInterest.intersectsExplicitRange(event.start, event.end))
42 loadingEvents.push(event);
43 });
44 });
45 return loadingEvents;
46 },
47
48 get hasLatencyEvents() {
49 var hasLatency = false;
Chris Craikf516a622015-04-01 17:52:39 -070050 this.modelHelper.model.getAllThreads().forEach(function(thread) {
Chris Craik93216d02015-03-05 13:58:42 -080051 thread.iterateAllEvents(function(event) {
Chris Craik44c28202015-05-12 17:25:16 -070052 if (!event.isTopLevel)
53 return;
54 if (!(event instanceof tv.e.cc.InputLatencyAsyncSlice))
55 return;
56 hasLatency = true;
Chris Craik93216d02015-03-05 13:58:42 -080057 });
58 });
59 return hasLatency;
60 },
61
62 getLatencyEventsInRange: function(rangeOfInterest) {
63 var latencyEvents = [];
Chris Craikf516a622015-04-01 17:52:39 -070064 this.modelHelper.model.getAllThreads().forEach(function(thread) {
Chris Craik93216d02015-03-05 13:58:42 -080065 thread.iterateAllEvents(function(event) {
Chris Craik44c28202015-05-12 17:25:16 -070066 if (!event.isTopLevel)
67 return;
68 if (!(event instanceof tv.e.cc.InputLatencyAsyncSlice))
Chris Craik93216d02015-03-05 13:58:42 -080069 return;
70 if (rangeOfInterest.intersectsExplicitRange(event.start, event.end))
71 latencyEvents.push(event);
72 });
73 });
74 return latencyEvents;
75 },
76
Chris Craik44c28202015-05-12 17:25:16 -070077 getAllAsyncSlicesMatching: function(pred, opt_this) {
78 var events = [];
79 this.iterAllThreads(function(thread) {
80 thread.asyncSliceGroup.slices.forEach(function(slice) {
81 if (pred.call(opt_this, slice))
82 events.push(slice);
83 });
Chris Craik93216d02015-03-05 13:58:42 -080084 });
Chris Craik44c28202015-05-12 17:25:16 -070085 return events;
Chris Craik93216d02015-03-05 13:58:42 -080086 },
87
88 getAllNetworkEventsInRange: function(rangeOfInterest) {
89 var networkEvents = [];
Chris Craikf516a622015-04-01 17:52:39 -070090 this.modelHelper.model.getAllThreads().forEach(function(thread) {
Chris Craik93216d02015-03-05 13:58:42 -080091 thread.asyncSliceGroup.slices.forEach(function(slice) {
92 var match = false;
93 if (slice.cat == 'net' || // old-style URLRequest/Resource slices.
94 slice.cat == 'disabled-by-default-netlog' || // early netlog.
95 slice.cat == 'netlog') {
96 match = true;
97 }
98
99 if (!match)
100 return;
101
102 if (rangeOfInterest.intersectsExplicitRange(slice.start, slice.end))
103 networkEvents.push(slice);
104 });
105 });
106 return networkEvents;
Chris Craik44c28202015-05-12 17:25:16 -0700107 },
108
109 iterAllThreads: function(func, opt_this) {
110 tv.b.iterItems(this.process.threads, function(tid, thread) {
111 func.call(opt_this, thread);
112 });
113 this.rendererProcesses.forEach(function(rendererProcess) {
114 tv.b.iterItems(rendererProcess.threads, function(tid, thread) {
115 func.call(opt_this, thread);
116 });
117 });
Chris Craik93216d02015-03-05 13:58:42 -0800118 }
119 };
120
121 return {
Chris Craikf516a622015-04-01 17:52:39 -0700122 ChromeBrowserHelper: ChromeBrowserHelper
Chris Craik93216d02015-03-05 13:58:42 -0800123 };
124});
125</script>