Skip to content

Commit b73c126

Browse files
nsavoireQard
authored andcommitted
[profiling] Adapt to new pprof-nodejs API (#3368)
* Remove cpu-experimental profiler * Adapt to API changes in pprof-nodejs
1 parent cee63ca commit b73c126

File tree

9 files changed

+64
-355
lines changed

9 files changed

+64
-355
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": "^1.6.0",
73-
"@datadog/pprof": "2.2.3",
73+
"@datadog/pprof": "3.0.0",
7474
"@datadog/sketches-js": "^2.1.0",
7575
"@types/node": "<18.13",
7676
"@opentelemetry/api": "^1.0.0",

packages/dd-trace/src/profiling/config.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const { URL, format, pathToFileURL } = require('url')
77
const { AgentExporter } = require('./exporters/agent')
88
const { FileExporter } = require('./exporters/file')
99
const { ConsoleLogger } = require('./loggers/console')
10-
const CpuProfiler = require('./profilers/cpu')
1110
const WallProfiler = require('./profilers/wall')
1211
const SpaceProfiler = require('./profilers/space')
1312
const { oomExportStrategies, snapshotKinds } = require('./constants')
@@ -202,8 +201,6 @@ function getProfiler (name, options) {
202201
return new WallProfiler(options)
203202
case 'space':
204203
return new SpaceProfiler(options)
205-
case 'cpu-experimental':
206-
return new CpuProfiler(options)
207204
default:
208205
options.logger.error(`Unknown profiler "${name}"`)
209206
}

packages/dd-trace/src/profiling/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
'use strict'
22

33
const { Profiler, ServerlessProfiler } = require('./profiler')
4-
const CpuProfiler = require('./profilers/cpu')
54
const WallProfiler = require('./profilers/wall')
65
const SpaceProfiler = require('./profilers/space')
76
const { AgentExporter } = require('./exporters/agent')
@@ -14,7 +13,6 @@ module.exports = {
1413
profiler,
1514
AgentExporter,
1615
FileExporter,
17-
CpuProfiler,
1816
WallProfiler,
1917
SpaceProfiler,
2018
ConsoleLogger

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

Lines changed: 0 additions & 126 deletions
This file was deleted.

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/config.spec.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const os = require('os')
77
const path = require('path')
88
const { AgentExporter } = require('../../src/profiling/exporters/agent')
99
const { FileExporter } = require('../../src/profiling/exporters/file')
10-
const CpuProfiler = require('../../src/profiling/profilers/cpu')
1110
const WallProfiler = require('../../src/profiling/profilers/wall')
1211
const SpaceProfiler = require('../../src/profiling/profilers/space')
1312
const { ConsoleLogger } = require('../../src/profiling/loggers/console')
@@ -58,7 +57,7 @@ describe('config', () => {
5857
error () { }
5958
},
6059
exporters: 'agent,file',
61-
profilers: 'wall,cpu-experimental',
60+
profilers: 'wall',
6261
url: 'http://localhost:1234/'
6362
}
6463

@@ -79,9 +78,8 @@ describe('config', () => {
7978
expect(config.exporters[0]._url.toString()).to.equal(options.url)
8079
expect(config.exporters[1]).to.be.an.instanceof(FileExporter)
8180
expect(config.profilers).to.be.an('array')
82-
expect(config.profilers.length).to.equal(2)
81+
expect(config.profilers.length).to.equal(1)
8382
expect(config.profilers[0]).to.be.an.instanceOf(WallProfiler)
84-
expect(config.profilers[1]).to.be.an.instanceOf(CpuProfiler)
8583
})
8684

8785
it('should filter out invalid profilers', () => {

0 commit comments

Comments
 (0)