perf_hooks: precise mode for monitorEventLoopDelay#32102
perf_hooks: precise mode for monitorEventLoopDelay#32102indutny wants to merge 3 commits intonodejs:masterfrom
Conversation
Introduce precise mode of `monitorEventLoopDelay` by using `uv_prepare_t` to calculate time difference between two `uv_prepare_t` callbacks.
|
@jasnell I've added a test here to check that both modes actually capture the event loop delay. Let's see if CI is happy with it. |
|
|
||
| // Since we pass `timer_` to `HandleWrap` constructor - we have to | ||
| // initialize it here. It is equally important to have it initialized for | ||
| // correct operation of `Close()` below. |
There was a problem hiding this comment.
If you turn the above lines into
ELDHistogram::ELDHistogram(
Environment* env,
Local<Object> wrap,
int32_t resolution)
: HandleWrap(env,
wrap,
resolution > 0 ?
reinterpret_cast<uv_handle_t*>(&timer_) :
reinterpret_cast<uv_handle_t*>(&prepare_),
AsyncWrap::PROVIDER_ELDHISTOGRAM),
Histogram(1, 3.6e12),
resolution_(resolution) {
...Then you only need to initialize one handle, and don’t need the custom ::Close() override … and, going one step further, you could even save some memory and turn the timer_/prepare_ fields into e.g.
union {
uv_handle_t handle;
uv_timer_t timer;
uv_prepare_t prepare;
} handle_;|
The problem I see with this approach is that it includes I/O time. If the event loop is completely idle it's not a big deal as no measurements are done. I think this could be improved by adding the number of measurements done (Refs: #26556 (comment)) as this allows users to correlate measured delays with complete observation time. |
|
@Flarna you are right 🤦 |
Introduce precise mode of
monitorEventLoopDelayby usinguv_prepare_tto calculate time difference between twouv_prepare_tcallbacks.Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passescc @nodejs/performance
NOTE: Moved from #32018 since github didn't let me reopen the PR after force push... 😢