Skip to content
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

perf - allow to log duration of 2 perf markers in web #171152

Merged
merged 3 commits into from Jan 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -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;
Expand Down Expand Up @@ -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
);
Expand Up @@ -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;
}

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

Expand Down
Expand Up @@ -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;
Expand Down
8 changes: 7 additions & 1 deletion src/vs/workbench/services/timer/browser/timerService.ts
Expand Up @@ -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" : {
Expand Down Expand Up @@ -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);
Expand Down