-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
12 changed files
with
293 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
export * from './metrics-frontend-application-contribution'; |
51 changes: 51 additions & 0 deletions
51
packages/metrics/src/browser/metrics-frontend-application-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
import { inject, injectable } from '@theia/core/shared/inversify'; | ||
import { FrontendApplicationContribution } from '@theia/core/lib/browser'; | ||
import { ILogger, LogLevel, MeasurementResult, Stopwatch } from '@theia/core'; | ||
import { UUID } from '@theia/core/shared/@phosphor/coreutils'; | ||
import { MeasurementNotificationService } from '../common'; | ||
|
||
@injectable() | ||
export class MetricsFrontendApplicationContribution implements FrontendApplicationContribution { | ||
@inject(Stopwatch) | ||
protected stopwatch: Stopwatch; | ||
|
||
@inject(MeasurementNotificationService) | ||
protected notificationService: MeasurementNotificationService; | ||
|
||
@inject(ILogger) | ||
protected logger: ILogger; | ||
|
||
readonly id = UUID.uuid4(); | ||
|
||
initialize(): void { | ||
this.doInitialize(); | ||
} | ||
|
||
protected async doInitialize(): Promise<void> { | ||
const logLevel = await this.logger.getLogLevel(); | ||
if (logLevel !== LogLevel.DEBUG) { | ||
return; | ||
} | ||
this.stopwatch.getCachedResults().forEach(result => this.notify(result)); | ||
this.stopwatch.onMeasurementResult(result => this.notify(result)); | ||
} | ||
|
||
protected notify(result: MeasurementResult): void { | ||
this.notificationService.onFrontendMeasurement(this.id, result); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { ContainerModule } from '@theia/core/shared/inversify'; | ||
import { MetricsFrontendApplicationContribution } from './metrics-frontend-application-contribution'; | ||
import { MeasurementNotificationService, measurementNotificationServicePath } from '../common'; | ||
import { FrontendApplicationContribution, WebSocketConnectionProvider } from '@theia/core/lib/browser'; | ||
|
||
export default new ContainerModule(bind => { | ||
bind(FrontendApplicationContribution).to(MetricsFrontendApplicationContribution).inSingletonScope(); | ||
bind(MeasurementNotificationService).toDynamicValue(ctx => { | ||
const connection = ctx.container.get(WebSocketConnectionProvider); | ||
return connection.createProxy<MeasurementNotificationService>(measurementNotificationServicePath); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
export * from './measurement-notification-service'; |
29 changes: 29 additions & 0 deletions
29
packages/metrics/src/common/measurement-notification-service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
|
||
import { MeasurementResult } from '@theia/core'; | ||
|
||
export const measurementNotificationServicePath = '/services/measurement-notification'; | ||
|
||
export const MeasurementNotificationService = Symbol('MeasurementNotificationService'); | ||
export interface MeasurementNotificationService { | ||
/** | ||
* Notify the backend when a fronted stopwatch provides a new measurement. | ||
* @param frontendId The unique id associated with the frontend that sends the notification | ||
* @param result The new measurement result | ||
*/ | ||
onFrontendMeasurement(frontendId: string, result: MeasurementResult): void; | ||
} |
75 changes: 75 additions & 0 deletions
75
packages/metrics/src/node/measurement-metrics-contribution.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// ***************************************************************************** | ||
// Copyright (C) 2023 STMicroelectronics and others. | ||
// | ||
// This program and the accompanying materials are made available under the | ||
// terms of the Eclipse Public License v. 2.0 which is available at | ||
// http://www.eclipse.org/legal/epl-2.0. | ||
// | ||
// This Source Code may also be made available under the following Secondary | ||
// Licenses when the conditions for such availability set forth in the Eclipse | ||
// Public License v. 2.0 are satisfied: GNU General Public License, version 2 | ||
// with the GNU Classpath Exception which is available at | ||
// https://www.gnu.org/software/classpath/license.html. | ||
// | ||
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0 | ||
// ***************************************************************************** | ||
import { inject, injectable, } from '@theia/core/shared/inversify'; | ||
import { MetricsContribution } from './metrics-contribution'; | ||
import { LogLevel, MeasurementResult, Stopwatch } from '@theia/core'; | ||
import { MeasurementNotificationService } from '../common'; | ||
import { LogLevelCliContribution } from '@theia/core/lib/node/logger-cli-contribution'; | ||
|
||
const backendId = 'backend'; | ||
const metricsName = 'theia_measurements'; | ||
|
||
@injectable() | ||
export class MeasurementMetricsBackendContribution implements MetricsContribution, MeasurementNotificationService { | ||
@inject(Stopwatch) | ||
protected backendStopwatch: Stopwatch; | ||
|
||
@inject(LogLevelCliContribution) | ||
protected logLevelCli: LogLevelCliContribution; | ||
|
||
protected metrics = ''; | ||
protected frontendCounter = new Map<string, string>(); | ||
|
||
startCollecting(): void { | ||
if (this.logLevelCli.defaultLogLevel !== LogLevel.DEBUG) { | ||
return; | ||
} | ||
this.metrics += `# HELP ${metricsName} Theia stopwatch measurement results.\n`; | ||
this.metrics += `# TYPE ${metricsName} gauge\n`; | ||
this.backendStopwatch.getCachedResults().forEach(result => this.onBackendMeasurement(result)); | ||
this.backendStopwatch.onMeasurementResult(result => this.onBackendMeasurement(result)); | ||
} | ||
|
||
getMetrics(): string { | ||
return this.metrics; | ||
} | ||
|
||
protected appendMetricsValue(id: string, result: MeasurementResult): void { | ||
const { name, elapsed, startTime, owner } = result; | ||
const labels: string = `id="${id}", name="${name}", startTime="${startTime}", owner="${owner}"`; | ||
const metricsValue = `${metricsName}{${labels}} ${elapsed}`; | ||
this.metrics += (metricsValue + '\n'); | ||
} | ||
|
||
protected onBackendMeasurement(result: MeasurementResult): void { | ||
this.appendMetricsValue(backendId, result); | ||
} | ||
|
||
protected createFrontendCounterId(frontendId: string): string { | ||
const counterId = `frontend-${this.frontendCounter.size + 1}`; | ||
this.frontendCounter.set(frontendId, counterId); | ||
return counterId; | ||
} | ||
|
||
protected toCounterId(frontendId: string): string { | ||
return this.frontendCounter.get(frontendId) ?? this.createFrontendCounterId(frontendId); | ||
} | ||
|
||
onFrontendMeasurement(frontendId: string, result: MeasurementResult): void { | ||
this.appendMetricsValue(this.toCounterId(frontendId), result); | ||
} | ||
|
||
} |
Oops, something went wrong.