diff --git a/lib/perf_hooks.js b/lib/perf_hooks.js index 6c66350cab3c02..4a05f7ccba7bc8 100644 --- a/lib/perf_hooks.js +++ b/lib/perf_hooks.js @@ -36,8 +36,6 @@ const { NODE_PERFORMANCE_MILESTONE_PRELOAD_MODULE_LOAD_END } = constants; -const { sessionStats, streamStats } = process.binding('http2'); - const L = require('internal/linkedlist'); const kInspect = require('internal/util').customInspectSymbol; const { inherits } = require('util'); @@ -85,9 +83,14 @@ const IDX_SESSION_STATS_DATA_SENT = 6; const IDX_SESSION_STATS_DATA_RECEIVED = 7; const IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS = 8; +let sessionStats; +let streamStats; + function collectHttp2Stats(entry) { switch (entry.name) { case 'Http2Stream': + if (streamStats === undefined) + streamStats = process.binding('http2').streamStats; entry.id = streamStats[IDX_STREAM_STATS_ID] >>> 0; entry.timeToFirstByte = @@ -102,6 +105,8 @@ function collectHttp2Stats(entry) { streamStats[IDX_STREAM_STATS_RECEIVEDBYTES]; break; case 'Http2Session': + if (sessionStats === undefined) + sessionStats = process.binding('http2').sessionStats; entry.type = sessionStats[IDX_SESSION_STATS_TYPE] >>> 0 === 0 ? 'server' : 'client'; entry.pingRTT =