Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: third_party/WebKit/Source/devtools/front_end/sdk/CPUProfilerModel.js

Issue 2721663005: [DevTools] Access cpu profiler only when JS capability is present. (Closed)
Patch Set: coverage Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2014 Google Inc. All rights reserved. 2 * Copyright (C) 2014 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 10 *
11 * 2. Redistributions in binary form must reproduce the above 11 * 2. Redistributions in binary form must reproduce the above
12 * copyright notice, this list of conditions and the following disclaimer 12 * copyright notice, this list of conditions and the following disclaimer
13 * in the documentation and/or other materials provided with the 13 * in the documentation and/or other materials provided with the
14 * distribution. 14 * distribution.
15 * 15 *
16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS 16 * THIS SOFTWARE IS PROVIDED BY GOOGLE INC. AND ITS CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC. 19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GOOGLE INC.
20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 * OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28
28 /** 29 /**
29 * @implements {Protocol.ProfilerDispatcher} 30 * @implements {Protocol.ProfilerDispatcher}
30 * @unrestricted
31 */ 31 */
32 SDK.CPUProfilerModel = class extends SDK.SDKModel { 32 SDK.CPUProfilerModel = class extends SDK.SDKModel {
33 /** 33 /**
34 * @param {!SDK.Target} target 34 * @param {!SDK.Target} target
35 */ 35 */
36 constructor(target) { 36 constructor(target) {
37 super(target); 37 super(target);
38 this._isRecording = false; 38 this._isRecording = false;
39 this._profilerAgent = target.profilerAgent();
39 target.registerProfilerDispatcher(this); 40 target.registerProfilerDispatcher(this);
40 target.profilerAgent().enable(); 41 this._profilerAgent.enable();
41 42 this._debuggerModel = /** @type {!SDK.DebuggerModel} */ (target.model(SDK.De buggerModel));
42 this._configureCpuProfilerSamplingInterval();
43 Common.moduleSetting('highResolutionCpuProfiling')
44 .addChangeListener(this._configureCpuProfilerSamplingInterval, this);
45 }
46
47 _configureCpuProfilerSamplingInterval() {
48 var intervalUs = Common.moduleSetting('highResolutionCpuProfiling').get() ? 100 : 1000;
49 this.target().profilerAgent().setSamplingInterval(intervalUs);
50 } 43 }
51 44
52 /** 45 /**
53 * @override 46 * @override
54 * @param {string} id 47 * @param {string} id
55 * @param {!Protocol.Debugger.Location} scriptLocation 48 * @param {!Protocol.Debugger.Location} scriptLocation
56 * @param {string=} title 49 * @param {string=} title
57 */ 50 */
58 consoleProfileStarted(id, scriptLocation, title) { 51 consoleProfileStarted(id, scriptLocation, title) {
59 this._dispatchProfileEvent(SDK.CPUProfilerModel.Events.ConsoleProfileStarted , id, scriptLocation, title); 52 this._dispatchProfileEvent(SDK.CPUProfilerModel.Events.ConsoleProfileStarted , id, scriptLocation, title);
(...skipping 13 matching lines...) Expand all
73 66
74 /** 67 /**
75 * @param {symbol} eventName 68 * @param {symbol} eventName
76 * @param {string} id 69 * @param {string} id
77 * @param {!Protocol.Debugger.Location} scriptLocation 70 * @param {!Protocol.Debugger.Location} scriptLocation
78 * @param {string=} title 71 * @param {string=} title
79 * @param {!Protocol.Profiler.Profile=} cpuProfile 72 * @param {!Protocol.Profiler.Profile=} cpuProfile
80 */ 73 */
81 _dispatchProfileEvent(eventName, id, scriptLocation, title, cpuProfile) { 74 _dispatchProfileEvent(eventName, id, scriptLocation, title, cpuProfile) {
82 // Make sure ProfilesPanel is initialized and CPUProfileType is created. 75 // Make sure ProfilesPanel is initialized and CPUProfileType is created.
83 self.runtime.loadModulePromise('profiler').then(_ => { 76 self.runtime.loadModulePromise('profiler').then(() => {
84 var debuggerModel = 77 var debuggerLocation = SDK.DebuggerModel.Location.fromPayload(this._debugg erModel, scriptLocation);
85 /** @type {!SDK.DebuggerModel} */ (SDK.DebuggerModel.fromTarget(this.t arget()));
86 var debuggerLocation = SDK.DebuggerModel.Location.fromPayload(debuggerMode l, scriptLocation);
87 var globalId = this.target().id() + '.' + id; 78 var globalId = this.target().id() + '.' + id;
88 var data = /** @type {!SDK.CPUProfilerModel.EventData} */ ( 79 var data = /** @type {!SDK.CPUProfilerModel.EventData} */ (
89 {id: globalId, scriptLocation: debuggerLocation, cpuProfile: cpuProfil e, title: title}); 80 {id: globalId, scriptLocation: debuggerLocation, cpuProfile: cpuProfil e, title: title});
90 this.dispatchEventToListeners(eventName, data); 81 this.dispatchEventToListeners(eventName, data);
91 }); 82 });
92 } 83 }
93 84
94 /** 85 /**
95 * @return {boolean} 86 * @return {boolean}
96 */ 87 */
97 isRecordingProfile() { 88 isRecordingProfile() {
98 return this._isRecording; 89 return this._isRecording;
99 } 90 }
100 91
92 /**
93 * @return {!Promise}
alph 2017/02/28 23:59:13 Why promise? It's a sync function
dgozman 2017/03/01 00:18:41 Correct, removed the promise.
94 */
101 startRecording() { 95 startRecording() {
102 this._isRecording = true; 96 this._isRecording = true;
103 this.target().profilerAgent().start();
104 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ProfilesCPUProfileTaken ); 97 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ProfilesCPUProfileTaken );
98 var intervalUs = Common.moduleSetting('highResolutionCpuProfiling').get() ? 100 : 1000;
99 this._profilerAgent.setSamplingInterval(intervalUs);
100 return this._profilerAgent.start();
105 } 101 }
106 102
107 /** 103 /**
108 * @return {!Promise.<?Protocol.Profiler.Profile>} 104 * @return {!Promise.<?Protocol.Profiler.Profile>}
109 */ 105 */
110 stopRecording() { 106 stopRecording() {
111 /** 107 /**
112 * @param {?Protocol.Error} error 108 * @param {?Protocol.Error} error
113 * @param {?Protocol.Profiler.Profile} profile 109 * @param {?Protocol.Profiler.Profile} profile
114 * @return {?Protocol.Profiler.Profile} 110 * @return {?Protocol.Profiler.Profile}
115 */ 111 */
116 function extractProfile(error, profile) { 112 function extractProfile(error, profile) {
117 return !error && profile ? profile : null; 113 return !error && profile ? profile : null;
118 } 114 }
119 this._isRecording = false; 115 this._isRecording = false;
120 return this.target().profilerAgent().stop(extractProfile); 116 return this._profilerAgent.stop(extractProfile);
121 } 117 }
122 118
123 /** 119 /**
124 * @override 120 * @return {!Promise}
125 */ 121 */
126 dispose() { 122 startPreciseCoverage() {
127 Common.moduleSetting('highResolutionCpuProfiling') 123 return this._profilerAgent.startPreciseCoverage();
128 .removeChangeListener(this._configureCpuProfilerSamplingInterval, this); 124 }
125
126 /**
127 * @return {!Promise<!Array<!Protocol.Profiler.ScriptCoverage>>}
128 */
129 takePreciseCoverage() {
130 return this._profilerAgent.takePreciseCoverage((error, coverage) => error ? [] : coverage);
131 }
132
133 /**
134 * @return {!Promise}
135 */
136 stopPreciseCoverage() {
137 return this._profilerAgent.stopPreciseCoverage();
129 } 138 }
130 }; 139 };
131 140
132 // TODO(dgozman): should be JS. 141 SDK.SDKModel.register(SDK.CPUProfilerModel, SDK.Target.Capability.JS);
133 SDK.SDKModel.register(SDK.CPUProfilerModel, SDK.Target.Capability.None);
134 142
135 /** @enum {symbol} */ 143 /** @enum {symbol} */
136 SDK.CPUProfilerModel.Events = { 144 SDK.CPUProfilerModel.Events = {
137 ConsoleProfileStarted: Symbol('ConsoleProfileStarted'), 145 ConsoleProfileStarted: Symbol('ConsoleProfileStarted'),
138 ConsoleProfileFinished: Symbol('ConsoleProfileFinished') 146 ConsoleProfileFinished: Symbol('ConsoleProfileFinished')
139 }; 147 };
140 148
141 /** @typedef {!{id: string, scriptLocation: !SDK.DebuggerModel.Location, title: (string|undefined), cpuProfile: (!Protocol.Profiler.Profile|undefined)}} */ 149 /** @typedef {!{id: string, scriptLocation: !SDK.DebuggerModel.Location, title: (string|undefined), cpuProfile: (!Protocol.Profiler.Profile|undefined)}} */
142 SDK.CPUProfilerModel.EventData; 150 SDK.CPUProfilerModel.EventData;
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698