Capture stopwatch results#12812
Conversation
349e8c4 to
f8baf78
Compare
| * Flag to indicate whether the stopwatch should cache measurement results for later retrieval. | ||
| * For example the cache can be used to retrieve measurements which were taken during startup before a listener had a chance to register. | ||
| */ | ||
| cacheResults?: boolean |
There was a problem hiding this comment.
In IT, the word "cache" usually refers to a short-term, incomplete set of items, often size-limited, where some items may be replaced according to some algorithm. I suspect this is not what's happening here. If we want to store a full trace of results, we should call this field storeResults and rename related variables accordingly.
| @inject(ILogger) | ||
| protected readonly logger: ILogger; | ||
|
|
||
| protected cachedResults: MeasurementResult[] = []; |
|
|
||
| protected cachedResults: MeasurementResult[] = []; | ||
|
|
||
| protected onMeasurementResultEmitter = new Emitter<MeasurementResult>(); |
There was a problem hiding this comment.
According to our guidelines, the name of this event should be onDidAddMeasurementResult.
| } | ||
|
|
||
| protected createMeasurement(name: string, measurement: () => number, options?: MeasurementOptions): Measurement { | ||
| protected createMeasurement(name: string, measurement: () => { startTime: number, duration: number }, options?: MeasurementOptions): Measurement { |
There was a problem hiding this comment.
I would prefer measure as a name, since it's a function.
| return result; | ||
| } | ||
|
|
||
| protected handleCompletedMeasurement(name: string, startTime: number, elapsed: number, options: LogOptions): void { |
There was a problem hiding this comment.
Why not keep this method private or inline it? I don't see the point of overriding it in a subclass. It just adds gratuitous API surface.
| this.logger.log(level, `${whatWasMeasured}: ${elapsed.toFixed(1)} ms [${timeFromStart}]`, ...(options.arguments ?? [])); | ||
| } | ||
|
|
||
| getCachedResults(): MeasurementResult[] { |
There was a problem hiding this comment.
Why not use a property accessor returning a readonly array? It prevent unnecessary copying.
| // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
| // ***************************************************************************** | ||
|
|
||
| export * from './metrics-frontend-application-contribution'; |
There was a problem hiding this comment.
Isn't the point of the contribution to be used in the module? Why does it need to be exported from index.ts?
| protected logLevelCli: LogLevelCliContribution; | ||
|
|
||
| protected metrics = ''; | ||
| protected frontendCounter = new Map<string, string>(); |
|
Here's the text form localhost:3000/metrics after starting a front end: Beyond the confusing format, I'm not seeing any outputs the look stopwatch-related. |
Introduce `MeasurementResults` that capture a stopwatch execution in a serializable format. Add `onMeasurementResult` event emitter to stopwatch class and introduce optional caching of results. Add a metrics contribution to `@theia/metrics` that collects all measurement results of frontend and backend processes Contributed on behalf of STMicroelectronics
f8baf78 to
1cd3a61
Compare
|
Thanks for the review @tsmaeder. I have rebased the PR and addresses your comments.
The test instructions were incomplete, my bad. Currently the measurement metrics is only active if the application is started in debug mode ( |
tsmaeder
left a comment
There was a problem hiding this comment.
Thanks for addressing the comments, I can see the metrics now.
|
I'm approving based on the assumption that the |
What it does
Introduce
MeasurementResultsthat capture a stopwatch execution in a serializable format.Add
onMeasurementResultevent emitter to stopwatch class and introduce optional caching of results.Add a metrics contribution to
@theia/metricsthat collects all measurement results of frontend and backend processes (when running with debug log level).The new metrics can be picked up by the performance measurement step of the e2e framework.
Contributed on behalf of STMicroelectronics
How to test
Start the example Theia application in browser in debug mode (
yarn browser start:debug). Go tolocalhost:3000/metrics. The stopwatch results for the backend and frontend should be part of the dataset.Reload the theia application, then reload
localhost:3000/metrics. It should now contain an additional dataset for the second frontend instance.Review checklist
Reminder for reviewers