diff options
| author | Filip Wandzio <contact@philw.dev> | 2026-03-01 01:03:39 +0100 |
|---|---|---|
| committer | Filip Wandzio <contact@philw.dev> | 2026-03-01 01:03:39 +0100 |
| commit | bf0d77d7d448e964e9716d5af67c48f3d014f090 (patch) | |
| tree | e55f1e91a8c20cd737dfb01dc12a954c25711e01 /benchmark/resource_usage.c | |
| download | embedded_guardian-bf0d77d7d448e964e9716d5af67c48f3d014f090.tar.gz embedded_guardian-bf0d77d7d448e964e9716d5af67c48f3d014f090.zip | |
Scaffold basic project tree, implement benchmarking logic
Implement unit testing guardian
Diffstat (limited to '')
| -rw-r--r-- | benchmark/resource_usage.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/benchmark/resource_usage.c b/benchmark/resource_usage.c new file mode 100644 index 0000000..04f7195 --- /dev/null +++ b/benchmark/resource_usage.c | |||
| @@ -0,0 +1,17 @@ | |||
| 1 | #include "resource_usage.h" | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <sys/resource.h> | ||
| 4 | #include <sys/time.h> | ||
| 5 | |||
| 6 | void print_resource_usage(const char *label) { | ||
| 7 | struct rusage usage; | ||
| 8 | if (getrusage(RUSAGE_SELF, &usage) == 0) { | ||
| 9 | long mem_kb = usage.ru_maxrss; | ||
| 10 | double user_sec = usage.ru_utime.tv_sec + usage.ru_utime.tv_usec / 1e6; | ||
| 11 | double sys_sec = usage.ru_stime.tv_sec + usage.ru_stime.tv_usec / 1e6; | ||
| 12 | printf("[%s] CPU user: %.3f s, system: %.3f s, peak memory: %ld KB\n", | ||
| 13 | label, user_sec, sys_sec, mem_kb); | ||
| 14 | } else { | ||
| 15 | printf("[%s] Resource usage not available\n", label); | ||
| 16 | } | ||
| 17 | } | ||
