Skip to content

Commit

Permalink
Propagate source mapper for heap correctly
Browse files Browse the repository at this point in the history
Fixes #64
  • Loading branch information
simonswine committed May 20, 2024
1 parent 3b98571 commit 422857a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/profilers/heap-profiler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { heap } from '@datadog/pprof'
import { heap, SourceMapper } from '@datadog/pprof'
import { Profile } from 'pprof-format'

import { ProfileExport } from '../profile-exporter'
Expand All @@ -10,11 +10,13 @@ const log = debug('pyroscope::profiler::heap')
export interface HeapProfilerStartArgs {
samplingIntervalBytes: number
stackDepth: number
sourceMapper: SourceMapper | undefined
}

export class HeapProfiler implements Profiler<HeapProfilerStartArgs> {
private labels: Record<string, number | string>
private lastProfiledAt: Date
private sourceMapper: SourceMapper | undefined

constructor() {
this.labels = {}
Expand All @@ -28,7 +30,7 @@ export class HeapProfiler implements Profiler<HeapProfilerStartArgs> {
public profile(): ProfileExport {
log('profile')

const profile: Profile = heap.profile()
const profile: Profile = heap.profile(undefined, this.sourceMapper, undefined)

const lastProfileStartedAt: Date = this.lastProfiledAt
this.lastProfiledAt = new Date()
Expand All @@ -48,6 +50,7 @@ export class HeapProfiler implements Profiler<HeapProfilerStartArgs> {
log('start')

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

Expand Down
1 change: 1 addition & 0 deletions src/profilers/pyroscope-profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ export class PyroscopeProfiler {
flushIntervalMs: flushIntervalMs,
profiler: new HeapProfiler(),
startArgs: {
sourceMapper: config.sourceMapper,
samplingIntervalBytes:
config.heap?.samplingIntervalBytes ?? DEFAULT_SAMPLING_INTERVAL_BYTES,
stackDepth: config.heap?.stackDepth ?? DEFAULT_STACK_DEPTH,
Expand Down

0 comments on commit 422857a

Please sign in to comment.