From 5729478509a11f53afe65fa1b569d920e86d1803 Mon Sep 17 00:00:00 2001 From: Gireesh Punathil Date: Mon, 2 Nov 2020 23:45:09 -0500 Subject: [PATCH] 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 Reviewed-By: Colin Ihrig Reviewed-By: Rich Trott Reviewed-By: Richard Lau --- doc/api/report.md | 3 ++- src/node_report.cc | 4 ++++ test/report/test-report-uv-handles.js | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/doc/api/report.md b/doc/api/report.md index 9ee65280a8aa41..accf3ca21044fd 100644 --- a/doc/api/report.md +++ b/doc/api/report.md @@ -292,7 +292,8 @@ is provided below for reference. { "type": "loop", "is_active": true, - "address": "0x000055fc7b2cb180" + "address": "0x000055fc7b2cb180", + "loopIdleTimeSeconds": 22644.8 } ], "workers": [], diff --git a/src/node_report.cc b/src/node_report.cc index 3b97bb705b6985..13f87b1e52e5d6 100644 --- a/src/node_report.cc +++ b/src/node_report.cc @@ -294,6 +294,10 @@ static void WriteNodeReport(Isolate* isolate, static_cast(uv_loop_alive(env->event_loop()))); writer.json_keyvalue("address", ValueToHexString(reinterpret_cast(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(); } diff --git a/test/report/test-report-uv-handles.js b/test/report/test-report-uv-handles.js index 3a6a34a8573fe7..d2dd630c46d25f 100644 --- a/test/report/test-report-uv-handles.js +++ b/test/report/test-report-uv-handles.js @@ -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); }),