Skip to content

Commit

Permalink
Add parallelism information to profiles (#4765)
Browse files Browse the repository at this point in the history
  • Loading branch information
szegedi authored Jan 15, 2025
1 parent 9e36df0 commit b070889
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/dd-trace/src/profiling/exporters/event_serializer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,22 @@ const os = require('os')
const perf = require('perf_hooks').performance
const version = require('../../../../../package.json').version

const libuvThreadPoolSize = (() => {
const ss = process.env.UV_THREADPOOL_SIZE
if (ss === undefined) {
// Backend will apply the default size based on Node version.
return undefined
}
// libuv uses atoi to parse the value, which is almost the same as parseInt, except that parseInt
// will return NaN on invalid input, while atoi will return 0. This is handled at return.
const s = parseInt(ss)
// We dont' interpret the value further here in the library. Backend will interpret the number
// based on Node version. In all currently known Node versions, 0 results in 1 worker thread,
// negative values (because they're assigned to an unsigned int) become very high positive values,
// and the value is finally capped at 1024.
return isNaN(s) ? 0 : s
})()

class EventSerializer {
constructor ({ env, host, service, version, libraryInjected, activation } = {}) {
this._env = env
Expand Down Expand Up @@ -56,11 +72,16 @@ class EventSerializer {
version
},
runtime: {
// os.availableParallelism only available in node 18.14.0/19.4.0 and above
available_processors: typeof os.availableParallelism === 'function'
? os.availableParallelism()
: os.cpus().length,
// Using `nodejs` for consistency with the existing `runtime` tag.
// Note that the event `family` property uses `node`, as that's what's
// proscribed by the Intake API, but that's an internal enum and is
// not customer visible.
engine: 'nodejs',
libuv_threadpool_size: libuvThreadPoolSize,
// strip off leading 'v'. This makes the format consistent with other
// runtimes (e.g. Ruby) but not with the existing `runtime_version` tag.
// We'll keep it like this as we want cross-engine consistency. We
Expand Down
3 changes: 2 additions & 1 deletion packages/dd-trace/test/profiling/exporters/agent.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ describe('exporters/agent', function () {
expect(event.info.profiler.ssi).to.have.property('mechanism', 'none')
expect(event.info.profiler).to.have.property('version', version)
expect(event.info).to.have.property('runtime')
expect(Object.keys(event.info.runtime)).to.have.length(2)
expect(Object.keys(event.info.runtime)).to.have.length(3)
expect(event.info.runtime).to.have.property('available_processors')
expect(event.info.runtime).to.have.property('engine', 'nodejs')
expect(event.info.runtime).to.have.property('version', process.version.substring(1))

Expand Down

0 comments on commit b070889

Please sign in to comment.