Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions src/profilers/heap-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -16,6 +20,8 @@ export interface HeapProfilerStartArgs {
export class HeapProfiler implements Profiler<HeapProfilerStartArgs> {
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();
Expand All @@ -38,6 +44,9 @@ export class HeapProfiler implements Profiler<HeapProfilerStartArgs> {
undefined
);

heap.stop();
heap.start(this.samplingIntervalBytes, this.stackDepth);

const lastProfileStartedAt: Date = this.lastProfiledAt;
this.lastProfiledAt = new Date();

Expand All @@ -57,6 +66,8 @@ export class HeapProfiler implements Profiler<HeapProfilerStartArgs> {

this.lastProfiledAt = new Date();
this.sourceMapper = args.sourceMapper;
this.samplingIntervalBytes = args.samplingIntervalBytes;
this.stackDepth = args.stackDepth;
heap.start(args.samplingIntervalBytes, args.stackDepth);
}

Expand Down
5 changes: 3 additions & 2 deletions src/profilers/pyroscope-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
Loading