From 5c6ae4701e0a37eac3bb416090358223ecabdad3 Mon Sep 17 00:00:00 2001 From: Edy Date: Mon, 23 Jun 2025 18:14:45 -0300 Subject: [PATCH 1/3] add a bunch of printf functions --- src/timer.c | 4 ++++ src/unix/core.c | 10 ++++++++-- src/unix/kqueue.c | 3 +++ src/unix/loop-watcher.c | 3 +++ src/unix/loop.c | 3 +++ 5 files changed, 21 insertions(+), 2 deletions(-) diff --git a/src/timer.c b/src/timer.c index 7cfca3b1fc0..9f22a64c3e7 100644 --- a/src/timer.c +++ b/src/timer.c @@ -21,6 +21,7 @@ #include "uv.h" #include "uv-common.h" #include "heap-inl.h" +#include #include @@ -162,6 +163,7 @@ int uv__next_timeout(const uv_loop_t* loop) { void uv__run_timers(uv_loop_t* loop) { + printf("Running timers\n"); struct heap_node* heap_node; uv_timer_t* handle; struct uv__queue* queue_node; @@ -191,6 +193,8 @@ void uv__run_timers(uv_loop_t* loop) { uv_timer_again(handle); handle->timer_cb(handle); } + + printf("Timers run completed\n"); } diff --git a/src/unix/core.c b/src/unix/core.c index 1dde27bd70d..d5372473619 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -443,13 +443,14 @@ int uv_run(uv_loop_t* loop, uv_run_mode mode) { } while (r != 0 && loop->stop_flag == 0) { + printf("Loop tick\n"); can_sleep = uv__queue_empty(&loop->pending_queue) && uv__queue_empty(&loop->idle_handles); uv__run_pending(loop); - uv__run_idle(loop); - uv__run_prepare(loop); + uv__run_idle(loop); // where the fuck is this implemented? + uv__run_prepare(loop); // where the fuck is this implemented? timeout = 0; if ((mode == UV_RUN_ONCE && can_sleep) || mode == UV_RUN_DEFAULT) @@ -478,6 +479,7 @@ int uv_run(uv_loop_t* loop, uv_run_mode mode) { uv__run_timers(loop); r = uv__loop_alive(loop); + printf("Finished tick\n Is loop alive? %d\n", r); if (mode == UV_RUN_ONCE || mode == UV_RUN_NOWAIT) break; } @@ -844,6 +846,8 @@ static void uv__run_pending(uv_loop_t* loop) { struct uv__queue pq; uv__io_t* w; + printf("Running pending callbacks\n"); + uv__queue_move(&loop->pending_queue, &pq); while (!uv__queue_empty(&pq)) { @@ -853,6 +857,8 @@ static void uv__run_pending(uv_loop_t* loop) { w = uv__queue_data(q, uv__io_t, pending_queue); w->cb(loop, w, POLLOUT); } + + printf("Finished running pending callbacks\n"); } diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index 39b72012c26..fb6fabfb2e3 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -157,6 +157,7 @@ static void uv__kqueue_delete(int kqfd, const struct kevent *ev) { void uv__io_poll(uv_loop_t* loop, int timeout) { + printf("Started polling IO with timeout %d ms\n", timeout); uv__loop_internal_fields_t* lfields; struct kevent events[1024]; struct kevent* ev; @@ -473,6 +474,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { timeout -= diff; } + + printf("Finished polling IO with timeout %d ms\n", timeout); } diff --git a/src/unix/loop-watcher.c b/src/unix/loop-watcher.c index 2db8b515df7..fde4b9ee6fb 100644 --- a/src/unix/loop-watcher.c +++ b/src/unix/loop-watcher.c @@ -21,6 +21,7 @@ #include "uv.h" #include "internal.h" +#include #define UV_LOOP_WATCHER_DEFINE(name, type) \ int uv_##name##_init(uv_loop_t* loop, uv_##name##_t* handle) { \ @@ -46,6 +47,7 @@ } \ \ void uv__run_##name(uv_loop_t* loop) { \ + printf("Running %s callbacks\n", #name); \ uv_##name##_t* h; \ struct uv__queue queue; \ struct uv__queue* q; \ @@ -57,6 +59,7 @@ uv__queue_insert_tail(&loop->name##_handles, q); \ h->name##_cb(h); \ } \ + printf("Finished running %s callbacks\n", #name); \ } \ \ void uv__##name##_close(uv_##name##_t* handle) { \ diff --git a/src/unix/loop.c b/src/unix/loop.c index 5d3f0c7a348..177fdf70577 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -26,12 +26,15 @@ #include #include #include +#include int uv_loop_init(uv_loop_t* loop) { uv__loop_internal_fields_t* lfields; void* saved_data; int err; + printf("Loop starded\n"); + saved_data = loop->data; memset(loop, 0, sizeof(*loop)); loop->data = saved_data; From aba3cba91b5bc23714c6e9c7d9354e5c5574557f Mon Sep 17 00:00:00 2001 From: Edy Date: Mon, 23 Jun 2025 18:16:32 -0300 Subject: [PATCH 2/3] fix typo --- src/unix/loop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/unix/loop.c b/src/unix/loop.c index 177fdf70577..4432b1c548e 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -33,7 +33,7 @@ int uv_loop_init(uv_loop_t* loop) { void* saved_data; int err; - printf("Loop starded\n"); + printf("Loop Started\n"); saved_data = loop->data; memset(loop, 0, sizeof(*loop)); From 3102a2189e724c4c2399c25609a28439949f6e98 Mon Sep 17 00:00:00 2001 From: Edy Date: Tue, 24 Jun 2025 14:50:07 -0300 Subject: [PATCH 3/3] blah --- src/unix/core.c | 35 +++++++++++++++++++++++++++++------ src/unix/kqueue.c | 4 ++-- src/unix/loop-watcher.c | 4 ++-- src/unix/loop.c | 2 +- src/uv-common.c | 1 + 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/unix/core.c b/src/unix/core.c index d5372473619..8ad2a6ab740 100644 --- a/src/unix/core.c +++ b/src/unix/core.c @@ -423,11 +423,18 @@ int uv_loop_alive(const uv_loop_t* loop) { return uv__loop_alive(loop); } +int is_default = -1; int uv_run(uv_loop_t* loop, uv_run_mode mode) { int timeout; int r; int can_sleep; + uv_loop_t* default_loop = uv_default_loop(); + is_default = (loop == default_loop); + + if(is_default) { + printf("\nLoop started [%p]\n\n", (void*)loop); + } r = uv__loop_alive(loop); if (!r) @@ -443,14 +450,17 @@ int uv_run(uv_loop_t* loop, uv_run_mode mode) { } while (r != 0 && loop->stop_flag == 0) { - printf("Loop tick\n"); + if(is_default) { + printf("\n\tStarted tick [%p]\n\n", (void*)loop); + } + can_sleep = uv__queue_empty(&loop->pending_queue) && uv__queue_empty(&loop->idle_handles); uv__run_pending(loop); - uv__run_idle(loop); // where the fuck is this implemented? - uv__run_prepare(loop); // where the fuck is this implemented? + uv__run_idle(loop); + uv__run_prepare(loop); timeout = 0; if ((mode == UV_RUN_ONCE && can_sleep) || mode == UV_RUN_DEFAULT) @@ -479,11 +489,17 @@ int uv_run(uv_loop_t* loop, uv_run_mode mode) { uv__run_timers(loop); r = uv__loop_alive(loop); - printf("Finished tick\n Is loop alive? %d\n", r); + if (is_default) { + printf("\tFinished Tick for loop [%p]\n\n", (void*)loop); + } if (mode == UV_RUN_ONCE || mode == UV_RUN_NOWAIT) break; } + if (is_default) { + printf("\nLoop finished [%p]\n\n", (void*)loop); + } + /* The if statement lets gcc compile it to a conditional store. Avoids * dirtying a cache line. */ @@ -845,8 +861,11 @@ static void uv__run_pending(uv_loop_t* loop) { struct uv__queue* q; struct uv__queue pq; uv__io_t* w; + int count = 0; - printf("Running pending callbacks\n"); + if (is_default) { + printf("\tRunning pending callbacks for loop\n"); + } uv__queue_move(&loop->pending_queue, &pq); @@ -856,9 +875,13 @@ static void uv__run_pending(uv_loop_t* loop) { uv__queue_init(q); w = uv__queue_data(q, uv__io_t, pending_queue); w->cb(loop, w, POLLOUT); + count++; } - printf("Finished running pending callbacks\n"); + if (is_default) { + printf("Ran %d pending callbacks\n", count); + printf("Finished running pending callbacks\n"); + } } diff --git a/src/unix/kqueue.c b/src/unix/kqueue.c index fb6fabfb2e3..4b15ce0271e 100644 --- a/src/unix/kqueue.c +++ b/src/unix/kqueue.c @@ -244,6 +244,8 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { w->events = w->pevents; } + printf("Finished polling IO with timeout %d ms\n", timeout); + pset = NULL; if (loop->flags & UV_LOOP_BLOCK_SIGPROF) { pset = &set; @@ -474,8 +476,6 @@ void uv__io_poll(uv_loop_t* loop, int timeout) { timeout -= diff; } - - printf("Finished polling IO with timeout %d ms\n", timeout); } diff --git a/src/unix/loop-watcher.c b/src/unix/loop-watcher.c index fde4b9ee6fb..503a228db52 100644 --- a/src/unix/loop-watcher.c +++ b/src/unix/loop-watcher.c @@ -47,7 +47,7 @@ } \ \ void uv__run_##name(uv_loop_t* loop) { \ - printf("Running %s callbacks\n", #name); \ + printf("Started running %s callbacks for loop %p\n", #name, (void*)loop); \ uv_##name##_t* h; \ struct uv__queue queue; \ struct uv__queue* q; \ @@ -59,7 +59,7 @@ uv__queue_insert_tail(&loop->name##_handles, q); \ h->name##_cb(h); \ } \ - printf("Finished running %s callbacks\n", #name); \ + printf("Finished running %s callbacks for loop %p\n", #name, (void*)loop); \ } \ \ void uv__##name##_close(uv_##name##_t* handle) { \ diff --git a/src/unix/loop.c b/src/unix/loop.c index 4432b1c548e..de06abed134 100644 --- a/src/unix/loop.c +++ b/src/unix/loop.c @@ -33,7 +33,7 @@ int uv_loop_init(uv_loop_t* loop) { void* saved_data; int err; - printf("Loop Started\n"); + printf("Loop Initialized: %p\n", (void*)loop); saved_data = loop->data; memset(loop, 0, sizeof(*loop)); diff --git a/src/uv-common.c b/src/uv-common.c index bff9d9ee1dd..c46ce86908b 100644 --- a/src/uv-common.c +++ b/src/uv-common.c @@ -901,6 +901,7 @@ int uv_loop_close(uv_loop_t* loop) { if (loop == default_loop_ptr) default_loop_ptr = NULL; + printf("Loops %p closed.\n", (void*) loop); return 0; }