1 <!DOCTYPE html> 2 <!-- 3 Copyright (c) 2014 The Chromium Authors. All rights reserved. 4 Use of this source code is governed by a BSD-style license that can be 5 found in the LICENSE file. 6 --> 7 8 <link rel="import" href="/tracing/model/helpers/chrome_process_helper.html"> 9 10 <script> 11 'use strict'; 12 13 /** 14 * @fileoverview Utilities for accessing trace data about the Chrome browser. 15 */ 16 tr.exportTo('tr.model.helpers', function() { 17 function ChromeBrowserHelper(modelHelper, process) { 18 tr.model.helpers.ChromeProcessHelper.call(this, modelHelper, process); 19 this.mainThread_ = process.findAtMostOneThreadNamed('CrBrowserMain'); 20 } 21 22 ChromeBrowserHelper.isBrowserProcess = function(process) { 23 return !!process.findAtMostOneThreadNamed('CrBrowserMain'); 24 }; 25 26 ChromeBrowserHelper.prototype = { 27 __proto__: tr.model.helpers.ChromeProcessHelper.prototype, 28 29 get rendererHelpers() { 30 return this.modelHelper.rendererHelpers; 31 }, 32 33 getLoadingEventsInRange: function(rangeOfInterest) { 34 return this.getAllAsyncSlicesMatching(function(slice) { 35 return slice.title.indexOf('WebContentsImpl Loading') === 0 && 36 rangeOfInterest.intersectsExplicitRangeInclusive( 37 slice.start, slice.end); 38 }); 39 }, 40 41 getCommitProvisionalLoadEventsInRange: function(rangeOfInterest) { 42 return this.getAllAsyncSlicesMatching(function(slice) { 43 return slice.title === 'RenderFrameImpl::didCommitProvisionalLoad' && 44 rangeOfInterest.intersectsExplicitRangeInclusive( 45 slice.start, slice.end); 46 }); 47 }, 48 49 get hasLatencyEvents() { 50 var hasLatency = false; 51 this.modelHelper.model.getAllThreads().some(function(thread) { 52 thread.iterateAllEvents(function(event) { 53 if (!event.isTopLevel) 54 return; 55 if (!(event instanceof tr.e.cc.InputLatencyAsyncSlice)) 56 return; 57 hasLatency = true; 58 }); 59 return hasLatency; 60 }); 61 return hasLatency; 62 }, 63 64 getLatencyEventsInRange: function(rangeOfInterest) { 65 return this.getAllAsyncSlicesMatching(function(slice) { 66 return (slice.title.indexOf('InputLatency') === 0) && 67 rangeOfInterest.intersectsExplicitRangeInclusive( 68 slice.start, slice.end); 69 }); 70 }, 71 72 getAllAsyncSlicesMatching: function(pred, opt_this) { 73 var events = []; 74 this.iterAllThreads(function(thread) { 75 thread.iterateAllEvents(function(slice) { 76 if (pred.call(opt_this, slice)) 77 events.push(slice); 78 }); 79 }); 80 return events; 81 }, 82 83 getAllNetworkEventsInRange: function(rangeOfInterest) { 84 var networkEvents = []; 85 this.modelHelper.model.getAllThreads().forEach(function(thread) { 86 thread.asyncSliceGroup.slices.forEach(function(slice) { 87 var match = false; 88 if (slice.category == 'net' || // old-style URLRequest/Resource 89 slice.category == 'disabled-by-default-netlog' || 90 slice.category == 'netlog') { 91 match = true; 92 } 93 94 if (!match) 95 return; 96 97 if (rangeOfInterest.intersectsExplicitRangeInclusive( 98 slice.start, slice.end)) 99 networkEvents.push(slice); 100 }); 101 }); 102 return networkEvents; 103 }, 104 105 iterAllThreads: function(func, opt_this) { 106 tr.b.iterItems(this.process.threads, function(tid, thread) { 107 func.call(opt_this, thread); 108 }); 109 110 tr.b.iterItems(this.rendererHelpers, function(pid, rendererHelper) { 111 var rendererProcess = rendererHelper.process; 112 tr.b.iterItems(rendererProcess.threads, function(tid, thread) { 113 func.call(opt_this, thread); 114 }); 115 }, this); 116 } 117 }; 118 119 return { 120 ChromeBrowserHelper: ChromeBrowserHelper 121 }; 122 }); 123 </script> 124