aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2026-04-01 22:18:41 +0200
committerLizzy Fleckenstein <lizzy@vlhl.dev>2026-04-01 22:18:41 +0200
commit102ded275951f107447434c933d1e3d98ac82bfa (patch)
treeb22b482bd8ddacf88e4e461df068e95ad730978f
parentfc93ed97cd02e7c737a3fdcd93faa6c866ab2d7a (diff)
downloadburstdog-102ded275951f107447434c933d1e3d98ac82bfa.tar.xz
rename to burstdog
-rw-r--r--.gitignore4
-rw-r--r--Makefile8
-rw-r--r--README.md16
-rw-r--r--burstdog.c (renamed from watchdog.c)34
4 files changed, 31 insertions, 31 deletions
diff --git a/.gitignore b/.gitignore
index 8955088..711446a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
-watchdog
-watchdog.log
+burstdog
+burstdog.log
diff --git a/Makefile b/Makefile
index 5f7c715..e578636 100644
--- a/Makefile
+++ b/Makefile
@@ -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
diff --git a/README.md b/README.md
index 1b527a5..005e299 100644
--- a/README.md
+++ b/README.md
@@ -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
```
diff --git a/watchdog.c b/burstdog.c
index 0e2d91b..8544f9e 100644
--- a/watchdog.c
+++ b/burstdog.c
@@ -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);
}
}