Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
unix, windows: add debug mode handle printer
Browse files Browse the repository at this point in the history
Debugging tool, prints a list of active/all handles. Not actively exported.
  • Loading branch information
bnoordhuis committed Jun 6, 2012
1 parent 24f8a53 commit 6fe7530
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/uv-common.c
Expand Up @@ -22,6 +22,7 @@
#include "uv.h"
#include "uv-common.h"

#include <stdio.h>
#include <assert.h>
#include <stddef.h> /* NULL */
#include <stdlib.h> /* malloc */
Expand Down Expand Up @@ -329,6 +330,50 @@ 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) {
const char* type;
ngx_queue_t* q;
uv_handle_t* h;

if (loop == NULL)
loop = uv_default_loop();

ngx_queue_foreach(q, &loop->handle_queue) {
h = ngx_queue_data(q, uv_handle_t, handle_queue);

if (only_active && !uv__is_active(h))
continue;

switch (h->type) {
#define X(uc, lc) case UV_##uc: type = #lc; break;
UV_HANDLE_TYPE_MAP(X)
#undef X
default: type = "<unknown>";
}

fprintf(stderr,
"[%c%c%c] %-8s %p\n",
"R-"[!(h->flags & UV__HANDLE_REF)],
"A-"[!(h->flags & UV__HANDLE_ACTIVE)],
"I-"[!(h->flags & UV__HANDLE_INTERNAL)],
type,
(void*)h);
}
}


void uv_print_all_handles(uv_loop_t* loop) {
uv__print_handles(loop, 0);
}


void uv_print_active_handles(uv_loop_t* loop) {
uv__print_handles(loop, 1);
}
#endif


void uv_ref(uv_handle_t* handle) {
uv__handle_ref(handle);
}
Expand Down

0 comments on commit 6fe7530

Please sign in to comment.