UNPKG

@beincom/node-profile

Version:

``` npm install @beincom/node-profile # yarn add @beincom/node-profile ```

55 lines 1.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.WallProfiler = void 0; const common_1 = require("@nestjs/common"); const pprof_1 = require("@datadog/pprof"); const MICROS_PER_SECOND = 1e6; class WallProfiler { constructor() { this.labels = {}; this.lastProfiledAt = new Date(); } getLabels() { return this.labels; } profile() { common_1.Logger.log('profile'); return this.innerProfile(true); } setLabels(labels) { this.labels = labels; } start(args) { if (!pprof_1.time.isStarted()) { common_1.Logger.log('start'); this.lastProfiledAt = new Date(); this.lastSamplingIntervalMicros = args.samplingDurationMs; pprof_1.time.start({ sourceMapper: args.sourceMapper, durationMillis: args.samplingDurationMs, intervalMicros: args.samplingIntervalMicros, withContexts: true, workaroundV8Bug: true, }); pprof_1.time.setContext({}); } } stop() { common_1.Logger.log('stop'); return this.innerProfile(false); } innerProfile(restart) { pprof_1.time.setContext({}); const profile = pprof_1.time.stop(restart, () => this.labels); const lastProfileStartedAt = this.lastProfiledAt; this.lastProfiledAt = new Date(); return { profile, sampleRate: Math.ceil(MICROS_PER_SECOND / this.lastSamplingIntervalMicros), startedAt: lastProfileStartedAt, stoppedAt: this.lastProfiledAt, }; } } exports.WallProfiler = WallProfiler; //# sourceMappingURL=wall-profiler.js.map