export default class TracingModel{constructor(backingStorage){this._backingStorage=backingStorage;this._firstWritePending=true;this._processById=new Map();this._processByName=new Map();this._minimumRecordTime=0;this._maximumRecordTime=0;this._devToolsMetadataEvents=[];this._asyncEvents=[];this._openAsyncEvents=new Map();this._openNestableAsyncEvents=new Map();this._profileGroups=new Map();this._parsedCategories=new Map();} static isNestableAsyncPhase(phase){return phase==='b'||phase==='e'||phase==='n';} static isAsyncBeginPhase(phase){return phase==='S'||phase==='b';} static isAsyncPhase(phase){return TracingModel.isNestableAsyncPhase(phase)||phase==='S'||phase==='T'||phase==='F'||phase==='p';} static isFlowPhase(phase){return phase==='s'||phase==='t'||phase==='f';} static isTopLevelEvent(event){return event.hasCategory(DevToolsTimelineEventCategory)&&event.name==='RunTask'||event.hasCategory(LegacyTopLevelEventCategory)||event.hasCategory(DevToolsMetadataEventCategory)&&event.name==='Program';} static _extractId(payload){const scope=payload.scope||'';if(typeof payload.id2==='undefined'){return scope&&payload.id?`${scope}@${payload.id}`:payload.id;} const id2=payload.id2;if(typeof id2==='object'&&('global'in id2)!==('local'in id2)){return typeof id2['global']!=='undefined'?`:${scope}:${id2['global']}`:`:${scope}:${payload.pid}:${id2['local']}`;} console.error(`Unexpected id2 field at ${payload.ts / 1000}, one and only one of 'local' and 'global' should be present.`);} static browserMainThread(tracingModel){const processes=tracingModel.sortedProcesses();if(!processes.length){return null;} const browserMainThreadName='CrBrowserMain';const browserProcesses=[];const browserMainThreads=[];for(const process of processes){if(process.name().toLowerCase().endsWith('browser')){browserProcesses.push(process);} browserMainThreads.push(...process.sortedThreads().filter(t=>t.name()===browserMainThreadName));} if(browserMainThreads.length===1){return browserMainThreads[0];} if(browserProcesses.length===1){return browserProcesses[0].threadByName(browserMainThreadName);} const tracingStartedInBrowser=tracingModel.devToolsMetadataEvents().filter(e=>e.name==='TracingStartedInBrowser');if(tracingStartedInBrowser.length===1){return tracingStartedInBrowser[0].thread;} Common.console.error('Failed to find browser main thread in trace, some timeline features may be unavailable');return null;} devToolsMetadataEvents(){return this._devToolsMetadataEvents;} addEvents(events){for(let i=0;ikeepStringsLessThan){backingStorage=this._backingStorage.appendAccessibleString(stringPayload);}else{this._backingStorage.appendString(stringPayload);} const timestamp=payload.ts/1000;if(timestamp&&(!this._minimumRecordTime||timestampevent.startTime){return null;} this._lastTopLevelEvent=event;} this._events.push(event);return event;} _addAsyncEvent(asyncEvent){this._asyncEvents.push(asyncEvent);} _setName(name){super._setName(name);this._process._setThreadByName(name,this);} id(){return this._id;} process(){return this._process;} events(){return this._events;} asyncEvents(){return this._asyncEvents;}} self.SDK=self.SDK||{};SDK=SDK||{};SDK.TracingModel=TracingModel;SDK.TracingModel.Phase=Phase;SDK.TracingModel.MetadataEvent=MetadataEvent;SDK.TracingModel.LegacyTopLevelEventCategory=LegacyTopLevelEventCategory;SDK.TracingModel.DevToolsMetadataEventCategory=DevToolsMetadataEventCategory;SDK.TracingModel.DevToolsTimelineEventCategory=DevToolsTimelineEventCategory;SDK.TracingModel.Event=Event;SDK.TracingModel.ObjectSnapshot=ObjectSnapshot;SDK.TracingModel.AsyncEvent=AsyncEvent;SDK.TracingModel.Process=Process;SDK.TracingModel.Thread=Thread;SDK.BackingStorage=BackingStorage;