@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 2.24 kB
JavaScript
import*as i18n from"../i18n/i18n.js";import{DebuggerModel,Location}from"./DebuggerModel.js";import{Capability}from"./Target.js";import{SDKModel}from"./SDKModel.js";const UIStrings={profileD:"Profile {PH1}"},str_=i18n.i18n.registerUIStrings("core/sdk/CPUProfilerModel.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);export class CPUProfilerModel extends SDKModel{#e;#t;#o;#r;#i;#s;registeredConsoleProfileMessages=[];constructor(e){super(e),this.#e=!1,this.#t=1,this.#o=new Map,this.#r=e.profilerAgent(),this.#i=null,e.registerProfilerDispatcher(this),this.#r.invoke_enable(),this.#s=e.model(DebuggerModel)}runtimeModel(){return this.#s.runtimeModel()}debuggerModel(){return this.#s}consoleProfileStarted({id:e,location:t,title:o}){o||(o=i18nString(UIStrings.profileD,{PH1:this.#t++}),this.#o.set(e,o));const r=this.createEventDataFrom(e,t,o);this.dispatchEventToListeners(Events.ConsoleProfileStarted,r)}consoleProfileFinished({id:e,location:t,profile:o,title:r}){r||(r=this.#o.get(e),this.#o.delete(e));const i={...this.createEventDataFrom(e,t,r),cpuProfile:o};this.registeredConsoleProfileMessages.push(i),this.dispatchEventToListeners(Events.ConsoleProfileFinished,i)}createEventDataFrom(e,t,o){const r=Location.fromPayload(this.#s,t);return{id:this.target().id()+"."+e,scriptLocation:r,title:o||"",cpuProfilerModel:this}}isRecordingProfile(){return this.#e}startRecording(){this.#e=!0;return this.#r.invoke_setSamplingInterval({interval:100}),this.#r.invoke_start()}stopRecording(){return this.#e=!1,this.#r.invoke_stop().then((e=>e.profile||null))}startPreciseCoverage(e,t){this.#i=t;return this.#r.invoke_startPreciseCoverage({callCount:!1,detailed:e,allowTriggeredUpdates:!0})}async takePreciseCoverage(){const e=await this.#r.invoke_takePreciseCoverage();return{timestamp:e&&e.timestamp||0,coverage:e&&e.result||[]}}stopPreciseCoverage(){return this.#i=null,this.#r.invoke_stopPreciseCoverage()}preciseCoverageDeltaUpdate({timestamp:e,occasion:t,result:o}){this.#i&&this.#i(e,t,o)}}export var Events;!function(e){e.ConsoleProfileStarted="ConsoleProfileStarted",e.ConsoleProfileFinished="ConsoleProfileFinished"}(Events||(Events={})),SDKModel.register(CPUProfilerModel,{capabilities:Capability.JS,autostart:!0});