| 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 * |
| (...skipping 11 matching lines...) Expand all Loading... |
| 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 * @implements {Protocol.ProfilerDispatcher} | 29 * @implements {Protocol.ProfilerDispatcher} |
| 30 * @unrestricted | 30 * @unrestricted |
| 31 */ | 31 */ |
| 32 WebInspector.CPUProfilerModel = class extends WebInspector.SDKModel { | 32 SDK.CPUProfilerModel = class extends SDK.SDKModel { |
| 33 /** | 33 /** |
| 34 * @param {!WebInspector.Target} target | 34 * @param {!SDK.Target} target |
| 35 */ | 35 */ |
| 36 constructor(target) { | 36 constructor(target) { |
| 37 super(WebInspector.CPUProfilerModel, target); | 37 super(SDK.CPUProfilerModel, target); |
| 38 this._isRecording = false; | 38 this._isRecording = false; |
| 39 target.registerProfilerDispatcher(this); | 39 target.registerProfilerDispatcher(this); |
| 40 target.profilerAgent().enable(); | 40 target.profilerAgent().enable(); |
| 41 | 41 |
| 42 this._configureCpuProfilerSamplingInterval(); | 42 this._configureCpuProfilerSamplingInterval(); |
| 43 WebInspector.moduleSetting('highResolutionCpuProfiling') | 43 Common.moduleSetting('highResolutionCpuProfiling') |
| 44 .addChangeListener(this._configureCpuProfilerSamplingInterval, this); | 44 .addChangeListener(this._configureCpuProfilerSamplingInterval, this); |
| 45 } | 45 } |
| 46 | 46 |
| 47 _configureCpuProfilerSamplingInterval() { | 47 _configureCpuProfilerSamplingInterval() { |
| 48 var intervalUs = WebInspector.moduleSetting('highResolutionCpuProfiling').ge
t() ? 100 : 1000; | 48 var intervalUs = Common.moduleSetting('highResolutionCpuProfiling').get() ?
100 : 1000; |
| 49 this.target().profilerAgent().setSamplingInterval(intervalUs); | 49 this.target().profilerAgent().setSamplingInterval(intervalUs); |
| 50 } | 50 } |
| 51 | 51 |
| 52 /** | 52 /** |
| 53 * @override | 53 * @override |
| 54 * @param {string} id | 54 * @param {string} id |
| 55 * @param {!Protocol.Debugger.Location} scriptLocation | 55 * @param {!Protocol.Debugger.Location} scriptLocation |
| 56 * @param {string=} title | 56 * @param {string=} title |
| 57 */ | 57 */ |
| 58 consoleProfileStarted(id, scriptLocation, title) { | 58 consoleProfileStarted(id, scriptLocation, title) { |
| 59 this._dispatchProfileEvent(WebInspector.CPUProfilerModel.Events.ConsoleProfi
leStarted, id, scriptLocation, title); | 59 this._dispatchProfileEvent(SDK.CPUProfilerModel.Events.ConsoleProfileStarted
, id, scriptLocation, title); |
| 60 } | 60 } |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * @override | 63 * @override |
| 64 * @param {string} id | 64 * @param {string} id |
| 65 * @param {!Protocol.Debugger.Location} scriptLocation | 65 * @param {!Protocol.Debugger.Location} scriptLocation |
| 66 * @param {!Protocol.Profiler.Profile} cpuProfile | 66 * @param {!Protocol.Profiler.Profile} cpuProfile |
| 67 * @param {string=} title | 67 * @param {string=} title |
| 68 */ | 68 */ |
| 69 consoleProfileFinished(id, scriptLocation, cpuProfile, title) { | 69 consoleProfileFinished(id, scriptLocation, cpuProfile, title) { |
| 70 this._dispatchProfileEvent( | 70 this._dispatchProfileEvent( |
| 71 WebInspector.CPUProfilerModel.Events.ConsoleProfileFinished, id, scriptL
ocation, title, cpuProfile); | 71 SDK.CPUProfilerModel.Events.ConsoleProfileFinished, id, scriptLocation,
title, cpuProfile); |
| 72 } | 72 } |
| 73 | 73 |
| 74 /** | 74 /** |
| 75 * @param {symbol} eventName | 75 * @param {symbol} eventName |
| 76 * @param {string} id | 76 * @param {string} id |
| 77 * @param {!Protocol.Debugger.Location} scriptLocation | 77 * @param {!Protocol.Debugger.Location} scriptLocation |
| 78 * @param {string=} title | 78 * @param {string=} title |
| 79 * @param {!Protocol.Profiler.Profile=} cpuProfile | 79 * @param {!Protocol.Profiler.Profile=} cpuProfile |
| 80 */ | 80 */ |
| 81 _dispatchProfileEvent(eventName, id, scriptLocation, title, cpuProfile) { | 81 _dispatchProfileEvent(eventName, id, scriptLocation, title, cpuProfile) { |
| 82 // Make sure ProfilesPanel is initialized and CPUProfileType is created. | 82 // Make sure ProfilesPanel is initialized and CPUProfileType is created. |
| 83 self.runtime.loadModulePromise('profiler').then(_ => { | 83 self.runtime.loadModulePromise('profiler').then(_ => { |
| 84 var debuggerModel = | 84 var debuggerModel = |
| 85 /** @type {!WebInspector.DebuggerModel} */ (WebInspector.DebuggerModel
.fromTarget(this.target())); | 85 /** @type {!SDK.DebuggerModel} */ (SDK.DebuggerModel.fromTarget(this.t
arget())); |
| 86 var debuggerLocation = WebInspector.DebuggerModel.Location.fromPayload(deb
uggerModel, scriptLocation); | 86 var debuggerLocation = SDK.DebuggerModel.Location.fromPayload(debuggerMode
l, scriptLocation); |
| 87 var globalId = this.target().id() + '.' + id; | 87 var globalId = this.target().id() + '.' + id; |
| 88 var data = /** @type {!WebInspector.CPUProfilerModel.EventData} */ ( | 88 var data = /** @type {!SDK.CPUProfilerModel.EventData} */ ( |
| 89 {id: globalId, scriptLocation: debuggerLocation, cpuProfile: cpuProfil
e, title: title}); | 89 {id: globalId, scriptLocation: debuggerLocation, cpuProfile: cpuProfil
e, title: title}); |
| 90 this.dispatchEventToListeners(eventName, data); | 90 this.dispatchEventToListeners(eventName, data); |
| 91 }); | 91 }); |
| 92 } | 92 } |
| 93 | 93 |
| 94 /** | 94 /** |
| 95 * @return {boolean} | 95 * @return {boolean} |
| 96 */ | 96 */ |
| 97 isRecordingProfile() { | 97 isRecordingProfile() { |
| 98 return this._isRecording; | 98 return this._isRecording; |
| 99 } | 99 } |
| 100 | 100 |
| 101 startRecording() { | 101 startRecording() { |
| 102 this._isRecording = true; | 102 this._isRecording = true; |
| 103 this.target().profilerAgent().start(); | 103 this.target().profilerAgent().start(); |
| 104 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Profile
sCPUProfileTaken); | 104 Host.userMetrics.actionTaken(Host.UserMetrics.Action.ProfilesCPUProfileTaken
); |
| 105 } | 105 } |
| 106 | 106 |
| 107 /** | 107 /** |
| 108 * @return {!Promise.<?Protocol.Profiler.Profile>} | 108 * @return {!Promise.<?Protocol.Profiler.Profile>} |
| 109 */ | 109 */ |
| 110 stopRecording() { | 110 stopRecording() { |
| 111 /** | 111 /** |
| 112 * @param {?Protocol.Error} error | 112 * @param {?Protocol.Error} error |
| 113 * @param {?Protocol.Profiler.Profile} profile | 113 * @param {?Protocol.Profiler.Profile} profile |
| 114 * @return {?Protocol.Profiler.Profile} | 114 * @return {?Protocol.Profiler.Profile} |
| 115 */ | 115 */ |
| 116 function extractProfile(error, profile) { | 116 function extractProfile(error, profile) { |
| 117 return !error && profile ? profile : null; | 117 return !error && profile ? profile : null; |
| 118 } | 118 } |
| 119 this._isRecording = false; | 119 this._isRecording = false; |
| 120 return this.target().profilerAgent().stop(extractProfile); | 120 return this.target().profilerAgent().stop(extractProfile); |
| 121 } | 121 } |
| 122 | 122 |
| 123 /** | 123 /** |
| 124 * @override | 124 * @override |
| 125 */ | 125 */ |
| 126 dispose() { | 126 dispose() { |
| 127 WebInspector.moduleSetting('highResolutionCpuProfiling') | 127 Common.moduleSetting('highResolutionCpuProfiling') |
| 128 .removeChangeListener(this._configureCpuProfilerSamplingInterval, this); | 128 .removeChangeListener(this._configureCpuProfilerSamplingInterval, this); |
| 129 } | 129 } |
| 130 }; | 130 }; |
| 131 | 131 |
| 132 /** @enum {symbol} */ | 132 /** @enum {symbol} */ |
| 133 WebInspector.CPUProfilerModel.Events = { | 133 SDK.CPUProfilerModel.Events = { |
| 134 ConsoleProfileStarted: Symbol('ConsoleProfileStarted'), | 134 ConsoleProfileStarted: Symbol('ConsoleProfileStarted'), |
| 135 ConsoleProfileFinished: Symbol('ConsoleProfileFinished') | 135 ConsoleProfileFinished: Symbol('ConsoleProfileFinished') |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 /** @typedef {!{id: string, scriptLocation: !WebInspector.DebuggerModel.Location
, title: (string|undefined), cpuProfile: (!Protocol.Profiler.Profile|undefined)}
} */ | 138 /** @typedef {!{id: string, scriptLocation: !SDK.DebuggerModel.Location, title:
(string|undefined), cpuProfile: (!Protocol.Profiler.Profile|undefined)}} */ |
| 139 WebInspector.CPUProfilerModel.EventData; | 139 SDK.CPUProfilerModel.EventData; |
| OLD | NEW |