forked from microsoft/vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofilingService.ts
More file actions
33 lines (27 loc) · 1.29 KB
/
profilingService.ts
File metadata and controls
33 lines (27 loc) · 1.29 KB
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import type { ProfilingSession } from 'v8-inspect-profiler';
import { generateUuid } from 'vs/base/common/uuid';
import { IV8InspectProfilingService, IV8Profile } from 'vs/platform/profiling/common/profiling';
export class InspectProfilingService implements IV8InspectProfilingService {
_serviceBrand: undefined;
private readonly _sessions = new Map<string, ProfilingSession>();
async startProfiling(options: { port: number }): Promise<string> {
const prof = await import('v8-inspect-profiler');
const session = await prof.startProfiling({ port: options.port, checkForPaused: true });
const id = generateUuid();
this._sessions.set(id, session);
return id;
}
async stopProfiling(sessionId: string): Promise<IV8Profile> {
const session = this._sessions.get(sessionId);
if (!session) {
throw new Error(`UNKNOWN session '${sessionId}'`);
}
const result = await session.stop();
this._sessions.delete(sessionId);
return result.profile;
}
}