libuv/test
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
..
fixtures unix: make uv_fs_read() fill all buffers 2019-06-20 12:06:31 +02:00
benchmark-async-pummel.c src,lib: fix comments 2018-05-22 16:34:33 -04:00
benchmark-async.c
benchmark-fs-stat.c
benchmark-getaddrinfo.c
benchmark-list.h test: added udp ping benchmark (1,10,100 pingers) 2020-02-20 11:52:18 +01:00
benchmark-loop-count.c
benchmark-million-async.c
benchmark-million-timers.c
benchmark-multi-accept.c pipe: disallow listening on an IPC pipe 2020-01-31 11:09:16 +01:00
benchmark-ping-pongs.c
benchmark-ping-udp.c test: added udp ping benchmark (1,10,100 pingers) 2020-02-20 11:52:18 +01:00
benchmark-pound.c
benchmark-pump.c test: fix -Wstrict-prototypes warnings 2017-10-05 22:26:55 +02:00
benchmark-sizes.c
benchmark-spawn.c
benchmark-tcp-write-batch.c
benchmark-thread.c
benchmark-udp-pummel.c
blackhole-server.c
dns-server.c
echo-server.c unix,stream: clear read/write states on close/eof 2020-07-28 09:05:05 -04:00
run-benchmarks.c test: simplify platform_init() 2020-03-27 23:51:32 +01:00
run-tests.c test: simplify platform_init() 2020-03-27 23:51:32 +01:00
runner-unix.c test: simplify platform_init() 2020-03-27 23:51:32 +01:00
runner-unix.h
runner-win.c test: simplify platform_init() 2020-03-27 23:51:32 +01:00
runner-win.h warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
runner.c test: add UV_TIMEOUT_MULTIPLIER environment var 2020-02-28 13:50:28 -05:00
runner.h test: simplify platform_init() 2020-03-27 23:51:32 +01:00
task.h unix,win: add uv_library_shutdown() 2020-04-22 12:24:36 +02:00
test-active.c
test-async-null-cb.c sunos: fix cmpxchgi and cmpxchgl type error 2017-07-01 00:24:42 +02:00
test-async.c
test-barrier.c test: add uv_barrier_wait serial thread test 2018-10-08 11:14:41 +02:00
test-callback-order.c
test-callback-stack.c src,test: fix idiosyncratic comment style 2018-05-29 11:56:49 -07:00
test-close-fd.c warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
test-close-order.c
test-condvar.c warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
test-connect-unspecified.c test: fix connect_unspecified 2018-03-08 11:37:00 +01:00
test-connection-fail.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-cwd-and-chdir.c test: canonicalize argv[0] in exepath test 2020-03-27 23:51:22 +01:00
test-default-loop-close.c
test-delayed-accept.c src,test: fix idiosyncratic comment style 2018-05-29 11:56:49 -07:00
test-dlerror.c test: fix test failure under NetBSD and OpenBSD 2019-12-16 15:31:02 +01:00
test-eintr-handling.c Revert "unix,fs: fix for potential partial reads/writes" 2018-01-19 17:51:08 +01:00
test-embed.c
test-emfile.c warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
test-env-vars.c win: support environment variables > 32767 chars 2020-04-28 20:11:12 +02:00
test-error.c src: add new error apis to prevent memory leaks 2018-07-06 19:35:21 +02:00
test-fail-always.c
test-fork.c warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
test-fs-copyfile.c ibmi: skip unsupported fs test cases 2020-01-26 17:51:49 +01:00
test-fs-event.c test: fix fs_event_watch_dir_recursive flakiness 2020-01-27 22:36:25 +01:00
test-fs-fd-hash.c win: add UV_FS_O_FILEMAP 2019-07-16 18:20:10 +02:00
test-fs-open-flags.c win: add UV_FS_O_FILEMAP 2019-07-16 18:20:10 +02:00
test-fs-poll.c unix,win: fix uv_fs_poll_stop() when active 2019-05-06 15:02:01 +02:00
test-fs-readdir.c test: fix order of operations in test 2019-10-06 16:07:01 +02:00
test-fs.c test: support common user profile on IBMi 2020-05-17 09:41:55 -04:00
test-get-currentexe.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-get-loadavg.c
test-get-memory.c ibmi: set the amount of memory in use to zero 2020-03-10 11:00:03 +01:00
test-get-passwd.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-getaddrinfo.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-gethostname.c test: pass test when hostname is single character 2020-04-06 12:57:32 +02:00
test-getnameinfo.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-getsockname.c
test-getters-setters.c core: add getter/setter functions for easier ABI compat 2017-12-02 09:51:25 +01:00
test-gettimeofday.c unix,win: introduce uv_timeval64_t 2019-04-11 14:08:17 -04:00
test-handle-fileno.c stream: autodetect direction 2018-09-19 18:19:28 +02:00
test-homedir.c test: canonicalize argv[0] in exepath test 2020-03-27 23:51:22 +01:00
test-hrtime.c test: relax uv_hrtime() test assumptions 2019-02-21 13:02:44 +01:00
test-idle.c
test-idna.c unix,win: support IDNA 2008 in uv_getaddrinfo() 2018-10-30 20:50:23 +01:00
test-ip4-addr.c unix: set sin_len and sin6_len 2019-10-04 23:58:18 +02:00
test-ip6-addr.c unix: set sin_len and sin6_len 2019-10-04 23:58:18 +02:00
test-ipc-heavy-traffic-deadlock-bug.c test: fix test-ipc tests 2019-01-15 09:49:33 +01:00
test-ipc-send-recv.c unix: don't send handle twice on partial write 2018-12-30 20:13:48 +01:00
test-ipc.c test: add a bunch of ASSERT macros 2020-03-27 14:51:49 +01:00
test-list.h core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
test-loop-alive.c
test-loop-close.c test: add threadpool init/teardown test 2017-12-06 23:47:38 +01:00
test-loop-configure.c
test-loop-handles.c test: remove call to floor() in test driver 2019-03-16 13:22:56 -04:00
test-loop-stop.c
test-loop-time.c
test-metrics.c core: add API to measure event loop idle time 2020-08-04 10:31:42 -04:00
test-multiple-listen.c
test-mutexes.c unix,win: add uv_mutex_init_recursive() 2017-10-02 10:01:09 -04:00
test-not-readable-nor-writable-on-read-error.c unix,stream: clear read/write states on close/eof 2020-07-28 09:05:05 -04:00
test-not-readable-on-eof.c unix,stream: clear read/write states on close/eof 2020-07-28 09:05:05 -04:00
test-not-writable-after-shutdown.c unix,stream: clear read/write states on close/eof 2020-07-28 09:05:05 -04:00
test-osx-select.c
test-pass-always.c
test-ping-pong.c test: add vectored uv_write() ping-pong tests 2018-05-29 13:01:23 -07:00
test-pipe-bind-error.c test: skip self-connecting tests on cygwin 2017-05-21 16:12:30 +02:00
test-pipe-close-stdout-read-stdin.c warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
test-pipe-connect-error.c
test-pipe-connect-multiple.c test: skip self-connecting tests on cygwin 2017-05-21 16:12:30 +02:00
test-pipe-connect-prepare.c
test-pipe-getsockname.c test: avoid AF_LOCAL 2019-08-01 22:16:31 +02:00
test-pipe-pending-instances.c
test-pipe-sendmsg.c cygwin: disable non-functional ipc handle send 2017-05-21 16:12:28 +02:00
test-pipe-server-close.c test: skip self-connecting tests on cygwin 2017-05-21 16:12:30 +02:00
test-pipe-set-fchmod.c src,test: fix idiosyncratic comment style 2018-05-29 11:56:49 -07:00
test-pipe-set-non-blocking.c
test-platform-output.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-poll-close-doesnt-corrupt-stack.c test: fix -fno-common build errors 2020-01-10 11:09:04 -05:00
test-poll-close.c
test-poll-closesocket.c test: fix -fno-common build errors 2020-01-10 11:09:04 -05:00
test-poll-oob.c warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
test-poll.c test: skip poll_duplex and poll_unidirectional on PASE 2020-04-20 09:45:26 -04:00
test-process-priority.c test: handle uv_os_setpriority() windows edge case 2018-09-25 20:56:37 -04:00
test-process-title-threadsafe.c test: canonicalize argv[0] in exepath test 2020-03-27 23:51:22 +01:00
test-process-title.c unix: fix size check in uv_get_process_title() 2020-02-08 12:28:34 +01:00
test-queue-foreach-delete.c test: fix gcc 8 warnings for tests 2019-08-06 12:01:15 -04:00
test-random.c unix,win: add uv_random() 2019-09-18 08:09:14 +02:00
test-ref.c
test-run-nowait.c
test-run-once.c
test-semaphore.c
test-shutdown-close.c
test-shutdown-eof.c
test-shutdown-twice.c
test-signal-multiple-loops.c test: skip signal_multiple_loops test on QEMU 2020-06-02 10:35:17 -04:00
test-signal-pending-on-close.c unix: fix signal handle closing deferral 2020-03-10 10:58:29 +01:00
test-signal.c win, process: uv_kill improvements 2017-12-07 14:00:05 +01:00
test-socket-buffer-size.c
test-spawn.c test: support common user profile on IBMi 2020-05-17 09:41:55 -04:00
test-stdio-over-pipes.c win,pipe: ensure req->event_handle is defined 2020-02-27 09:12:52 +01:00
test-strscpy.c unix: harden string copying, introduce strscpy() 2018-12-04 17:08:09 +01:00
test-tcp-alloc-cb-fail.c
test-tcp-bind6-error.c
test-tcp-bind-error.c tcp: add uv_tcp_close_reset method 2019-08-19 23:41:15 +02:00
test-tcp-close-accept.c warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
test-tcp-close-reset.c test: fix -Wsign-compare warning 2019-09-06 22:48:06 +02:00
test-tcp-close-while-connecting.c
test-tcp-close.c
test-tcp-connect6-error.c
test-tcp-connect-error-after-write.c
test-tcp-connect-error.c
test-tcp-connect-timeout.c
test-tcp-create-socket-early.c cygwin: implement support for cygwin and msys2 2017-05-21 16:12:21 +02:00
test-tcp-flags.c
test-tcp-oob.c warnings: fix code that emits compiler warnings 2018-11-29 11:21:44 -05:00
test-tcp-open.c test: fix warning in test-tcp-open 2018-08-16 10:28:49 +02:00
test-tcp-read-stop-start.c win,tcp: avoid reinserting a pending request (#2688) 2020-07-28 13:59:08 -04:00
test-tcp-read-stop.c
test-tcp-shutdown-after-write.c
test-tcp-try-write-error.c test: allow UV_ECONNRESET in tcp_try_write_error 2019-06-27 17:23:53 -04:00
test-tcp-try-write.c
test-tcp-unexpected-read.c
test-tcp-write-after-connect.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-tcp-write-fail.c
test-tcp-write-queue-order.c test: increase connection timeout to 1 second 2018-03-31 17:05:26 -04:00
test-tcp-write-to-half-open-connection.c
test-tcp-writealot.c
test-thread-equal.c
test-thread.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-threadpool-cancel.c unix,win: add uv_random() 2019-09-18 08:09:14 +02:00
test-threadpool.c
test-timer-again.c src,test: fix idiosyncratic comment style 2018-05-29 11:56:49 -07:00
test-timer-from-check.c
test-timer.c timer: fix uv_timer_start on closing timer 2019-08-23 20:42:37 +02:00
test-tmpdir.c test: canonicalize argv[0] in exepath test 2020-03-27 23:51:22 +01:00
test-tty-duplicate-key.c win: fix duplicate tty vt100 fn key 2019-02-10 10:04:18 -05:00
test-tty-escape-sequence-processing.c win,tty: Added set cursor style to CSI sequences 2020-02-29 14:11:36 +09:00
test-tty.c test: Test EBADF tty handling 2020-04-06 05:58:54 -04:00
test-udp-alloc-cb-fail.c src,test: fix idiosyncratic comment style 2018-05-29 11:56:49 -07:00
test-udp-bind.c
test-udp-connect.c test: skip some UDP tests on IBMi 2020-02-28 11:51:36 +01:00
test-udp-create-socket-early.c cygwin: implement support for cygwin and msys2 2017-05-21 16:12:21 +02:00
test-udp-dgram-too-big.c
test-udp-ipv6.c test,udp6: fix udp_ipv6 test flakiness 2020-01-27 14:58:56 -05:00
test-udp-mmsg.c udp: add uv_udp_using_recvmmsg query 2020-07-28 23:28:18 -04:00
test-udp-multicast-interface6.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-udp-multicast-interface.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-udp-multicast-join6.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-udp-multicast-join.c test: fix test failure under NetBSD and OpenBSD 2019-12-16 15:31:02 +01:00
test-udp-multicast-ttl.c test: allow multicast not permitted status 2018-01-09 14:32:35 +01:00
test-udp-open.c unix: support sockaddr_un in uv_udp_send() 2019-04-11 11:04:43 -04:00
test-udp-options.c build: test on more platforms via QEMU in CI 2020-05-17 10:03:20 -04:00
test-udp-send-and-recv.c src,test: fix idiosyncratic comment style 2018-05-29 11:56:49 -07:00
test-udp-send-hang-loop.c test: allow net unreachable status in udp test 2018-01-09 15:09:46 +01:00
test-udp-send-immediate.c src,test: fix idiosyncratic comment style 2018-05-29 11:56:49 -07:00
test-udp-send-unreachable.c
test-udp-sendmmsg-error.c udp: fix write_queue cleanup on sendmmsg error 2020-07-02 21:29:42 +02:00
test-udp-try-send.c win,udp: implements uv_udp_try_send 2017-07-01 17:20:15 +02:00
test-uname.c unix,win: add uv_os_uname() 2019-01-14 10:47:20 -05:00
test-walk-handles.c
test-watcher-cross-stop.c test: skip some UDP tests on IBMi 2020-02-28 11:51:36 +01:00