Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
rochdev committed Nov 27, 2024
1 parent 333e29d commit 3217b4f
Showing 1 changed file with 11 additions and 15 deletions.
26 changes: 11 additions & 15 deletions packages/dd-trace/src/runtime_metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {

if (allMetricsAvailable) { // All metrics are available from Node, skip native.
cpuUsage = process.cpuUsage()
lastLoopCount = getLoopCount()
lastLoopCount = performance.nodeTiming.uvMetricsInfo.loopCount
loopDelayHistogram = monitorEventLoopDelay()
loopDelayHistogram.enable()
gcProfiler = new v8.GCProfiler()
Expand Down Expand Up @@ -235,16 +235,18 @@ function captureHeapSpace () {
}

function captureEventLoopMetrics () {
const totalLoopCount = getLoopCount()
const totalLoopCount = performance.nodeTiming.uvMetricsInfo.loopCount
const loopCount = totalLoopCount - lastLoopCount

client.gauge('runtime.node.event_loop.delay.max', loopDelayHistogram.max)
client.gauge('runtime.node.event_loop.delay.min', loopDelayHistogram.min)
client.increment('runtime.node.event_loop.delay.sum', loopDelayHistogram.mean * loopCount)
client.gauge('runtime.node.event_loop.delay.avg', loopDelayHistogram.mean)
client.gauge('runtime.node.event_loop.delay.median', loopDelayHistogram.percentile(50))
client.gauge('runtime.node.event_loop.delay.95percentile', loopDelayHistogram.percentile(95))
client.increment('runtime.node.event_loop.delay.count', loopCount)
histogram('runtime.node.event_loop.delay', {
max: loopDelayHistogram.max,
min: loopDelayHistogram.min,
mean: loopDelayHistogram.mean * loopCount,
avg: loopDelayHistogram.mean,
median: loopDelayHistogram.percentile(50),
p95: loopDelayHistogram.percentile(95),
count: loopCount
})

lastLoopCount = totalLoopCount

Expand Down Expand Up @@ -364,12 +366,6 @@ function captureNativeMetrics () {
}
}

function getLoopCount () {
const uvMetricsInfo = performance.nodeTiming.uvMetricsInfo

return uvMetricsInfo ? uvMetricsInfo.loopCount : null
}

function histogram (name, stats, tags) {
tags = [].concat(tags)

Expand Down

0 comments on commit 3217b4f

Please sign in to comment.