UNPKG

@yuebai008/cli

Version:

Command line interface for rapid qg-minigame development

1 lines 3.07 kB
import{RuntimeModel}from"./RuntimeModel.js";import{Capability}from"./Target.js";import{SDKModel}from"./SDKModel.js";export class HeapProfilerModel extends SDKModel{#e;#t;#r;#a;constructor(e){super(e),e.registerHeapProfilerDispatcher(new HeapProfilerDispatcher(this)),this.#e=!1,this.#t=e.heapProfilerAgent(),this.#r=e.model(RuntimeModel),this.#a=0}debuggerModel(){return this.#r.debuggerModel()}runtimeModel(){return this.#r}async enable(){this.#e||(this.#e=!0,await this.#t.invoke_enable())}async startSampling(e){if(this.#a++)return!1;const t=await this.#t.invoke_startSampling({samplingInterval:e||16384});return Boolean(t.getError())}async stopSampling(){if(!this.#a)throw new Error("Sampling profiler is not running.");if(--this.#a)return this.getSamplingProfile();const e=await this.#t.invoke_stopSampling();return e.getError()?null:e.profile}async getSamplingProfile(){const e=await this.#t.invoke_getSamplingProfile();return e.getError()?null:e.profile}async collectGarbage(){const e=await this.#t.invoke_collectGarbage();return Boolean(e.getError())}async snapshotObjectIdForObjectId(e){const t=await this.#t.invoke_getHeapObjectId({objectId:e});return t.getError()?null:t.heapSnapshotObjectId}async objectForSnapshotObjectId(e,t){const r=await this.#t.invoke_getObjectByHeapObjectId({objectId:e,objectGroup:t});return r.getError()?null:this.#r.createRemoteObject(r.result)}async addInspectedHeapObject(e){const t=await this.#t.invoke_addInspectedHeapObject({heapObjectId:e});return Boolean(t.getError())}async takeHeapSnapshot(e){await this.#t.invoke_takeHeapSnapshot(e)}async startTrackingHeapObjects(e){const t=await this.#t.invoke_startTrackingHeapObjects({trackAllocations:e});return Boolean(t.getError())}async stopTrackingHeapObjects(e){const t=await this.#t.invoke_stopTrackingHeapObjects({reportProgress:e});return Boolean(t.getError())}heapStatsUpdate(e){this.dispatchEventToListeners(Events.HeapStatsUpdate,e)}lastSeenObjectId(e,t){this.dispatchEventToListeners(Events.LastSeenObjectId,{lastSeenObjectId:e,timestamp:t})}addHeapSnapshotChunk(e){this.dispatchEventToListeners(Events.AddHeapSnapshotChunk,e)}reportHeapSnapshotProgress(e,t,r){this.dispatchEventToListeners(Events.ReportHeapSnapshotProgress,{done:e,total:t,finished:r})}resetProfiles(){this.dispatchEventToListeners(Events.ResetProfiles,this)}}export var Events;!function(e){e.HeapStatsUpdate="HeapStatsUpdate",e.LastSeenObjectId="LastSeenObjectId",e.AddHeapSnapshotChunk="AddHeapSnapshotChunk",e.ReportHeapSnapshotProgress="ReportHeapSnapshotProgress",e.ResetProfiles="ResetProfiles"}(Events||(Events={}));class HeapProfilerDispatcher{#s;constructor(e){this.#s=e}heapStatsUpdate({statsUpdate:e}){this.#s.heapStatsUpdate(e)}lastSeenObjectId({lastSeenObjectId:e,timestamp:t}){this.#s.lastSeenObjectId(e,t)}addHeapSnapshotChunk({chunk:e}){this.#s.addHeapSnapshotChunk(e)}reportHeapSnapshotProgress({done:e,total:t,finished:r}){this.#s.reportHeapSnapshotProgress(e,t,r)}resetProfiles(){this.#s.resetProfiles()}}SDKModel.register(HeapProfilerModel,{capabilities:Capability.JS,autostart:!1});