@yuebai008/cli
Version:
Command line interface for rapid qg-minigame development
1 lines • 1.48 kB
JavaScript
import*as SDK from"../../core/sdk/sdk.js";export class TracingManager extends SDK.SDKModel.SDKModel{#e;#t;#i;#n;#r;constructor(e){super(e),this.#e=e.tracingAgent(),e.registerTracingDispatcher(new TracingDispatcher(this)),this.#t=null,this.#i=0,this.#n=0}bufferUsage(e,t,i){this.#i=void 0===t?null:t,this.#t&&this.#t.tracingBufferUsage(e||i||0)}eventsCollected(e){this.#t&&(this.#t.traceEventsCollected(e),this.#n+=e.length,this.#i?(this.#n>this.#i&&(this.#n=this.#i),this.#t.eventsRetrievalProgress(this.#n/this.#i)):this.#t.eventsRetrievalProgress(0))}tracingComplete(){this.#i=0,this.#n=0,this.#t&&(this.#t.tracingComplete(),this.#t=null),this.#r=!1}async reset(){this.#t&&await this.#e.invoke_end(),this.#i=0,this.#n=0,this.#t=null,this.#r=!1}async start(e,t,i){if(this.#t)throw new Error("Tracing is already started");this.#t=e;const n={bufferUsageReportingInterval:500,categories:t,options:i,transferMode:"ReportEvents"},r=await this.#e.invoke_start(n);return r.getError()&&(this.#t=null),r}stop(){if(!this.#t)throw new Error("Tracing is not started");if(this.#r)throw new Error("Tracing is already being stopped");this.#r=!0,this.#e.invoke_end()}}class TracingDispatcher{#s;constructor(e){this.#s=e}bufferUsage({value:e,eventCount:t,percentFull:i}){this.#s.bufferUsage(e,t,i)}dataCollected({value:e}){this.#s.eventsCollected(e)}tracingComplete(){this.#s.tracingComplete()}}SDK.SDKModel.SDKModel.register(TracingManager,{capabilities:SDK.Target.Capability.Tracing,autostart:!1});