| 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 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 this._configureCpuProfilerSamplingInterval(); | 42 this._configureCpuProfilerSamplingInterval(); |
| 43 WebInspector.moduleSetting("highResolutionCpuProfiling").addChangeListener(t
his._configureCpuProfilerSamplingInterval, this); | 43 WebInspector.moduleSetting("highResolutionCpuProfiling").addChangeListener(t
his._configureCpuProfilerSamplingInterval, this); |
| 44 } | 44 } |
| 45 | 45 |
| 46 /** @enum {symbol} */ | 46 /** @enum {symbol} */ |
| 47 WebInspector.CPUProfilerModel.Events = { | 47 WebInspector.CPUProfilerModel.Events = { |
| 48 ConsoleProfileStarted: Symbol("ConsoleProfileStarted"), | 48 ConsoleProfileStarted: Symbol("ConsoleProfileStarted"), |
| 49 ConsoleProfileFinished: Symbol("ConsoleProfileFinished") | 49 ConsoleProfileFinished: Symbol("ConsoleProfileFinished") |
| 50 }; | 50 }; |
| 51 | 51 |
| 52 /** @typedef {!{id: string, scriptLocation: !WebInspector.DebuggerModel.Location
, title: (string|undefined), cpuProfile: (!ProfilerAgent.CPUProfile|undefined)}}
*/ | 52 /** @typedef {!{id: string, scriptLocation: !WebInspector.DebuggerModel.Location
, title: (string|undefined), cpuProfile: (!ProfilerAgent.Profile|undefined)}} */ |
| 53 WebInspector.CPUProfilerModel.EventData; | 53 WebInspector.CPUProfilerModel.EventData; |
| 54 | 54 |
| 55 WebInspector.CPUProfilerModel.prototype = { | 55 WebInspector.CPUProfilerModel.prototype = { |
| 56 _configureCpuProfilerSamplingInterval: function() | 56 _configureCpuProfilerSamplingInterval: function() |
| 57 { | 57 { |
| 58 var intervalUs = WebInspector.moduleSetting("highResolutionCpuProfiling"
).get() ? 100 : 1000; | 58 var intervalUs = WebInspector.moduleSetting("highResolutionCpuProfiling"
).get() ? 100 : 1000; |
| 59 this.target().profilerAgent().setSamplingInterval(intervalUs); | 59 this.target().profilerAgent().setSamplingInterval(intervalUs); |
| 60 }, | 60 }, |
| 61 | 61 |
| 62 /** | 62 /** |
| 63 * @override | 63 * @override |
| 64 * @param {string} id | 64 * @param {string} id |
| 65 * @param {!DebuggerAgent.Location} scriptLocation | 65 * @param {!DebuggerAgent.Location} scriptLocation |
| 66 * @param {string=} title | 66 * @param {string=} title |
| 67 */ | 67 */ |
| 68 consoleProfileStarted: function(id, scriptLocation, title) | 68 consoleProfileStarted: function(id, scriptLocation, title) |
| 69 { | 69 { |
| 70 this._dispatchProfileEvent(WebInspector.CPUProfilerModel.Events.ConsoleP
rofileStarted, id, scriptLocation, title); | 70 this._dispatchProfileEvent(WebInspector.CPUProfilerModel.Events.ConsoleP
rofileStarted, id, scriptLocation, title); |
| 71 }, | 71 }, |
| 72 | 72 |
| 73 /** | 73 /** |
| 74 * @override | 74 * @override |
| 75 * @param {string} id | 75 * @param {string} id |
| 76 * @param {!DebuggerAgent.Location} scriptLocation | 76 * @param {!DebuggerAgent.Location} scriptLocation |
| 77 * @param {!ProfilerAgent.CPUProfile} cpuProfile | 77 * @param {!ProfilerAgent.Profile} cpuProfile |
| 78 * @param {string=} title | 78 * @param {string=} title |
| 79 */ | 79 */ |
| 80 consoleProfileFinished: function(id, scriptLocation, cpuProfile, title) | 80 consoleProfileFinished: function(id, scriptLocation, cpuProfile, title) |
| 81 { | 81 { |
| 82 this._dispatchProfileEvent(WebInspector.CPUProfilerModel.Events.ConsoleP
rofileFinished, id, scriptLocation, title, cpuProfile); | 82 this._dispatchProfileEvent(WebInspector.CPUProfilerModel.Events.ConsoleP
rofileFinished, id, scriptLocation, title, cpuProfile); |
| 83 }, | 83 }, |
| 84 | 84 |
| 85 /** | 85 /** |
| 86 * @param {symbol} eventName | 86 * @param {symbol} eventName |
| 87 * @param {string} id | 87 * @param {string} id |
| 88 * @param {!DebuggerAgent.Location} scriptLocation | 88 * @param {!DebuggerAgent.Location} scriptLocation |
| 89 * @param {string=} title | 89 * @param {string=} title |
| 90 * @param {!ProfilerAgent.CPUProfile=} cpuProfile | 90 * @param {!ProfilerAgent.Profile=} cpuProfile |
| 91 */ | 91 */ |
| 92 _dispatchProfileEvent: function(eventName, id, scriptLocation, title, cpuPro
file) | 92 _dispatchProfileEvent: function(eventName, id, scriptLocation, title, cpuPro
file) |
| 93 { | 93 { |
| 94 // Make sure ProfilesPanel is initialized and CPUProfileType is created. | 94 // Make sure ProfilesPanel is initialized and CPUProfileType is created. |
| 95 self.runtime.loadModulePromise("profiler").then(_ => { | 95 self.runtime.loadModulePromise("profiler").then(_ => { |
| 96 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (WebI
nspector.DebuggerModel.fromTarget(this.target())); | 96 var debuggerModel = /** @type {!WebInspector.DebuggerModel} */ (WebI
nspector.DebuggerModel.fromTarget(this.target())); |
| 97 var debuggerLocation = WebInspector.DebuggerModel.Location.fromPaylo
ad(debuggerModel, scriptLocation); | 97 var debuggerLocation = WebInspector.DebuggerModel.Location.fromPaylo
ad(debuggerModel, scriptLocation); |
| 98 var globalId = this.target().id() + "." + id; | 98 var globalId = this.target().id() + "." + id; |
| 99 var data = /** @type {!WebInspector.CPUProfilerModel.EventData} */ (
{id: globalId, scriptLocation: debuggerLocation, cpuProfile: cpuProfile, title:
title}); | 99 var data = /** @type {!WebInspector.CPUProfilerModel.EventData} */ (
{id: globalId, scriptLocation: debuggerLocation, cpuProfile: cpuProfile, title:
title}); |
| 100 this.dispatchEventToListeners(eventName, data); | 100 this.dispatchEventToListeners(eventName, data); |
| 101 }); | 101 }); |
| 102 }, | 102 }, |
| 103 | 103 |
| 104 /** | 104 /** |
| 105 * @return {boolean} | 105 * @return {boolean} |
| 106 */ | 106 */ |
| 107 isRecordingProfile: function() | 107 isRecordingProfile: function() |
| 108 { | 108 { |
| 109 return this._isRecording; | 109 return this._isRecording; |
| 110 }, | 110 }, |
| 111 | 111 |
| 112 startRecording: function() | 112 startRecording: function() |
| 113 { | 113 { |
| 114 this._isRecording = true; | 114 this._isRecording = true; |
| 115 this.target().profilerAgent().start(); | 115 this.target().profilerAgent().start(); |
| 116 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Pro
filesCPUProfileTaken); | 116 WebInspector.userMetrics.actionTaken(WebInspector.UserMetrics.Action.Pro
filesCPUProfileTaken); |
| 117 }, | 117 }, |
| 118 | 118 |
| 119 /** | 119 /** |
| 120 * @return {!Promise.<?ProfilerAgent.CPUProfile>} | 120 * @return {!Promise.<?ProfilerAgent.Profile>} |
| 121 */ | 121 */ |
| 122 stopRecording: function() | 122 stopRecording: function() |
| 123 { | 123 { |
| 124 /** | 124 /** |
| 125 * @param {?Protocol.Error} error | 125 * @param {?Protocol.Error} error |
| 126 * @param {?ProfilerAgent.CPUProfile} profile | 126 * @param {?ProfilerAgent.Profile} profile |
| 127 * @return {?ProfilerAgent.CPUProfile} | 127 * @return {?ProfilerAgent.Profile} |
| 128 */ | 128 */ |
| 129 function extractProfile(error, profile) | 129 function extractProfile(error, profile) |
| 130 { | 130 { |
| 131 return !error && profile ? profile : null; | 131 return !error && profile ? profile : null; |
| 132 } | 132 } |
| 133 this._isRecording = false; | 133 this._isRecording = false; |
| 134 return this.target().profilerAgent().stop(extractProfile); | 134 return this.target().profilerAgent().stop(extractProfile); |
| 135 }, | 135 }, |
| 136 | 136 |
| 137 dispose: function() | 137 dispose: function() |
| 138 { | 138 { |
| 139 WebInspector.moduleSetting("highResolutionCpuProfiling").removeChangeLis
tener(this._configureCpuProfilerSamplingInterval, this); | 139 WebInspector.moduleSetting("highResolutionCpuProfiling").removeChangeLis
tener(this._configureCpuProfilerSamplingInterval, this); |
| 140 }, | 140 }, |
| 141 | 141 |
| 142 __proto__: WebInspector.SDKModel.prototype | 142 __proto__: WebInspector.SDKModel.prototype |
| 143 } | 143 } |
| OLD | NEW |