Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: add loop idle time in diagnostic report #35940

Merged
merged 1 commit into from
Nov 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ is provided below for reference.
{
"type": "loop",
"is_active": true,
"address": "0x000055fc7b2cb180"
"address": "0x000055fc7b2cb180",
"loopIdleTimeSeconds": 22644.8
}
],
"workers": [],
Expand Down
4 changes: 4 additions & 0 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is idle_time in nanoseconds? I thought @trevnorris said it was milliseconds in #35940 (comment).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The libuv code uses uv_hrtime() without any additional scaling, so, yes, nanoseconds.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

node/src/node_perf.cc

Lines 446 to 447 in 589b2a1

uint64_t idle_time = uv_metrics_idle_time(env->event_loop());
args.GetReturnValue().Set(1.0 * idle_time / 1e6);

this may make it very clear - the nanoseconds that comes is converted to millis if accessed through API.

Copy link
Contributor

@cjihrig cjihrig Nov 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I was just confused by #35940 (comment). Thanks Anna and Gireesh.

writer.json_end();
}

Expand Down
3 changes: 3 additions & 0 deletions test/report/test-report-uv-handles.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}),
Expand Down