src: add loop idle time in diagnostic report

Add libuv's cumulative idle time in the diagnostic report.
Add the data under the libuv's loop section

Refs: https://github.com/nodejs/node/pull/34938
PR-URL: https://github.com/nodejs/node/pull/35940
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
This commit is contained in:
Gireesh Punathil
2020-11-02 23:45:09 -05:00
parent f03f7cbd35
commit 74bd866d94
3 changed files with 9 additions and 1 deletions

View File

@@ -292,7 +292,8 @@ is provided below for reference.
{
"type": "loop",
"is_active": true,
"address": "0x000055fc7b2cb180"
"address": "0x000055fc7b2cb180",
"loopIdleTimeSeconds": 22644.8
}
],
"workers": [],

View File

@@ -294,6 +294,10 @@ static void WriteNodeReport(Isolate* isolate,
static_cast<bool>(uv_loop_alive(env->event_loop())));
writer.json_keyvalue("address",
ValueToHexString(reinterpret_cast<int64_t>(env->event_loop())));
// Report Event loop idle time
uint64_t idle_time = uv_metrics_idle_time(env->event_loop());
writer.json_keyvalue("loopIdleTimeSeconds", 1.0 * idle_time / 1e9);
writer.json_end();
}

View File

@@ -128,6 +128,9 @@ if (process.argv[2] === 'child') {
assert.strictEqual(handle.filename, expected_filename);
assert(handle.is_referenced);
}),
loop: common.mustCall(function loop_validator(handle) {
assert.strictEqual(typeof handle.loopIdleTimeSeconds, 'number');
}),
pipe: common.mustCallAtLeast(function pipe_validator(handle) {
assert(handle.is_referenced);
}),