Ticket #4328: patch_top.diff

File patch_top.diff, 1.2 KB (added by stpere, 13 years ago)
  • src/bin/top.c

     
    443443            refresh = 0;
    444444        }
    445445    }
    446     if (iters < 0) {
    447         printf("Starting: infinite intervals of %d second%s each\n",
    448                interval,
    449                (interval == 1) ? "" : "s");
    450     } else {
     446    if (iters >= 0) {
    451447        printf("Starting: %d interval%s of %d second%s each\n", iters,
    452448               (iters == 1) ? "" : "s", interval,
    453449               (interval == 1) ? "" : "s");
     
    456452    signal(SIGWINCH, winch_handler);
    457453   
    458454    then = system_time();
     455    if (iters < 0) {
     456        // You will only have to wait half a second for the first iteration.
     457        uinterval = 1 * 1000000 / 2;
     458        baseline = gather(NULL, &busy, 0, refresh);
     459        elapsed = system_time() - then;
     460        if (elapsed < uinterval) {
     461            snooze(uinterval - elapsed);
     462            elapsed = uinterval;
     463        }
     464        then = system_time();
     465        baseline = gather(&baseline, &busy, elapsed, refresh);
     466    } else
     467        baseline = gather(NULL, &busy, 0, refresh);
     468
    459469    uinterval = interval * 1000000;
    460     baseline = gather(NULL, &busy, 0, refresh);
    461470    for (i = 0; iters < 0 || i < iters; i++) {
    462471        elapsed = system_time() - then;
    463472        if (elapsed < uinterval) {