]> mj.ucw.cz Git - libucw.git/commitdiff
UCW mainloop: Accumulate the total time spent in poll() into main_idle_time.
authorPavel Charvat <pchar@ucw.cz>
Thu, 29 Jan 2009 12:53:02 +0000 (13:53 +0100)
committerPavel Charvat <pchar@ucw.cz>
Thu, 29 Jan 2009 12:53:02 +0000 (13:53 +0100)
ucw/mainloop.c
ucw/mainloop.h

index fc5beff7cabeaa8a55cf3be64924aca2b6960498..9a39abd7d3338ae11720298ba5e1d9d43c2dbb30 100644 (file)
@@ -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))
index 5bd042091a07bf95d929aab4a2fae7f2fcbbb495..b6aea61dfb3412f98f38ee03ed04556bdc3edf7f 100644 (file)
@@ -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;
 
 /**