diff options
| author | Mattias Andrée <maandree@kth.se> | 2021-03-26 08:56:11 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2021-03-26 08:56:11 +0100 |
| commit | dada58bbd2f4a008c52bf148cf852d548c83199f (patch) | |
| tree | dba973f95e02bc3aa04b935a69a0fdeff77964c4 /stopwatch.c | |
| parent | stopwatch: add key p for pausing (diff) | |
| download | pdatools-dada58bbd2f4a008c52bf148cf852d548c83199f.tar.gz pdatools-dada58bbd2f4a008c52bf148cf852d548c83199f.tar.bz2 pdatools-dada58bbd2f4a008c52bf148cf852d548c83199f.tar.xz | |
stopwatch: do not reset when saving lap time
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | stopwatch.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/stopwatch.c b/stopwatch.c index 7c5ec76..b978753 100644 --- a/stopwatch.c +++ b/stopwatch.c @@ -26,7 +26,7 @@ static int display_stopwatch(int timerfd) { uint64_t overrun = 0; - uintmax_t total_overrun = 0, h, m, s, d, first_overrun = 0; + uintmax_t total_overrun = 0, subtotal_overrun = 0, h, m, s, d, first_overrun = 0; int paused = 0, have_first = 0; struct itimerspec old_time, zero_time; size_t lap = 1; @@ -63,34 +63,34 @@ display_stopwatch(int timerfd) } else if (c == '\n') { if (timerfd_settime(timerfd, 0, &orig_time, NULL)) goto fail; - d = total_overrun % 10; - s = total_overrun / 10 % 60; - m = total_overrun / 10 / 60 % 60; - h = total_overrun / 10 / 60 / 60; + d = subtotal_overrun % 10; + s = subtotal_overrun / 10 % 60; + m = subtotal_overrun / 10 / 60 % 60; + h = subtotal_overrun / 10 / 60 / 60; if (quadsize) printf("\033#5"); printf("Lap %2zu: %ju:%02ju:%02ju.%ju", lap, h, m, s, d); lap++; if (!have_first) { have_first = 1; - first_overrun = total_overrun; - } else if (total_overrun > first_overrun) { - total_overrun = total_overrun - first_overrun; - d = total_overrun % 10; - s = total_overrun / 10 % 60; - m = total_overrun / 10 / 60 % 60; - h = total_overrun / 10 / 60 / 60; + first_overrun = subtotal_overrun; + } else if (subtotal_overrun > first_overrun) { + subtotal_overrun = subtotal_overrun - first_overrun; + d = subtotal_overrun % 10; + s = subtotal_overrun / 10 % 60; + m = subtotal_overrun / 10 / 60 % 60; + h = subtotal_overrun / 10 / 60 / 60; printf(" \033[31m(+%ju:%02ju:%02ju.%ju)\033[m", h, m, s, d); - } else if (total_overrun < first_overrun) { - total_overrun = first_overrun - total_overrun; - d = total_overrun % 10; - s = total_overrun / 10 % 60; - m = total_overrun / 10 / 60 % 60; - h = total_overrun / 10 / 60 / 60; + } else if (subtotal_overrun < first_overrun) { + subtotal_overrun = first_overrun - subtotal_overrun; + d = subtotal_overrun % 10; + s = subtotal_overrun / 10 % 60; + m = subtotal_overrun / 10 / 60 % 60; + h = subtotal_overrun / 10 / 60 / 60; printf(" \033[34m(-%ju:%02ju:%02ju.%ju)\033[m", h, m, s, d); } printf("\033[K\n"); - total_overrun = 0; + subtotal_overrun = 0; } } } @@ -125,6 +125,7 @@ display_stopwatch(int timerfd) goto fail; } else { total_overrun += (uintmax_t)overrun; + subtotal_overrun += (uintmax_t)overrun; } } |
