From 90609a93f7c4fa01373bc5f8de9b2a7412c6c8a0 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Thu, 12 Jan 2023 14:13:51 +0100 Subject: [PATCH] perf - allow to log duration of 2 perf markers in web (#171152) * perf - allow to log duration of 2 perf markers in web * use `code/timeOrigin` * :lipstick: --- .../browser/performance.web.contribution.ts | 35 ++++++++++++++++++- .../environment/browser/environmentService.ts | 17 +++++++++ .../environment/common/environmentService.ts | 1 + .../services/timer/browser/timerService.ts | 8 ++++- 4 files changed, 59 insertions(+), 2 deletions(-) diff --git a/src/vs/workbench/contrib/performance/browser/performance.web.contribution.ts b/src/vs/workbench/contrib/performance/browser/performance.web.contribution.ts index 4f1cd29af52..bc756362a17 100644 --- a/src/vs/workbench/contrib/performance/browser/performance.web.contribution.ts +++ b/src/vs/workbench/contrib/performance/browser/performance.web.contribution.ts @@ -9,10 +9,17 @@ import { Extensions, IWorkbenchContributionsRegistry } from 'vs/workbench/common import { ITelemetryService } from 'vs/platform/telemetry/common/telemetry'; import { posix } from 'vs/base/common/path'; import { hash } from 'vs/base/common/hash'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { ITimerService } from 'vs/workbench/services/timer/browser/timerService'; +import { IBrowserWorkbenchEnvironmentService } from 'vs/workbench/services/environment/browser/environmentService'; +import { ILogService } from 'vs/platform/log/common/log'; class ResourcePerformanceMarks { - constructor(@ITelemetryService telemetryService: ITelemetryService) { + constructor( + @ITelemetryService telemetryService: ITelemetryService, + @IEnvironmentService environmentService: IEnvironmentService + ) { type Entry = { hosthash: string; @@ -44,7 +51,33 @@ class ResourcePerformanceMarks { } } +class StartupTimings { + constructor( + @ITimerService private readonly timerService: ITimerService, + @ILogService private readonly logService: ILogService, + @IBrowserWorkbenchEnvironmentService private readonly environmentService: IBrowserWorkbenchEnvironmentService + ) { + this.logPerfMarks(); + } + + private async logPerfMarks(): Promise { + if (!this.environmentService.profDurationMarkers) { + return; + } + + await this.timerService.whenReady(); + + const [from, to] = this.environmentService.profDurationMarkers; + this.logService.info(`[perf] from '${from}' to '${to}': ${this.timerService.getDuration(from, to)}ms`); + } +} + Registry.as(Extensions.Workbench).registerWorkbenchContribution( ResourcePerformanceMarks, LifecyclePhase.Eventually ); + +Registry.as(Extensions.Workbench).registerWorkbenchContribution( + StartupTimings, + LifecyclePhase.Eventually +); diff --git a/src/vs/workbench/services/environment/browser/environmentService.ts b/src/vs/workbench/services/environment/browser/environmentService.ts index 17b1d82de09..7982196ca87 100644 --- a/src/vs/workbench/services/environment/browser/environmentService.ts +++ b/src/vs/workbench/services/environment/browser/environmentService.ts @@ -53,6 +53,7 @@ export class BrowserWorkbenchEnvironmentService implements IBrowserWorkbenchEnvi if (logLevelFromPayload) { return logLevelFromPayload.split(',').find(entry => !EXTENSION_IDENTIFIER_WITH_LOG_REGEX.test(entry)); } + return this.options.developmentOptions?.logLevel !== undefined ? LogLevelToString(this.options.developmentOptions?.logLevel) : undefined; } @@ -66,11 +67,27 @@ export class BrowserWorkbenchEnvironmentService implements IBrowserWorkbenchEnvi result.push([matches[1], matches[2]]); } } + return result.length ? result : undefined; } + return this.options.developmentOptions?.extensionLogLevel !== undefined ? this.options.developmentOptions?.extensionLogLevel.map(([extension, logLevel]) => ([extension, LogLevelToString(logLevel)])) : undefined; } + get profDurationMarkers(): string[] | undefined { + const profDurationMarkersFromPayload = this.payload?.get('profDurationMarkers'); + if (profDurationMarkersFromPayload) { + const result: string[] = []; + for (const entry of profDurationMarkersFromPayload.split(',')) { + result.push(entry); + } + + return result.length === 2 ? result : undefined; + } + + return undefined; + } + @memoize get windowLogsPath(): URI { return this.logsHome; } diff --git a/src/vs/workbench/services/environment/common/environmentService.ts b/src/vs/workbench/services/environment/common/environmentService.ts index a1b4d8341d1..4c726446196 100644 --- a/src/vs/workbench/services/environment/common/environmentService.ts +++ b/src/vs/workbench/services/environment/common/environmentService.ts @@ -42,6 +42,7 @@ export interface IWorkbenchEnvironmentService extends IEnvironmentService { readonly debugRenderer: boolean; readonly logExtensionHostCommunication?: boolean; readonly enableSmokeTestDriver?: boolean; + readonly profDurationMarkers?: string[]; // --- Editors to open readonly filesToOpenOrCreate?: IPath[] | undefined; diff --git a/src/vs/workbench/services/timer/browser/timerService.ts b/src/vs/workbench/services/timer/browser/timerService.ts index bff61febcc8..be8a894354a 100644 --- a/src/vs/workbench/services/timer/browser/timerService.ts +++ b/src/vs/workbench/services/timer/browser/timerService.ts @@ -18,6 +18,7 @@ import { IPaneCompositePartService } from 'vs/workbench/services/panecomposite/b import { ViewContainerLocation } from 'vs/workbench/common/views'; import { StopWatch } from 'vs/base/common/stopwatch'; import { TelemetryTrustedValue } from 'vs/platform/telemetry/common/telemetryUtils'; +import { isWeb } from 'vs/base/common/platform'; /* __GDPR__FRAGMENT__ "IMemoryInfo" : { @@ -619,7 +620,12 @@ export abstract class AbstractTimerService implements ITimerService { private async _computeStartupMetrics(): Promise { const initialStartup = this._isInitialStartup(); - const startMark = initialStartup ? 'code/didStartMain' : 'code/willOpenNewWindow'; + let startMark: string; + if (isWeb) { + startMark = 'code/timeOrigin'; + } else { + startMark = initialStartup ? 'code/didStartMain' : 'code/willOpenNewWindow'; + } const activeViewlet = this._paneCompositeService.getActivePaneComposite(ViewContainerLocation.Sidebar); const activePanel = this._paneCompositeService.getActivePaneComposite(ViewContainerLocation.Panel);