Skip to content

Commit

Permalink
Fix CPU profiler latency
Browse files Browse the repository at this point in the history
The current profile must be stopped AFTER the next begins. This is because V8 will
tear down the symbolizer thread when the active profile count reaches zero. This
means the next profile started will spin up a new symbolizer thread. When this
thread starts it streams in all the JIT location information which could block the
JavaScript thread for a significant length of time.
  • Loading branch information
Qard committed Nov 2, 2021
1 parent 56c67f5 commit 31c81fc
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
4 changes: 1 addition & 3 deletions packages/dd-trace/src/profiling/profilers/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,7 @@ class NativeCpuProfiler {

profile () {
if (!this._stop) return
const profile = this._stop()
this._record()
return profile
return this._stop(true)
}

encode (profile) {
Expand Down
2 changes: 1 addition & 1 deletion packages/dd-trace/test/profiling/profilers/cpu.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ describe('profilers/native/cpu', () => {
expect(profile).to.equal('profile')

sinon.assert.calledOnce(stop)
sinon.assert.calledTwice(pprof.time.start)
sinon.assert.calledOnce(pprof.time.start)
})

it('should encode profiles from the pprof time profiler', () => {
Expand Down

0 comments on commit 31c81fc

Please sign in to comment.