mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 21:58:48 +02:00
http2: use aliased buffer for perf stats, add stats
Add an aliased buffer for session and stream statistics, add a few more metrics PR-URL: https://github.com/nodejs/node/pull/18020 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
This commit is contained in:
parent
ececdd3167
commit
a02fcd2716
6 changed files with 240 additions and 66 deletions
|
@ -66,6 +66,70 @@ const observerableTypes = [
|
|||
'http2'
|
||||
];
|
||||
|
||||
const IDX_STREAM_STATS_ID = 0;
|
||||
const IDX_STREAM_STATS_TIMETOFIRSTBYTE = 1;
|
||||
const IDX_STREAM_STATS_TIMETOFIRSTHEADER = 2;
|
||||
const IDX_STREAM_STATS_TIMETOFIRSTBYTESENT = 3;
|
||||
const IDX_STREAM_STATS_SENTBYTES = 4;
|
||||
const IDX_STREAM_STATS_RECEIVEDBYTES = 5;
|
||||
|
||||
const IDX_SESSION_STATS_TYPE = 0;
|
||||
const IDX_SESSION_STATS_PINGRTT = 1;
|
||||
const IDX_SESSION_STATS_FRAMESRECEIVED = 2;
|
||||
const IDX_SESSION_STATS_FRAMESSENT = 3;
|
||||
const IDX_SESSION_STATS_STREAMCOUNT = 4;
|
||||
const IDX_SESSION_STATS_STREAMAVERAGEDURATION = 5;
|
||||
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 =
|
||||
streamStats[IDX_STREAM_STATS_TIMETOFIRSTBYTE];
|
||||
entry.timeToFirstHeader =
|
||||
streamStats[IDX_STREAM_STATS_TIMETOFIRSTHEADER];
|
||||
entry.timeToFirstByteSent =
|
||||
streamStats[IDX_STREAM_STATS_TIMETOFIRSTBYTESENT];
|
||||
entry.bytesWritten =
|
||||
streamStats[IDX_STREAM_STATS_SENTBYTES];
|
||||
entry.bytesRead =
|
||||
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 =
|
||||
sessionStats[IDX_SESSION_STATS_PINGRTT];
|
||||
entry.framesReceived =
|
||||
sessionStats[IDX_SESSION_STATS_FRAMESRECEIVED];
|
||||
entry.framesSent =
|
||||
sessionStats[IDX_SESSION_STATS_FRAMESSENT];
|
||||
entry.streamCount =
|
||||
sessionStats[IDX_SESSION_STATS_STREAMCOUNT];
|
||||
entry.streamAverageDuration =
|
||||
sessionStats[IDX_SESSION_STATS_STREAMAVERAGEDURATION];
|
||||
entry.bytesWritten =
|
||||
sessionStats[IDX_SESSION_STATS_DATA_SENT];
|
||||
entry.bytesRead =
|
||||
sessionStats[IDX_SESSION_STATS_DATA_RECEIVED];
|
||||
entry.maxConcurrentStreams =
|
||||
sessionStats[IDX_SESSION_STATS_MAX_CONCURRENT_STREAMS];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
let errors;
|
||||
function lazyErrors() {
|
||||
if (errors === undefined)
|
||||
|
@ -467,6 +531,10 @@ function doNotify() {
|
|||
// Set up the callback used to receive PerformanceObserver notifications
|
||||
function observersCallback(entry) {
|
||||
const type = mapTypes(entry.entryType);
|
||||
|
||||
if (type === NODE_PERFORMANCE_ENTRY_TYPE_HTTP2)
|
||||
collectHttp2Stats(entry);
|
||||
|
||||
performance[kInsertEntry](entry);
|
||||
const list = getObserversList(type);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue