[haiku-commits] haiku: hrev44130 - src/bin

  • From: stpere@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 9 May 2012 03:09:48 +0200 (CEST)

hrev44130 adds 1 changeset to branch 'master'
old head: f5b83627d0c61d160f7c87d7b29f50eee929238b
new head: f1e0212d7241571a61d942cc63611c8e6530b54b

----------------------------------------------------------------------------

f1e0212: top: Attempt to avoid negative "(unknown)" %
  
  Top was using the 'theorical' interval value to determine the percentages.
  The measured thread times were taken in an always a bit larger interval than
  that theorical value, hence the negative '%' occuring regularly.
  
  Should fix #4589.

                                [ Philippe Saint-Pierre <stpere@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev44130
Commit:      f1e0212d7241571a61d942cc63611c8e6530b54b
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f1e0212
Author:      Philippe Saint-Pierre <stpere@xxxxxxxxx>
Date:        Wed May  9 01:05:41 2012 UTC

Ticket:      https://dev.haiku-os.org/ticket/4589

----------------------------------------------------------------------------

1 file changed, 24 insertions(+), 23 deletions(-)
src/bin/top.c |   47 ++++++++++++++++++++++++-----------------------

----------------------------------------------------------------------------

diff --git a/src/bin/top.c b/src/bin/top.c
index 090bf17..ad92f05 100644
--- a/src/bin/top.c
+++ b/src/bin/top.c
@@ -20,6 +20,7 @@
 #include <termios.h>
 
 static const char IDLE_NAME[] = "idle thread ";
+static bigtime_t lastMeasure = 0;
 
 /*
  * Keeps track of a single thread's times 
@@ -243,8 +244,7 @@ compare(
        utotal = 0;
        for (i = 0; i < times.nthreads; i++) {
                ignore = 0;
-               if (get_thread_info(times.thread_times[i].thid,
-                                                       &t) < B_NO_ERROR) {
+               if (get_thread_info(times.thread_times[i].thid, &t) < 
B_NO_ERROR) {
                        strcpy(t.name, "(unknown)");
                        strcpy(tm.args, "(unknown)");
                } else {
@@ -286,10 +286,10 @@ compare(
        }
        free_times(&times);
        printf("------ %7.2f %7.2f %7.2f %4.1f%% TOTAL (%4.1f%% idle time, 
%4.1f%% unknown)", 
-                  (double)(gtotal / 1000), 
+                  (double) (gtotal / 1000),
                   (double) (utotal / 1000),
                   (double) (ktotal / 1000),
-                  cpu_perc(gtotal, uinterval), 
+                  cpu_perc(gtotal, uinterval),
                   cpu_perc(idletime, uinterval),
                   cpu_perc(cpus * uinterval - (gtotal + idletime), uinterval));
        fflush(stdout);
@@ -339,7 +339,6 @@ static thread_time_list_t
 gather(
           thread_time_list_t *old,
           bigtime_t *busy_wait_time,
-          bigtime_t uinterval,
           int refresh
           )
 {
@@ -351,10 +350,18 @@ gather(
        bigtime_t old_busy;
        int i;
        system_info info;
+       bigtime_t       oldLastMeasure;
 
        i = 0;
        init_times(&times);
        tmcookie = 0;
+       oldLastMeasure = lastMeasure;
+       lastMeasure = system_time();
+
+       get_system_info(&info);
+       old_busy = *busy_wait_time;
+       *busy_wait_time = info._busy_wait_time;
+
        while (get_next_team_info(&tmcookie, &tm) == B_NO_ERROR) {
                thcookie = 0;
                while (get_next_thread_info(tm.team, &thcookie, &t) == 
B_NO_ERROR) {
@@ -365,15 +372,13 @@ gather(
                        i++;
                }
        }
-       get_system_info(&info);
-       old_busy = *busy_wait_time;
-       *busy_wait_time = info._busy_wait_time;
        if (old != NULL) {
                if (screen_size_changed) {
                        setup_term(true);
                        screen_size_changed = 0;
                }
-               compare(old, &times, old_busy, *busy_wait_time, uinterval, 
refresh);
+               compare(old, &times, old_busy, *busy_wait_time,
+                       system_time() - oldLastMeasure, refresh);
                free_times(old);
        }
        return (times);
@@ -451,30 +456,26 @@ main(int argc, char **argv)
        
        signal(SIGWINCH, winch_handler);
        
-       then = system_time();
+       lastMeasure = system_time();
        if (iters < 0) {
                // You will only have to wait half a second for the first 
iteration.
                uinterval = 1 * 1000000 / 2;
-               baseline = gather(NULL, &busy, 0, refresh);
-               elapsed = system_time() - then;
-               if (elapsed < uinterval) {
+               baseline = gather(NULL, &busy, refresh);
+               elapsed = system_time() - lastMeasure;
+               if (elapsed < uinterval)
                        snooze(uinterval - elapsed);
-                       elapsed = uinterval;
-               }
                then = system_time();
-               baseline = gather(&baseline, &busy, elapsed, refresh);
+               baseline = gather(&baseline, &busy, refresh);
+
        } else
-               baseline = gather(NULL, &busy, 0, refresh);
+               baseline = gather(NULL, &busy, refresh);
 
        uinterval = interval * 1000000;
        for (i = 0; iters < 0 || i < iters; i++) {
-               elapsed = system_time() - then;
-               if (elapsed < uinterval) {
+               elapsed = system_time() - lastMeasure;
+               if (elapsed < uinterval)
                        snooze(uinterval - elapsed);
-                       elapsed = uinterval;
-               }
-               then = system_time();
-               baseline = gather(&baseline, &busy, elapsed, refresh);
+               baseline = gather(&baseline, &busy, refresh);
        }
        exit(0);
 }


Other related posts:

  • » [haiku-commits] haiku: hrev44130 - src/bin - stpere