diff options
| author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2026-04-01 22:18:41 +0200 |
|---|---|---|
| committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2026-04-01 22:18:41 +0200 |
| commit | 102ded275951f107447434c933d1e3d98ac82bfa (patch) | |
| tree | b22b482bd8ddacf88e4e461df068e95ad730978f | |
| parent | fc93ed97cd02e7c737a3fdcd93faa6c866ab2d7a (diff) | |
| download | burstdog-102ded275951f107447434c933d1e3d98ac82bfa.tar.xz | |
rename to burstdog
| -rw-r--r-- | .gitignore | 4 | ||||
| -rw-r--r-- | Makefile | 8 | ||||
| -rw-r--r-- | README.md | 16 | ||||
| -rw-r--r-- | burstdog.c (renamed from watchdog.c) | 34 |
4 files changed, 31 insertions, 31 deletions
@@ -1,2 +1,2 @@ -watchdog -watchdog.log +burstdog +burstdog.log @@ -1,10 +1,10 @@ CFLAGS = -O3 -Wall -Wextra PREFIX = /usr/local -watchdog: watchdog.c - $(CC) $(CFLAGS) watchdog.c -o watchdog +burstdog: burstdog.c + $(CC) $(CFLAGS) burstdog.c -o burstdog -install: watchdog - install -Dm 755 watchdog "$(PREFIX)/bin/watchdog" +install: burstdog + install -Dm 755 burstdog "$(PREFIX)/bin/burstdog" .PHONY: install @@ -1,27 +1,27 @@ -# watchdog +# burstdog Monitor CPU usage by process and report bursts to a logfile. ## Invocation ```sh -watchdog [logfile] +burstdog [logfile] ``` -Default logfile is `watchdog.log` in the current directory. +Default logfile is `burstdog.log` in the current directory. ## Build -Compile using `make` or `cc watchdog.c -O3 -o watchdog`. +Compile using `make` or `cc burstdog.c -O3 -o burstdog`. -See [watchdog.c](watchdog.c) for configuration options. +See [burstdog.c](burstdog.c) for configuration options. Install to PREFIX using `make install`. -## Test watchdog +## Test burstdog ```sh -$ watchdog & -$ tail -f watchdog.log +$ burstdog & +$ tail -f burstdog.log $ cat < /dev/random > /dev/null # in a different shell ``` @@ -11,12 +11,12 @@ #include <time.h> // settings -#define WATCHDOG_IV 10 // how often to wake up, per second -#define WATCHDOG_BURST 98 // cpu time percentage considered a burst -#define WATCHDOG_BURST_END 90 // cpu time percentage considered the end of a burst -#define WATCHDOG_SAMPLES 5 // how many samples a burst needs to persist for to be logged +#define BURSTDOG_IV 10 // how often to wake up, per second +#define BURSTDOG_BURST 98 // cpu time percentage considered a burst +#define BURSTDOG_BURST_END 90 // cpu time percentage considered the end of a burst +#define BURSTDOG_SAMPLES 5 // how many samples a burst needs to persist for to be logged -#if WATCHDOG_SAMPLES < 2 +#if BURSTDOG_SAMPLES < 2 #error must consider at least 2 samples #endif @@ -28,7 +28,7 @@ struct process { unsigned int pid; int fd; - unsigned int time[WATCHDOG_SAMPLES]; + unsigned int time[BURSTDOG_SAMPLES]; }; struct process_tab @@ -84,7 +84,7 @@ int main(int argc, char **argv) { long clock_tick = sysconf(_SC_CLK_TCK); - char *logfile = argc > 1 ? argv[1] : "watchdog.log"; + char *logfile = argc > 1 ? argv[1] : "burstdog.log"; int logfd = open(logfile, O_WRONLY | O_CREAT | O_APPEND | O_DIRECT, 0644); if (logfd == -1) { perror("open logfile"); @@ -97,13 +97,13 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - unsigned int times[WATCHDOG_SAMPLES]; + unsigned int times[BURSTDOG_SAMPLES]; unsigned int num_samples = 0; unsigned int bursting_pid = 0; struct process_tab *procs = &process_tabs[0], *oldprocs = &process_tabs[1]; for (;;) { size_t move_samples = num_samples; - if (num_samples < WATCHDOG_SAMPLES) + if (num_samples < BURSTDOG_SAMPLES) num_samples++; else move_samples--; @@ -185,19 +185,19 @@ int main(int argc, char **argv) proc->time[0] = atoi(utime) + atoi(stime); if (oldproc) { - memcpy(&proc->time[1], &oldproc->time[0], (WATCHDOG_SAMPLES-1) * sizeof(int)); + memcpy(&proc->time[1], &oldproc->time[0], (BURSTDOG_SAMPLES-1) * sizeof(int)); } else { - for (size_t j = 1; j < WATCHDOG_SAMPLES; j++) + for (size_t j = 1; j < BURSTDOG_SAMPLES; j++) proc->time[j] = proc->time[0]; } - if (num_samples == WATCHDOG_SAMPLES) { - unsigned int total = times[0] - times[WATCHDOG_SAMPLES-1]; - unsigned int subset = proc->time[0] - proc->time[WATCHDOG_SAMPLES-1]; + 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; - if (bursting_pid == proc->pid && share < WATCHDOG_BURST_END) { + if (bursting_pid == proc->pid && share < BURSTDOG_BURST_END) { bursting_pid = 0; - } else if (bursting_pid != proc->pid && share >= WATCHDOG_BURST) { + } else if (bursting_pid != proc->pid && share >= BURSTDOG_BURST) { time_t time_v = time(NULL); struct tm time_s; localtime_r(&time_v, &time_s); @@ -222,6 +222,6 @@ int main(int argc, char **argv) oldprocs = procs; procs = tmp; - usleep(1000000/WATCHDOG_IV); + usleep(1000000/BURSTDOG_IV); } } |
