CPUProfilerModel.js 2.4 KB

123456789101112131415
  1. export default class CPUProfilerModel extends SDK.SDKModel{constructor(target){super(target);this._isRecording=false;this._nextAnonymousConsoleProfileNumber=1;this._anonymousConsoleProfileIdToTitle=new Map();this._profilerAgent=target.profilerAgent();target.registerProfilerDispatcher(this);this._profilerAgent.enable();this._debuggerModel=(target.model(SDK.DebuggerModel));}
  2. runtimeModel(){return this._debuggerModel.runtimeModel();}
  3. debuggerModel(){return this._debuggerModel;}
  4. consoleProfileStarted(id,scriptLocation,title){if(!title){title=Common.UIString('Profile %d',this._nextAnonymousConsoleProfileNumber++);this._anonymousConsoleProfileIdToTitle.set(id,title);}
  5. this._dispatchProfileEvent(Events.ConsoleProfileStarted,id,scriptLocation,title);}
  6. consoleProfileFinished(id,scriptLocation,cpuProfile,title){if(!title){title=this._anonymousConsoleProfileIdToTitle.get(id);this._anonymousConsoleProfileIdToTitle.delete(id);}
  7. self.runtime.loadModulePromise('profiler').then(()=>{this._dispatchProfileEvent(Events.ConsoleProfileFinished,id,scriptLocation,title,cpuProfile);});}
  8. _dispatchProfileEvent(eventName,id,scriptLocation,title,cpuProfile){const debuggerLocation=SDK.DebuggerModel.Location.fromPayload(this._debuggerModel,scriptLocation);const globalId=this.target().id()+'.'+id;const data=({id:globalId,scriptLocation:debuggerLocation,cpuProfile:cpuProfile,title:title,cpuProfilerModel:this});this.dispatchEventToListeners(eventName,data);}
  9. isRecordingProfile(){return this._isRecording;}
  10. startRecording(){this._isRecording=true;const intervalUs=Common.moduleSetting('highResolutionCpuProfiling').get()?100:1000;this._profilerAgent.setSamplingInterval(intervalUs);return this._profilerAgent.start();}
  11. stopRecording(){this._isRecording=false;return this._profilerAgent.stop();}
  12. startPreciseCoverage(jsCoveragePerBlock){const callCount=false;return this._profilerAgent.startPreciseCoverage(callCount,jsCoveragePerBlock);}
  13. takePreciseCoverage(){return this._profilerAgent.takePreciseCoverage().then(result=>result||[]);}
  14. stopPreciseCoverage(){return this._profilerAgent.stopPreciseCoverage();}}
  15. export const Events={ConsoleProfileStarted:Symbol('ConsoleProfileStarted'),ConsoleProfileFinished:Symbol('ConsoleProfileFinished')};self.SDK=self.SDK||{};SDK=SDK||{};SDK.CPUProfilerModel=CPUProfilerModel;SDK.CPUProfilerModel.Events=Events;SDK.SDKModel.register(SDK.CPUProfilerModel,SDK.Target.Capability.JS,true);SDK.CPUProfilerModel.EventData;