Skip to content

Commit 9d0618d

Browse files
committed
Adapt to API changes in pprof-nodejs
1 parent fe3b51c commit 9d0618d

File tree

4 files changed

+62
-45
lines changed

4 files changed

+62
-45
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"@datadog/native-iast-rewriter": "2.0.1",
7171
"@datadog/native-iast-taint-tracking": "^1.5.0",
7272
"@datadog/native-metrics": "^2.0.0",
73-
"@datadog/pprof": "2.2.3",
73+
"@datadog/pprof": "3.0.0",
7474
"@datadog/sketches-js": "^2.1.0",
7575
"@opentelemetry/api": "^1.0.0",
7676
"@opentelemetry/core": "^1.14.0",

packages/dd-trace/src/profiling/profilers/wall.js

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@
33
class NativeWallProfiler {
44
constructor (options = {}) {
55
this.type = 'wall'
6-
this._samplingInterval = options.samplingInterval || 1e6 / 99 // 99hz
6+
this._samplingIntervalMicros = options.samplingInterval || 1e6 / 99 // 99hz
7+
this._flushIntervalMillis = options.flushInterval || 60 * 1e3 // 60 seconds
8+
this._codeHotspotsEnabled = !!options.codeHotspotsEnabled
79
this._mapper = undefined
810
this._pprof = undefined
11+
12+
this._logger = options.logger
13+
this._started = false
914
}
1015

1116
start ({ mapper } = {}) {
17+
if (this._started) return
18+
1219
this._mapper = mapper
1320
this._pprof = require('@datadog/pprof')
1421

@@ -20,27 +27,32 @@ class NativeWallProfiler {
2027
process._stopProfilerIdleNotifier = () => {}
2128
}
2229

23-
this._record()
30+
this._pprof.time.start({
31+
intervalMicros: this._samplingIntervalMicros,
32+
durationMillis: this._flushIntervalMillis,
33+
sourceMapper: this._mapper,
34+
customLabels: this._codeHotspotsEnabled,
35+
lineNumbers: false
36+
})
37+
38+
this._started = true
2439
}
2540

2641
profile () {
27-
if (!this._stop) return
28-
return this._stop(true)
42+
if (!this._started) return
43+
return this._pprof.time.stop(true)
2944
}
3045

3146
encode (profile) {
3247
return this._pprof.encode(profile)
3348
}
3449

3550
stop () {
36-
if (!this._stop) return
37-
this._stop()
38-
this._stop = undefined
39-
}
51+
if (!this._started) return
4052

41-
_record () {
42-
this._stop = this._pprof.time.start(this._samplingInterval, null,
43-
this._mapper, false)
53+
const profile = this._pprof.time.stop()
54+
this._started = false
55+
return profile
4456
}
4557
}
4658

