diff --git a/src/profilers/heap-profiler.ts b/src/profilers/heap-profiler.ts index 03ef1faa..9a404803 100644 --- a/src/profilers/heap-profiler.ts +++ b/src/profilers/heap-profiler.ts @@ -4,6 +4,10 @@ import { Profile } from 'pprof-format'; import { ProfileExport } from '../profile-exporter.js'; import { Profiler } from './profiler.js'; import debug from 'debug'; +import { + DEFAULT_SAMPLING_INTERVAL_BYTES, + DEFAULT_STACK_DEPTH, +} from './pyroscope-profiler.js'; const log = debug('pyroscope::profiler::heap'); @@ -16,6 +20,8 @@ export interface HeapProfilerStartArgs { export class HeapProfiler implements Profiler { private lastProfiledAt: Date; private sourceMapper: SourceMapper | undefined; + private samplingIntervalBytes: number = DEFAULT_SAMPLING_INTERVAL_BYTES; + private stackDepth: number = DEFAULT_STACK_DEPTH; constructor() { this.lastProfiledAt = new Date(); @@ -38,6 +44,9 @@ export class HeapProfiler implements Profiler { undefined ); + heap.stop(); + heap.start(this.samplingIntervalBytes, this.stackDepth); + const lastProfileStartedAt: Date = this.lastProfiledAt; this.lastProfiledAt = new Date(); @@ -57,6 +66,8 @@ export class HeapProfiler implements Profiler { this.lastProfiledAt = new Date(); this.sourceMapper = args.sourceMapper; + this.samplingIntervalBytes = args.samplingIntervalBytes; + this.stackDepth = args.stackDepth; heap.start(args.samplingIntervalBytes, args.stackDepth); } diff --git a/src/profilers/pyroscope-profiler.ts b/src/profilers/pyroscope-profiler.ts index 9e14782d..efc840fa 100644 --- a/src/profilers/pyroscope-profiler.ts +++ b/src/profilers/pyroscope-profiler.ts @@ -22,9 +22,10 @@ const DEFAULT_SAMPLING_INTERVAL_MICROS = MICROS_PER_SECOND / DEFAULT_SAMPLING_HZ; const DEFAULT_SAMPLING_INTERVAL_MB = 512; -const DEFAULT_SAMPLING_INTERVAL_BYTES = B_PER_MB * DEFAULT_SAMPLING_INTERVAL_MB; +export const DEFAULT_SAMPLING_INTERVAL_BYTES = + B_PER_MB * DEFAULT_SAMPLING_INTERVAL_MB; -const DEFAULT_STACK_DEPTH = 64; +export const DEFAULT_STACK_DEPTH = 64; const DEFAULT_APP_NAME = ''; const DEFAULT_SERVER_ADDRESS = 'http://localhost:4040';