misc: expose handle print APIs

PR-URL: https://github.com/libuv/libuv/pull/291
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
This commit is contained in:
Petka Antonov 2015-11-16 10:22:00 +02:00 committed by Saúl Ibarra Corretgé
parent baf700acdb
commit 6490c508a9
3 changed files with 48 additions and 8 deletions

View File

@ -288,3 +288,41 @@ API
.. note::
Not every platform can support nanosecond resolution; however, this value will always
be in nanoseconds.
.. c:function:: void uv_print_all_handles(uv_loop_t* loop, FILE* stream)
Prints all handles associated with the given `loop` to the given `stream`.
Example:
::
uv_print_all_handles(uv_default_loop(), stderr);
/*
[--I] signal 0x1a25ea8
[-AI] async 0x1a25cf0
[R--] idle 0x1a7a8c8
*/
The format is `[flags] handle-type handle-address`. For `flags`:
- `R` is printed for a handle that is referenced
- `A` is printed for a handle that is active
- `I` is printed for a handle that is internal
.. warning::
This function is meant for ad hoc debugging, there is no API/ABI
stability guarantees.
.. versionadded:: 1.8.0
.. c:function:: void uv_print_active_handles(uv_loop_t* loop, FILE* stream)
This is the same as :c:func:`uv_print_all_handles` except only active handles
are printed.
.. warning::
This function is meant for ad hoc debugging, there is no API/ABI
stability guarantees.
.. versionadded:: 1.8.0

View File

@ -424,6 +424,10 @@ UV_EXTERN int uv_is_active(const uv_handle_t* handle);
UV_EXTERN void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg);
/* Helpers for ad hoc debugging, no API/ABI stability guaranteed. */
UV_EXTERN void uv_print_all_handles(uv_loop_t* loop, FILE* stream);
UV_EXTERN void uv_print_active_handles(uv_loop_t* loop, FILE* stream);
UV_EXTERN void uv_close(uv_handle_t* handle, uv_close_cb close_cb);
UV_EXTERN int uv_send_buffer_size(uv_handle_t* handle, int* value);

View File

@ -355,8 +355,7 @@ void uv_walk(uv_loop_t* loop, uv_walk_cb walk_cb, void* arg) {
}
#ifndef NDEBUG
static void uv__print_handles(uv_loop_t* loop, int only_active) {
static void uv__print_handles(uv_loop_t* loop, int only_active, FILE* stream) {
const char* type;
QUEUE* q;
uv_handle_t* h;
@ -377,7 +376,7 @@ static void uv__print_handles(uv_loop_t* loop, int only_active) {
default: type = "<unknown>";
}
fprintf(stderr,
fprintf(stream,
"[%c%c%c] %-8s %p\n",
"R-"[!(h->flags & UV__HANDLE_REF)],
"A-"[!(h->flags & UV__HANDLE_ACTIVE)],
@ -388,15 +387,14 @@ static void uv__print_handles(uv_loop_t* loop, int only_active) {
}
void uv_print_all_handles(uv_loop_t* loop) {
uv__print_handles(loop, 0);
void uv_print_all_handles(uv_loop_t* loop, FILE* stream) {
uv__print_handles(loop, 0, stream);
}
void uv_print_active_handles(uv_loop_t* loop) {
uv__print_handles(loop, 1);
void uv_print_active_handles(uv_loop_t* loop, FILE* stream) {
uv__print_handles(loop, 1, stream);
}
#endif
void uv_ref(uv_handle_t* handle) {