libuv/docs/src
Trevor Norris e8effd4556 core: add API to measure event loop idle time
The API addition `uv_metrics_idle_time()` is a thread safe call that
allows the user to retrieve the amount of time the event loop has spent
in the kernel's event provider (i.e. poll). It was done this way to
allow retrieving this value without needing to interrupt the execution
of the event loop. This option can be enabled by passing
`UV_METRICS_IDLE_TIME` to `uv_loop_configure()`.

One important aspect of this change is, when enabled, to always first
call the event provider with a `timeout == 0`. This allows libuv to know
whether any events were waiting in the event queue when the event
provider was called. The importance of this is because libuv is tracking
the amount of "idle time", not "poll time". Thus the provider entry time
is not recorded when `timeout == 0` (the event provider never idles in
this case).

While this does add a small amount of overhead, when enabled, but the
overhead decreases when the event loop has a heavier load. This is
because poll events will be waiting when the event provider is called.
Thus never actually recording the provider entry time.

Checking if `uv_loop_t` is configured with `UV_METRICS_IDLE_TIME` always
happens in `uv__metrics_set_provider_entry_time()` and
`uv__metrics_update_idle_time()`. Making the conditional logic wrapping
each call simpler and allows for instrumentation to always hook into
those two function calls.

Rather than placing the fields directly on `uv__loop_internal_fields_t`
add the struct `uv__loop_metrics_t` as a location for future metrics API
additions.

Tests and additional documentation has been included.

PR-URL: https://github.com/libuv/libuv/pull/2725
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Jameson Nash <vtjnash@gmail.com>
2020-08-04 10:31:42 -04:00
..
guide doc: correct source lines 2020-04-22 12:40:32 +02:00
sphinx-plugins docs: switch from linux.die.net to man7.org 2020-01-08 11:52:02 -05:00
static doc: strip ICC profile from 2 jpg files 2020-02-07 22:08:04 +01:00
api.rst core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
async.rst doc: mark uv_async_send() as async-signal-safe 2019-04-23 10:46:56 +02:00
check.rst doc: check/idle/prepare functions always succeed 2020-04-28 20:06:55 +02:00
conf.py core: move all include files except uv.h to uv/ 2018-06-14 18:39:32 +02:00
design.rst docs: fix linkcheck 2020-01-08 11:51:04 -05:00
dll.rst doc: add uv_dlsym() return type 2015-09-02 09:58:55 +02:00
dns.rst doc: document uv_getnameinfo_t.{host|service} 2015-03-02 16:53:57 +01:00
errors.rst doc: add more error constants 2020-07-31 14:29:54 -04:00
fs_event.rst docs: fix linkcheck 2020-01-08 11:51:04 -05:00
fs_poll.rst docs: improve UV_ENOBUFS scenario documentation 2017-03-08 20:55:40 -05:00
fs.rst fs: report original error 2020-04-29 13:14:57 +02:00
guide.rst doc: add warning note to user guide 2017-04-28 11:15:53 +02:00
handle.rst doc: improve uv_{send,recv}_buffer_size() docs 2019-10-14 21:22:57 -04:00
idle.rst doc: check/idle/prepare functions always succeed 2020-04-28 20:06:55 +02:00
index.rst docs: fix linkcheck 2020-01-08 11:51:04 -05:00
loop.rst core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
metrics.rst core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
migration_010_100.rst doc: fix spelling 2014-11-29 04:22:56 +01:00
misc.rst docs: improve the descriptions for get memory info 2020-07-28 17:10:34 -04:00
pipe.rst pipe: disallow listening on an IPC pipe 2020-01-31 11:09:16 +01:00
poll.rst poll: add support for OOB TCP and GPIO interrupts 2017-07-12 23:04:34 +02:00
prepare.rst doc: check/idle/prepare functions always succeed 2020-04-28 20:06:55 +02:00
process.rst win: support more fine-grained windows hiding 2018-11-10 14:43:23 -05:00
request.rst doc: uv_cancel() handles uv_random_t requests 2020-04-22 12:44:12 +02:00
signal.rst win, tty: improve SIGWINCH performance 2019-09-05 11:36:02 +02:00
stream.rst doc: clarify uv_buf_t usage in uv_alloc_cb 2019-08-23 20:27:48 +02:00
tcp.rst unix: make uv_tcp_keepalive predictable 2020-02-07 22:52:45 +01:00
threading.rst doc: fix typo in uv_thread_options_t definition 2019-03-16 11:37:00 -04:00
threadpool.rst doc: fix incorrect versionchanged 2019-06-27 13:20:14 -04:00
timer.rst doc: document uv_timer_start() on an active timer 2018-02-21 09:07:05 -05:00
tty.rst win,tty: add uv_tty_{get,set}_vterm_state 2019-10-09 09:36:36 +02:00
udp.rst udp: add uv_udp_using_recvmmsg query 2020-07-28 23:28:18 -04:00
upgrading.rst doc: move "upgrading" to a standalone document 2017-04-28 11:15:04 +02:00
version.rst docs: fix linkcheck 2020-01-08 11:51:04 -05:00