@sussudio/platform
Version:
Internal APIs for VS Code's service injection the base services.
60 lines (59 loc) • 2.28 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
var __decorate =
(this && this.__decorate) ||
function (decorators, target, key, desc) {
var c = arguments.length,
r = c < 3 ? target : desc === null ? (desc = Object.getOwnPropertyDescriptor(target, key)) : desc,
d;
if (typeof Reflect === 'object' && typeof Reflect.decorate === 'function')
r = Reflect.decorate(decorators, target, key, desc);
else
for (var i = decorators.length - 1; i >= 0; i--)
if ((d = decorators[i])) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __param =
(this && this.__param) ||
function (paramIndex, decorator) {
return function (target, key) {
decorator(target, key, paramIndex);
};
};
import { timeout } from '@sussudio/base/common/async.mjs';
import { ILogService } from '../../log/common/log.mjs';
let WindowProfiler = class WindowProfiler {
_window;
_sessionId;
_logService;
constructor(_window, _sessionId, _logService) {
this._window = _window;
this._sessionId = _sessionId;
this._logService = _logService;
}
async inspect(duration) {
await this._connect();
const inspector = this._window.webContents.debugger;
await inspector.sendCommand('Profiler.start');
this._logService.warn('[perf] profiling STARTED', this._sessionId);
await timeout(duration);
const data = await inspector.sendCommand('Profiler.stop');
this._logService.warn('[perf] profiling DONE', this._sessionId);
await this._disconnect();
return data.profile;
}
async _connect() {
const inspector = this._window.webContents.debugger;
inspector.attach();
await inspector.sendCommand('Profiler.enable');
}
async _disconnect() {
const inspector = this._window.webContents.debugger;
await inspector.sendCommand('Profiler.disable');
inspector.detach();
}
};
WindowProfiler = __decorate([__param(2, ILogService)], WindowProfiler);
export { WindowProfiler };