@sussudio/platform
Version:
Internal APIs for VS Code's service injection the base services.
88 lines (87 loc) • 3.3 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 { DefaultWorkerFactory } from '@sussudio/base/browser/defaultWorkerFactory.mjs';
import { SimpleWorkerClient } from '@sussudio/base/common/worker/simpleWorker.mjs';
import { registerSingleton } from '../../instantiation/common/extensions.mjs';
import { createDecorator } from '../../instantiation/common/instantiation.mjs';
import { ILogService } from '../../log/common/log.mjs';
import { reportSample } from '../common/profilingTelemetrySpec.mjs';
import { ITelemetryService } from '../../telemetry/common/telemetry.mjs';
export const IProfileAnalysisWorkerService = createDecorator('IProfileAnalysisWorkerService');
// ---- impl
let ProfileAnalysisWorkerService = class ProfileAnalysisWorkerService {
_telemetryService;
_logService;
_workerFactory = new DefaultWorkerFactory('CpuProfileAnalysis');
constructor(_telemetryService, _logService) {
this._telemetryService = _telemetryService;
this._logService = _logService;
}
async _withWorker(callback) {
const worker = new SimpleWorkerClient(
this._workerFactory,
'vs/platform/profiling/electron-sandbox/profileAnalysisWorker',
{
/* host */
},
);
try {
const r = await callback(await worker.getProxyObject());
return r;
} finally {
worker.dispose();
}
}
async analyseBottomUp(profile, callFrameClassifier, perfBaseline) {
return this._withWorker(async (worker) => {
const result = await worker.analyseBottomUp(profile);
if (result.kind === 2 /* ProfilingOutput.Interesting */) {
for (const sample of result.samples) {
reportSample(
{
sample,
perfBaseline,
source: callFrameClassifier(sample.url),
},
this._telemetryService,
this._logService,
);
}
}
return result.kind;
});
}
async analyseByLocation(profile, locations) {
return this._withWorker(async (worker) => {
const result = await worker.analyseByUrlCategory(profile, locations);
return result;
});
}
};
ProfileAnalysisWorkerService = __decorate(
[__param(0, ITelemetryService), __param(1, ILogService)],
ProfileAnalysisWorkerService,
);
registerSingleton(IProfileAnalysisWorkerService, ProfileAnalysisWorkerService, 1 /* InstantiationType.Delayed */);