packages/dd-trace/test/profiling/profilers/wall.spec.js

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ const sinon = require('sinon')
99
describe('profilers/native/wall', () => {
1010
let NativeWallProfiler
1111
let pprof
12-
let stop
1312

1413
beforeEach(() => {
15-
stop = sinon.stub().returns('profile')
1614
pprof = {
1715
encode: sinon.stub().returns(Promise.resolve()),
1816
time: {
19-
start: sinon.stub().returns(stop)
17+
start: sinon.stub(),
18+
stop: sinon.stub().returns('profile')
2019
}
2120
}
2221

@@ -45,24 +44,35 @@ describe('profilers/native/wall', () => {
4544
process._stopProfilerIdleNotifier = stop
4645

4746
sinon.assert.calledOnce(pprof.time.start)
48-
sinon.assert.calledWith(pprof.time.start, 1e6 / 99)
47+
sinon.assert.calledWith(pprof.time.start,
48+
{ intervalMicros: 1e6 / 99,
49+
durationMillis: 60000,
50+
sourceMapper: undefined,
51+
customLabels: false,
52+
lineNumbers: false })
4953
})
5054

5155
it('should use the provided configuration options', () => {
5256
const samplingInterval = 500
5357
const profiler = new NativeWallProfiler({ samplingInterval })
5458

5559
profiler.start()
60+
profiler.stop()
5661

57-
sinon.assert.calledWith(pprof.time.start, samplingInterval)
62+
sinon.assert.calledWith(pprof.time.start,
63+
{ intervalMicros: 500,
64+
durationMillis: 60000,
65+
sourceMapper: undefined,
66+
customLabels: false,
67+
lineNumbers: false })
5868
})
5969

6070
it('should not stop when not started', () => {
6171
const profiler = new NativeWallProfiler()
6272

6373
profiler.stop()
6474

65-
sinon.assert.notCalled(stop)
75+
sinon.assert.notCalled(pprof.time.stop)
6676
})
6777

6878
it('should stop the internal time profiler', () => {
@@ -71,7 +81,7 @@ describe('profilers/native/wall', () => {
7181
profiler.start()
7282
profiler.stop()
7383

74-
sinon.assert.calledOnce(stop)
84+
sinon.assert.calledOnce(pprof.time.stop)
7585
})
7686

7787
it('should stop the internal time profiler only once', () => {
@@ -81,7 +91,7 @@ describe('profilers/native/wall', () => {
8191
profiler.stop()
8292
profiler.stop()
8393

84-
sinon.assert.calledOnce(stop)
94+
sinon.assert.calledOnce(pprof.time.stop)
8595
})
8696

8797
it('should collect profiles from the internal time profiler', () => {
@@ -93,8 +103,9 @@ describe('profilers/native/wall', () => {
93103

94104
expect(profile).to.equal('profile')
95105

96-
sinon.assert.calledOnce(stop)
106+
sinon.assert.calledOnce(pprof.time.stop)
97107
sinon.assert.calledOnce(pprof.time.start)
108+
profiler.stop()
98109
})
99110

100111
it('should encode profiles from the pprof time profiler', () => {
@@ -106,6 +117,8 @@ describe('profilers/native/wall', () => {
106117

107118
profiler.encode(profile)
108119

120+
profiler.stop()
121+
109122
sinon.assert.calledOnce(pprof.encode)
110123
})
111124

@@ -115,7 +128,13 @@ describe('profilers/native/wall', () => {
115128
const mapper = {}
116129

117130
profiler.start({ mapper })
131+
profiler.stop()
118132

119-
sinon.assert.calledWith(pprof.time.start, 1e6 / 99, null, mapper, false)
133+
sinon.assert.calledWith(pprof.time.start,
134+
{ intervalMicros: 1e6 / 99,
135+
durationMillis: 60000,
136+
sourceMapper: mapper,
137+
customLabels: false,
138+
lineNumbers: false })
120139
})
121140
})

yarn.lock

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -409,18 +409,16 @@
409409
node-addon-api "^6.1.0"
410410
node-gyp-build "^3.9.0"
411411

412-
"@datadog/pprof@2.2.3":
413-
version "2.2.3"
414-
resolved "https://registry.yarnpkg.com/@datadog/pprof/-/pprof-2.2.3.tgz#a22ca30e386f5aa8559f4b2e297b76c80551c26d"
415-
integrity sha512-cZXvNBBzvTMUx2xOxp49cZJ7/HOF7geVxqeRbveeJUVKwi8ZxmU1rQGcWPFX4iEEtfQu1M3NqbhmNtYsMJdEsQ==
412+
"@datadog/pprof@3.0.0":
413+
version "3.0.0"
414+
resolved "https://registry.yarnpkg.com/@datadog/pprof/-/pprof-3.0.0.tgz#b5e6df853589512ceb470c44cfc50cbe2ebfa5ab"
415+
integrity sha512-nE/iWBX6h61SXrVWA6DeJ/m2iJX9ZNHrcoxFzHkK0LnSbNzrMlQZ0yw24ExhvIPLOFP4uFW057Cm48rsgr0NyQ==
416416
dependencies:
417417
delay "^5.0.0"
418-
node-gyp-build "^3.9.0"
418+
node-gyp-build "<4.0"
419419
p-limit "^3.1.0"
420-
pify "^5.0.0"
421420
pprof-format "^2.0.7"
422-
source-map "^0.7.3"
423-
split "^1.0.1"
421+
source-map "^0.7.4"
424422

425423
"@datadog/sketches-js@^2.1.0":
426424
version "2.1.0"
@@ -3314,7 +3312,7 @@ node-addon-api@^6.1.0:
33143312
resolved "https://registry.yarnpkg.com/node-addon-api/-/node-addon-api-6.1.0.tgz#ac8470034e58e67d0c6f1204a18ae6995d9c0d76"
33153313
integrity sha512-+eawOlIgy680F0kBzPUNFhMZGtJ1YmqM6l4+Crf4IkImjYrO/mqPwRMh352g23uIaQKFItcQ64I7KMaJxHgAVA==
33163314

3317-
node-gyp-build@^3.9.0:
3315+
node-gyp-build@<4.0, node-gyp-build@^3.9.0:
33183316
version "3.9.0"
33193317
resolved "https://registry.yarnpkg.com/node-gyp-build/-/node-gyp-build-3.9.0.tgz#53a350187dd4d5276750da21605d1cb681d09e25"
33203318
integrity sha512-zLcTg6P4AbcHPq465ZMFNXx7XpKKJh+7kkN699NiQWisR2uWYOWNWqRHAmbnmKiL4e9aLSlmy5U7rEMUXV59+A==
@@ -3612,11 +3610,6 @@ picomatch@^2.0.4, picomatch@^2.2.1, picomatch@^2.3.1:
36123610
resolved "https://registry.yarnpkg.com/picomatch/-/picomatch-2.3.1.tgz#3ba3833733646d9d3e4995946c1365a67fb07a42"
36133611
integrity sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==
36143612

3615-
pify@^5.0.0:
3616-
version "5.0.0"
3617-
resolved "https://registry.yarnpkg.com/pify/-/pify-5.0.0.tgz#1f5eca3f5e87ebec28cc6d54a0e4aaf00acc127f"
3618-
integrity sha512-eW/gHNMlxdSP6dmG6uJip6FXN0EQBwm2clYYd8Wul42Cwu/DK8HEftzsapcNdYe2MfLiIwZqsDk2RDEsTE79hA==
3619-
36203613
pkg-dir@^4.1.0:
36213614
version "4.2.0"
36223615
resolved "https://registry.yarnpkg.com/pkg-dir/-/pkg-dir-4.2.0.tgz#f099133df7ede422e81d1d8448270eeb3e4261f3"
@@ -4116,7 +4109,7 @@ source-map@^0.6.0, source-map@^0.6.1:
41164109
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.6.1.tgz#74722af32e9614e9c287a8d0bbde48b5e2f1a263"
41174110
integrity sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==
41184111

4119-
source-map@^0.7.3:
4112+
source-map@^0.7.4:
41204113
version "0.7.4"
41214114
resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.7.4.tgz#a9bbe705c9d8846f4e08ff6765acf0f1b0898656"
41224115
integrity sha512-l3BikUxvPOcn5E74dZiq5BGsTb5yEwhaTSzccU6t4sDOH8NWJCstKO5QT2CvtFoK6F0saL7p9xHAqHOlCPJygA==
@@ -4133,13 +4126,6 @@ spawn-wrap@^2.0.0:
41334126
signal-exit "^3.0.2"
41344127
which "^2.0.1"
41354128

4136-
split@^1.0.1:
4137-
version "1.0.1"
4138-
resolved "https://registry.yarnpkg.com/split/-/split-1.0.1.tgz#605bd9be303aa59fb35f9229fbea0ddec9ea07d9"
4139-
integrity sha512-mTyOoPbrivtXnwnIxZRFYRrPNtEFKlpB2fvjSnCQUiAA6qAZzqwna5envK4uk6OIeP17CsdF3rSBGYVBsU0Tkg==
4140-
dependencies:
4141-
through "2"
4142-
41434129
sprintf-js@~1.0.2:
41444130
version "1.0.3"
41454131
resolved "https://registry.yarnpkg.com/sprintf-js/-/sprintf-js-1.0.3.tgz#04e6926f662895354f3dd015203633b857297e2c"
@@ -4377,7 +4363,7 @@ text-table@^0.2.0:
43774363
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
43784364
integrity sha512-N+8UisAXDGk8PFXP4HAzVR9nbfmVJ3zYLAWiTIoqC5v5isinhr+r5uaO8+7r3BMfuNIufIsA7RdpVgacC2cSpw==
43794365

4380-
through@2, through@~2.3.4, through@~2.3.8:
4366+
through@~2.3.4, through@~2.3.8:
43814367
version "2.3.8"
43824368
resolved "https://registry.yarnpkg.com/through/-/through-2.3.8.tgz#0dd4c9ffaabc357960b1b724115d7e0e86a2e1f5"
43834369
integrity sha512-w89qg7PI8wAdvX60bMDP+bFoD5Dvhm9oLheFp5O4a2QF0cSBGsBX4qZmadPMvVqlLJBBci+WqGGOAPvcDeNSVg==

0 commit comments

Comments
 (0)