Welcome to mirror list, hosted at ThFree Co, Russian Federation.

notebookPerformance.ts « common « notebook « contrib « workbench « vs « src - github.com/microsoft/vscode.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: bd59c7bfbf1c6b798ca2e2ba85804946fe5039fb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import { URI } from 'vs/base/common/uri';

export type PerfName = 'startTime' | 'extensionActivated' | 'inputLoaded' | 'webviewCommLoaded' | 'customMarkdownLoaded' | 'editorLoaded';

type PerformanceMark = { [key in PerfName]?: number };

const perfMarks = new Map<string, PerformanceMark>();

export function mark(resource: URI, name: PerfName): void {
	const key = resource.toString();
	if (!perfMarks.has(key)) {
		const perfMark: PerformanceMark = {};
		perfMark[name] = Date.now();
		perfMarks.set(key, perfMark);
	} else {
		if (perfMarks.get(key)![name]) {
			console.error(`Skipping overwrite of notebook perf value: ${name}`);
			return;
		}
		perfMarks.get(key)![name] = Date.now();
	}
}

export function clearMarks(resource: URI): void {
	const key = resource.toString();

	perfMarks.delete(key);
}

export function getAndClearMarks(resource: URI): PerformanceMark | null {
	const key = resource.toString();

	const perfMark = perfMarks.get(key) || null;
	perfMarks.delete(key);
	return perfMark;
}