"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const addonProfiler_1 = require("../profilers/addonProfiler"); const inspectorProfiler_1 = require("../profilers/inspectorProfiler"); const constants_1 = require("../constants"); const Debug = require("debug"); class ProfilingConfig { } exports.ProfilingConfig = ProfilingConfig; const defaultProfilingConfig = { cpuJS: true, heapSnapshot: true, heapSampling: true, implementation: 'both' }; const disabledProfilingConfig = { cpuJS: false, heapSnapshot: false, heapSampling: false, implementation: 'none' }; class ProfilingFeature { constructor() { this.logger = Debug('axm:features:profiling'); } init(config) { if (config === true) { config = defaultProfilingConfig; } else if (config === false) { config = disabledProfilingConfig; } else if (config === undefined) { config = defaultProfilingConfig; } if (process.env.PM2_PROFILING_FORCE_FALLBACK === 'true') { config.implementation = 'addon'; } if (config.implementation === undefined || config.implementation === 'both') { config.implementation = constants_1.canUseInspector() === true ? 'inspector' : 'addon'; } switch (config.implementation) { case 'inspector': { this.logger('using inspector implementation'); this.profiler = new inspectorProfiler_1.default(); break; } case 'addon': { this.logger('using addon implementation'); this.profiler = new addonProfiler_1.default(); break; } default: { return this.logger(`Invalid profiler implementation choosen: ${config.implementation}`); } } this.logger('init'); this.profiler.init(); } destroy() { this.logger('destroy'); if (this.profiler === undefined) return; this.profiler.destroy(); } } exports.ProfilingFeature = ProfilingFeature; //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoicHJvZmlsaW5nLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vc3JjL2ZlYXR1cmVzL3Byb2ZpbGluZy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLDhEQUFzRDtBQUN0RCxzRUFBOEQ7QUFDOUQsNENBQThDO0FBQzlDLCtCQUE4QjtBQVE5QixNQUFhLGVBQWU7Q0FLM0I7QUFMRCwwQ0FLQztBQUVELE1BQU0sc0JBQXNCLEdBQW9CO0lBQzlDLEtBQUssRUFBRSxJQUFJO0lBQ1gs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