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`

* 💄
This commit is contained in:
Benjamin Pasero 2023-01-12 14:13:51 +01:00 committed by GitHub
parent 05baad392b
commit 90609a93f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 2 deletions

View File

@ -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<void> {
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<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(
ResourcePerformanceMarks,
LifecyclePhase.Eventually
);
Registry.as<IWorkbenchContributionsRegistry>(Extensions.Workbench).registerWorkbenchContribution(
StartupTimings,
LifecyclePhase.Eventually
);

View File

@ -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; }

View File

@ -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;

View File

@ -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<IStartupMetrics> {
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);