TracingManager.js 2.3 KB

123456789101112131415161718192021
  1. export default class TracingManager extends SDK.SDKModel{constructor(target){super(target);this._tracingAgent=target.tracingAgent();target.registerTracingDispatcher(new TracingDispatcher(this));this._activeClient=null;this._eventBufferSize=0;this._eventsRetrieved=0;}
  2. _bufferUsage(usage,eventCount,percentFull){this._eventBufferSize=eventCount;this._activeClient.tracingBufferUsage(usage||percentFull||0);}
  3. _eventsCollected(events){this._activeClient.traceEventsCollected(events);this._eventsRetrieved+=events.length;if(!this._eventBufferSize){this._activeClient.eventsRetrievalProgress(0);return;}
  4. if(this._eventsRetrieved>this._eventBufferSize){this._eventsRetrieved=this._eventBufferSize;}
  5. this._activeClient.eventsRetrievalProgress(this._eventsRetrieved/this._eventBufferSize);}
  6. _tracingComplete(){this._eventBufferSize=0;this._eventsRetrieved=0;this._activeClient.tracingComplete();this._activeClient=null;this._finishing=false;}
  7. async start(client,categoryFilter,options){if(this._activeClient){throw new Error('Tracing is already started');}
  8. const bufferUsageReportingIntervalMs=500;this._activeClient=client;const args={bufferUsageReportingInterval:bufferUsageReportingIntervalMs,categories:categoryFilter,options:options,transferMode:TransferMode.ReportEvents};const response=await this._tracingAgent.invoke_start(args);if(response[Protocol.Error]){this._activeClient=null;}
  9. return response;}
  10. stop(){if(!this._activeClient){throw new Error('Tracing is not started');}
  11. if(this._finishing){throw new Error('Tracing is already being stopped');}
  12. this._finishing=true;this._tracingAgent.end();}}
  13. const TransferMode={ReportEvents:'ReportEvents',ReturnAsStream:'ReturnAsStream'};export class TracingManagerClient{traceEventsCollected(events){}
  14. tracingComplete(){}
  15. tracingBufferUsage(usage){}
  16. eventsRetrievalProgress(progress){}}
  17. class TracingDispatcher{constructor(tracingManager){this._tracingManager=tracingManager;}
  18. bufferUsage(usage,eventCount,percentFull){this._tracingManager._bufferUsage(usage,eventCount,percentFull);}
  19. dataCollected(data){this._tracingManager._eventsCollected(data);}
  20. tracingComplete(){this._tracingManager._tracingComplete();}}
  21. self.SDK=self.SDK||{};SDK=SDK||{};SDK.TracingManager=TracingManager;SDK.TracingManagerClient=TracingManagerClient;SDK.TracingManager.EventPayload;SDK.SDKModel.register(SDK.TracingManager,SDK.Target.Capability.Tracing,false);