| OLD | NEW |
| 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 Loading... |
| 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 |
| 101 startRecording() { | 92 startRecording() { |
| 102 this._isRecording = true; | 93 this._isRecording = true; |
| 103 this.target().profilerAgent().start(); | |
| 104 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ProfilesCPUProfileTaken
); | 94 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ProfilesCPUProfileTaken
); |
| 95 var intervalUs = Common.moduleSetting('highResolutionCpuProfiling').get() ?
100 : 1000; |
| 96 this._profilerAgent.setSamplingInterval(intervalUs); |
| 97 this._profilerAgent.start(); |
| 105 } | 98 } |
| 106 | 99 |
| 107 /** | 100 /** |
| 108 * @return {!Promise.<?Protocol.Profiler.Profile>} | 101 * @return {!Promise.<?Protocol.Profiler.Profile>} |
| 109 */ | 102 */ |
| 110 stopRecording() { | 103 stopRecording() { |
| 111 /** | 104 /** |
| 112 * @param {?Protocol.Error} error | 105 * @param {?Protocol.Error} error |
| 113 * @param {?Protocol.Profiler.Profile} profile | 106 * @param {?Protocol.Profiler.Profile} profile |
| 114 * @return {?Protocol.Profiler.Profile} | 107 * @return {?Protocol.Profiler.Profile} |
| 115 */ | 108 */ |
| 116 function extractProfile(error, profile) { | 109 function extractProfile(error, profile) { |
| 117 return !error && profile ? profile : null; | 110 return !error && profile ? profile : null; |
| 118 } | 111 } |
| 119 this._isRecording = false; | 112 this._isRecording = false; |
| 120 return this.target().profilerAgent().stop(extractProfile); | 113 return this._profilerAgent.stop(extractProfile); |
| 121 } | 114 } |
| 122 | 115 |
| 123 /** | 116 /** |
| 124 * @override | 117 * @return {!Promise} |
| 125 */ | 118 */ |
| 126 dispose() { | 119 startPreciseCoverage() { |
| 127 Common.moduleSetting('highResolutionCpuProfiling') | 120 return this._profilerAgent.startPreciseCoverage(); |
| 128 .removeChangeListener(this._configureCpuProfilerSamplingInterval, this); | 121 } |
| 122 |
| 123 /** |
| 124 * @return {!Promise<!Array<!Protocol.Profiler.ScriptCoverage>>} |
| 125 */ |
| 126 takePreciseCoverage() { |
| 127 return this._profilerAgent.takePreciseCoverage((error, coverage) => error ?
[] : coverage); |
| 128 } |
| 129 |
| 130 /** |
| 131 * @return {!Promise} |
| 132 */ |
| 133 stopPreciseCoverage() { |
| 134 return this._profilerAgent.stopPreciseCoverage(); |
| 129 } | 135 } |
| 130 }; | 136 }; |
| 131 | 137 |
| 132 // TODO(dgozman): should be JS. | 138 SDK.SDKModel.register(SDK.CPUProfilerModel, SDK.Target.Capability.JS); |
| 133 SDK.SDKModel.register(SDK.CPUProfilerModel, SDK.Target.Capability.None); | |
| 134 | 139 |
| 135 /** @enum {symbol} */ | 140 /** @enum {symbol} */ |
| 136 SDK.CPUProfilerModel.Events = { | 141 SDK.CPUProfilerModel.Events = { |
| 137 ConsoleProfileStarted: Symbol('ConsoleProfileStarted'), | 142 ConsoleProfileStarted: Symbol('ConsoleProfileStarted'), |
| 138 ConsoleProfileFinished: Symbol('ConsoleProfileFinished') | 143 ConsoleProfileFinished: Symbol('ConsoleProfileFinished') |
| 139 }; | 144 }; |
| 140 | 145 |
| 141 /** @typedef {!{id: string, scriptLocation: !SDK.DebuggerModel.Location, title:
(string|undefined), cpuProfile: (!Protocol.Profiler.Profile|undefined)}} */ | 146 /** @typedef {!{id: string, scriptLocation: !SDK.DebuggerModel.Location, title:
(string|undefined), cpuProfile: (!Protocol.Profiler.Profile|undefined)}} */ |
| 142 SDK.CPUProfilerModel.EventData; | 147 SDK.CPUProfilerModel.EventData; |
| OLD | NEW |