-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Capture stopwatch results #12812
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -50,10 +51,20 @@ export abstract class Stopwatch { | |||
@inject(ILogger) | |||
protected readonly logger: ILogger; | |||
|
|||
protected cachedResults: MeasurementResult[] = []; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
storedMeasurements
@@ -50,10 +51,20 @@ export abstract class Stopwatch { | |||
@inject(ILogger) | |||
protected readonly logger: ILogger; | |||
|
|||
protected cachedResults: MeasurementResult[] = []; | |||
|
|||
protected onMeasurementResultEmitter = new Emitter<MeasurementResult>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to our guidelines, the name of this event should be onDidAddMeasurementResult
.
@@ -91,14 +102,17 @@ export abstract class Stopwatch { | |||
return result; | |||
} | |||
|
|||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer measure
as a name, since it's a function.
@@ -112,6 +126,19 @@ export abstract class Stopwatch { | |||
return result; | |||
} | |||
|
|||
protected handleCompletedMeasurement(name: string, startTime: number, elapsed: number, options: LogOptions): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -154,4 +181,8 @@ export abstract class Stopwatch { | |||
this.logger.log(level, `${whatWasMeasured}: ${elapsed.toFixed(1)} ms [${timeFromStart}]`, ...(options.arguments ?? [])); | |||
} | |||
|
|||
getCachedResults(): MeasurementResult[] { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
frontendCounters
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 ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for addressing the comments, I can see the metrics now.
I'm approving based on the assumption that the |
What it does
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 (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