Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[profiling] Adapt to new pprof-nodejs API #3368

Merged
merged 2 commits into from
Jul 10, 2023
Merged
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
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
"@datadog/native-iast-rewriter": "2.0.1",
"@datadog/native-iast-taint-tracking": "^1.5.0",
"@datadog/native-metrics": "^2.0.0",
"@datadog/pprof": "2.2.3",
"@datadog/pprof": "3.0.0",
"@datadog/sketches-js": "^2.1.0",
"@opentelemetry/api": "^1.0.0",
"@opentelemetry/core": "^1.14.0",
Expand Down
3 changes: 0 additions & 3 deletions packages/dd-trace/src/profiling/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const { URL, format, pathToFileURL } = require('url')
const { AgentExporter } = require('./exporters/agent')
const { FileExporter } = require('./exporters/file')
const { ConsoleLogger } = require('./loggers/console')
const CpuProfiler = require('./profilers/cpu')
const WallProfiler = require('./profilers/wall')
const SpaceProfiler = require('./profilers/space')
const { oomExportStrategies, snapshotKinds } = require('./constants')
Expand Down Expand Up @@ -202,8 +201,6 @@ function getProfiler (name, options) {
return new WallProfiler(options)
case 'space':
return new SpaceProfiler(options)
case 'cpu-experimental':
return new CpuProfiler(options)
default:
options.logger.error(`Unknown profiler "${name}"`)
}
Expand Down
2 changes: 0 additions & 2 deletions packages/dd-trace/src/profiling/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const { Profiler, ServerlessProfiler } = require('./profiler')
const CpuProfiler = require('./profilers/cpu')
const WallProfiler = require('./profilers/wall')
const SpaceProfiler = require('./profilers/space')
const { AgentExporter } = require('./exporters/agent')
Expand All @@ -14,7 +13,6 @@ module.exports = {
profiler,
AgentExporter,
FileExporter,
CpuProfiler,
WallProfiler,
SpaceProfiler,
ConsoleLogger
Expand Down
126 changes: 0 additions & 126 deletions packages/dd-trace/src/profiling/profilers/cpu.js

This file was deleted.

34 changes: 23 additions & 11 deletions packages/dd-trace/src/profiling/profilers/wall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,19 @@
class NativeWallProfiler {
constructor (options = {}) {
this.type = 'wall'
this._samplingInterval = options.samplingInterval || 1e6 / 99 // 99hz
this._samplingIntervalMicros = options.samplingInterval || 1e6 / 99 // 99hz
this._flushIntervalMillis = options.flushInterval || 60 * 1e3 // 60 seconds
this._codeHotspotsEnabled = !!options.codeHotspotsEnabled
this._mapper = undefined
this._pprof = undefined

this._logger = options.logger
this._started = false
}

start ({ mapper } = {}) {
if (this._started) return

this._mapper = mapper
this._pprof = require('@datadog/pprof')

Expand All @@ -20,27 +27,32 @@ class NativeWallProfiler {
process._stopProfilerIdleNotifier = () => {}
}

this._record()
this._pprof.time.start({
intervalMicros: this._samplingIntervalMicros,
durationMillis: this._flushIntervalMillis,
sourceMapper: this._mapper,
customLabels: this._codeHotspotsEnabled,
lineNumbers: false
})

this._started = true
}

profile () {
if (!this._stop) return
return this._stop(true)
if (!this._started) return
return this._pprof.time.stop(true)
}

encode (profile) {
return this._pprof.encode(profile)
}

stop () {
if (!this._stop) return
this._stop()
this._stop = undefined
}
if (!this._started) return

_record () {
this._stop = this._pprof.time.start(this._samplingInterval, null,
this._mapper, false)
const profile = this._pprof.time.stop()
this._started = false
return profile
}
}

Expand Down
6 changes: 2 additions & 4 deletions packages/dd-trace/test/profiling/config.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const os = require('os')
const path = require('path')
const { AgentExporter } = require('../../src/profiling/exporters/agent')
const { FileExporter } = require('../../src/profiling/exporters/file')
const CpuProfiler = require('../../src/profiling/profilers/cpu')
const WallProfiler = require('../../src/profiling/profilers/wall')
const SpaceProfiler = require('../../src/profiling/profilers/space')
const { ConsoleLogger } = require('../../src/profiling/loggers/console')
Expand Down Expand Up @@ -58,7 +57,7 @@ describe('config', () => {
error () { }
},
exporters: 'agent,file',
profilers: 'wall,cpu-experimental',
profilers: 'wall',
url: 'http://localhost:1234/'
}

Expand All @@ -79,9 +78,8 @@ describe('config', () => {
expect(config.exporters[0]._url.toString()).to.equal(options.url)
expect(config.exporters[1]).to.be.an.instanceof(FileExporter)
expect(config.profilers).to.be.an('array')
expect(config.profilers.length).to.equal(2)
expect(config.profilers.length).to.equal(1)
expect(config.profilers[0]).to.be.an.instanceOf(WallProfiler)
expect(config.profilers[1]).to.be.an.instanceOf(CpuProfiler)
})

it('should filter out invalid profilers', () => {
Expand Down
Loading