diff options
| -rw-r--r-- | burstdog.c | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -9,6 +9,8 @@ #include <stdbool.h> #include <string.h> #include <time.h> +#include <stdint.h> +#include <inttypes.h> // settings #define BURSTDOG_IV 10 // how often to wake up, per second @@ -28,7 +30,7 @@ struct process { unsigned int pid; int fd; - unsigned int time[BURSTDOG_SAMPLES]; + uint64_t time[BURSTDOG_SAMPLES]; }; struct process_tab @@ -97,8 +99,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - unsigned int times[BURSTDOG_SAMPLES]; - unsigned int num_samples = 0; + uint64_t times[BURSTDOG_SAMPLES]; + size_t num_samples = 0; unsigned int bursting_pid = 0; struct process_tab *procs = &process_tabs[0], *oldprocs = &process_tabs[1]; for (;;) { @@ -182,7 +184,7 @@ int main(int argc, char **argv) struct process *proc = &procs->arr[procs->num++]; proc->pid = pids[i]; proc->fd = statfd; - proc->time[0] = atoi(utime) + atoi(stime); + proc->time[0] = atoll(utime) + atoll(stime); if (oldproc) { memcpy(&proc->time[1], &oldproc->time[0], (BURSTDOG_SAMPLES-1) * sizeof(int)); @@ -192,9 +194,9 @@ int main(int argc, char **argv) } if (num_samples == BURSTDOG_SAMPLES) { - unsigned int total = times[0] - times[BURSTDOG_SAMPLES-1]; - unsigned int subset = proc->time[0] - proc->time[BURSTDOG_SAMPLES-1]; - unsigned int share = subset * 100 / total; + uint64_t total = times[0] - times[BURSTDOG_SAMPLES-1]; + uint64_t subset = proc->time[0] - proc->time[BURSTDOG_SAMPLES-1]; + uint64_t share = subset * 100 / total; if (bursting_pid == proc->pid && share < BURSTDOG_BURST_END) { bursting_pid = 0; } else if (bursting_pid != proc->pid && share >= BURSTDOG_BURST) { @@ -205,7 +207,7 @@ int main(int argc, char **argv) strftime(timebuf, 128, "%c", &time_s); int n_line = snprintf(linebuffer, BUFSIZ, - "%s: %5d %s is bursting: %d of %d ticks (%d%%)\n", + "%s: %5d %s is bursting: %"PRIu64" of %"PRIu64" ticks (%"PRIu64"%%)\n", timebuf, proc->pid, name, subset, total, share); int n_written = write(logfd, linebuffer, n_line); |
