libuv/src/unix
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
..
aix-common.c ibmi: implement uv_interface_addresses() 2020-01-21 09:32:11 +01:00
aix.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
android-ifaddrs.c android: fix OOB write in uv_interface_addresses() 2020-04-06 12:48:32 +02:00
async.c unix: yield cpu when spinlocking on async handle 2020-04-22 12:28:13 +02:00
atomic-ops.h unix: implement cpu_relax() for arm 2020-04-14 15:30:30 +02:00
bsd-ifaddrs.c build: fix build warning on cygwin 2019-10-04 23:54:06 +02:00
bsd-proctitle.c unix,win: add uv_library_shutdown() 2020-04-22 12:24:36 +02:00
core.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
cygwin.c src: move uv_free_cpu_info to uv-common.c 2019-08-19 23:01:17 +02:00
darwin-proctitle.c darwin: fix build with non-apple compilers 2020-04-28 20:07:59 +02:00
darwin-stub.h darwin: fix build with non-apple compilers 2020-04-28 20:07:59 +02:00
darwin.c darwin: work around clock jumping back in time 2020-07-01 10:34:21 +02:00
dl.c
freebsd.c freebsd,linux: add recvmmsg() + sendmmsg() udp implementation 2020-02-20 11:52:54 +01:00
fs.c linux: use copy_file_range for uv_fs_copyfile when possible 2020-07-28 11:58:04 -04:00
fsevents.c darwin: fix build with non-apple compilers 2020-04-28 20:07:59 +02:00
getaddrinfo.c test,sunos: fix statement not reached warnings 2019-03-16 13:22:16 -04:00
getnameinfo.c unix,win: limit concurrent DNS calls to nthreads/2 2018-08-21 10:48:24 +02:00
haiku.c src: move uv_free_cpu_info to uv-common.c 2019-08-19 23:01:17 +02:00
ibmi.c ibmi: set the amount of memory in use to zero 2020-03-10 11:00:03 +01:00
internal.h unix,win: add uv_library_shutdown() 2020-04-22 12:24:36 +02:00
kqueue.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
linux-core.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
linux-inotify.c linux: assume the presence of inotify system calls 2020-02-04 16:36:59 +01:00
linux-syscalls.c linux: use copy_file_range for uv_fs_copyfile when possible 2020-07-28 11:58:04 -04:00
linux-syscalls.h linux: use copy_file_range for uv_fs_copyfile when possible 2020-07-28 11:58:04 -04:00
loop-watcher.c
loop.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
netbsd.c unix: pass sysctl size arg using ARRAY_SIZE macro 2019-12-16 15:55:59 +01:00
no-fsevents.c
no-proctitle.c unix,win: add uv_library_shutdown() 2020-04-22 12:24:36 +02:00
openbsd.c src: add uv__reallocf() 2020-03-15 10:00:15 -04:00
os390-syscalls.c unix: use relaxed loads/stores for feature checks 2020-06-16 11:42:51 +02:00
os390-syscalls.h zos: fix non-Release builds 2020-03-24 09:33:47 -04:00
os390.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
pipe.c pipe: disallow listening on an IPC pipe 2020-01-31 11:09:16 +01:00
poll.c unix: catch some cases of watching fd twice 2018-05-30 13:24:19 +02:00
posix-hrtime.c
posix-poll.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
process.c unix: fix error handling in uv__make_pipe() 2020-02-04 16:36:59 +01:00
procfs-exepath.c
proctitle.c unix,win: add uv_library_shutdown() 2020-04-22 12:24:36 +02:00
pthread-fixes.c unix: use relaxed loads/stores for feature checks 2020-06-16 11:42:51 +02:00
random-devurandom.c unix: handle uv__open_cloexec return value correctly 2020-01-21 20:02:56 +01:00
random-getentropy.c unix,win: add uv_random() 2019-09-18 08:09:14 +02:00
random-getrandom.c unix,win: add uv_random() 2019-09-18 08:09:14 +02:00
random-sysctl-linux.c netbsd: use KERN_ARND sysctl to get entropy 2019-10-29 13:36:05 +01:00
signal.c unix: squelch harmless valgrind warning 2020-07-20 11:42:48 +02:00
spinlock.h
stream.c unix,stream: clear read/write states on close/eof 2020-07-28 09:05:05 -04:00
sunos.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
sysinfo-loadavg.c
sysinfo-memory.c
tcp.c unix: use relaxed loads/stores for feature checks 2020-06-16 11:42:51 +02:00
thread.c android: remove patch code for below 21 2020-06-12 12:22:06 +02:00
tty.c ibmi: Fix isatty EBADF handling and refactor 2020-04-06 05:58:34 -04:00
udp.c udp: add uv_udp_using_recvmmsg query 2020-07-28 23:28:18 -04:00