From d4f83a6243188542814dc49726c9bbfa14d273a8 Mon Sep 17 00:00:00 2001 From: Pavel Charvat Date: Thu, 29 Jan 2009 13:53:02 +0100 Subject: [PATCH] UCW mainloop: Accumulate the total time spent in poll() into main_idle_time. --- ucw/mainloop.c | 11 ++++++++--- ucw/mainloop.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ucw/mainloop.c b/ucw/mainloop.c index fc5beff7..9a39abd7 100644 --- a/ucw/mainloop.c +++ b/ucw/mainloop.c @@ -25,6 +25,7 @@ timestamp_t main_now; ucw_time_t main_now_seconds; +timestamp_t main_idle_time; uns main_shutdown; clist main_timer_list, main_file_list, main_hook_list, main_process_list; @@ -366,9 +367,9 @@ main_loop(void) struct main_process *pr; cnode *tmp; + main_get_time(); for (;;) { - main_get_time(); timestamp_t wake = main_now + 1000000000; while ((tm = clist_head(&main_timer_list)) && tm->expires <= main_now) { @@ -419,12 +420,16 @@ main_loop(void) /* FIXME: Here is a small race window where SIGCHLD can come unnoticed. */ if ((tm = clist_head(&main_timer_list)) && tm->expires < wake) wake = tm->expires; + main_get_time(); int timeout = (wake ? wake - main_now : 0); DBG("MAIN: Poll for %d fds and timeout %d ms", main_file_cnt, timeout); - if (poll(main_poll_table, main_file_cnt, timeout)) + int p = poll(main_poll_table, main_file_cnt, timeout); + timestamp_t old_now = main_now; + main_get_time(); + main_idle_time += main_now - old_now; + if (p > 0) { struct pollfd *p = main_poll_table; - main_get_time(); CLIST_WALK(fi, main_file_list) { if (p->revents & (POLLIN | POLLHUP | POLLERR)) diff --git a/ucw/mainloop.h b/ucw/mainloop.h index 5bd04209..b6aea61d 100644 --- a/ucw/mainloop.h +++ b/ucw/mainloop.h @@ -34,6 +34,7 @@ extern timestamp_t main_now; /** Current time in milliseconds since the UNIX epoch. See @main_get_time(). **/ extern ucw_time_t main_now_seconds; /** Current time in seconds since the epoch. **/ +extern timestamp_t main_idle_time; /** Total time in milliseconds spent in the poll() call. **/ extern clist main_timer_list, main_file_list, main_hook_list, main_process_list; /** -- 2.39.2