* Parses an array of trace events into a structured object containing all the * information parsed by the trace handlers. * You can `await` this function to pause execution until parsing is complete, * or instead rely on the `ModuleUpdateEvent` that is dispatched when the * parsing is fi
(traceEvents: readonly Types.Events.Event[], config: Types.Configuration.ParseOptions = {})
| 78 | * void this.traceModel.parse(events); |
| 79 | **/ |
| 80 | async parse(traceEvents: readonly Types.Events.Event[], config: Types.Configuration.ParseOptions = {}): |
| 81 | Promise<void> { |
| 82 | if (config.showAllEvents === undefined) { |
| 83 | config.showAllEvents = this.#config.showAllEvents; |
| 84 | } |
| 85 | |
| 86 | const metadata = config.metadata || {}; |
| 87 | // During parsing, periodically update any listeners on each processors' |
| 88 | // progress (if they have any updates). |
| 89 | const onTraceUpdate = (event: Event): void => { |
| 90 | const {data} = event as TraceParseProgressEvent; |
| 91 | this.dispatchEvent(new ModelUpdateEvent({type: ModelUpdateType.PROGRESS_UPDATE, data})); |
| 92 | }; |
| 93 | |
| 94 | this.#processor.addEventListener(TraceParseProgressEvent.eventName, onTraceUpdate); |
| 95 | |
| 96 | // TODO(cjamcl): this.#processor.parse needs this to work. So it should either take it as input, or create it itself. |
| 97 | const syntheticEventsManager = Helpers.SyntheticEvents.SyntheticEventsManager.createAndActivate(traceEvents); |
| 98 | |
| 99 | try { |
| 100 | // Wait for all outstanding promises before finishing the async execution, |
| 101 | // but perform all tasks in parallel. |
| 102 | await this.#processor.parse(traceEvents, config); |
| 103 | if (!this.#processor.data) { |
| 104 | throw new Error('processor did not parse trace'); |
| 105 | } |
| 106 | const file = this.#storeAndCreateParsedTraceFile( |
| 107 | syntheticEventsManager, traceEvents, metadata, this.#processor.data, this.#processor.insights); |
| 108 | // We only push the file onto this.#traces here once we know it's valid |
| 109 | // and there's been no errors in the parsing. |
| 110 | this.#traces.push(file); |
| 111 | } catch (e) { |
| 112 | throw e; |
| 113 | } finally { |
| 114 | // All processors have finished parsing, no more updates are expected. |
| 115 | this.#processor.removeEventListener(TraceParseProgressEvent.eventName, onTraceUpdate); |
| 116 | // Finally, update any listeners that all processors are 'done'. |
| 117 | this.dispatchEvent(new ModelUpdateEvent({type: ModelUpdateType.COMPLETE, data: 'done'})); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | #storeAndCreateParsedTraceFile( |
| 122 | syntheticEventsManager: Helpers.SyntheticEvents.SyntheticEventsManager, |