diff options
| author | Gabriel Schneider <[email protected]> | 2026-11-10 12:07:53 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-11-10 12:09:56 -0300 |
| commit | a10e1691dbe5b944812dc8761a450636bc247e3d (patch) | |
| tree | 68b4ae8b519496dd35a94bb799f3fd564ec42569 /targets | |
| parent | 08d36ff6295a5f04e503ffe0aaa8a4e712af865f (diff) | |
| download | computeranim-a10e1691dbe5b944812dc8761a450636bc247e3d.tar.gz computeranim-a10e1691dbe5b944812dc8761a450636bc247e3d.zip | |
agent: bench-agent and its numbers, hooks with names, an archive cc can link
zig build bench-agent runs each capability against its native loop and
prints what it costs and writes; README has the table. ztrace run looks
at the ring a little longer before sleeping (a target that finds the
tracer asleep pays a futex wake an event). A hooked function's name is
defined as the string of its address, so the recorder's call stack reads
fib. A static link without libc's malloc says which -u to add. The
archive carries no stack probes, so cc links it in debug builds too.
Tests for --wrap (musl, zig cc) and for a recording that fills.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Diffstat (limited to 'targets')
| -rw-r--r-- | targets/agent_bench.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/targets/agent_bench.c b/targets/agent_bench.c new file mode 100644 index 0000000..e1add0e --- /dev/null +++ b/targets/agent_bench.c @@ -0,0 +1,45 @@ +// Loops to measure the agent with: `agent_bench WHAT N` runs one N times +// and prints the nanoseconds an iteration took. +// malloc a malloc and a free +// syscall a getppid +// call a call of `work`, which writes one word of `kb64` +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/syscall.h> +#include <time.h> +#include <unistd.h> + +// Memory to watch, of three sizes. +long kb1[1 << 7], kb64[1 << 13], mb1[1 << 17]; + +__attribute__((noinline)) long work(long i) { + kb64[i & 8191] = i; + return i * 3; +} + +static double now(void) { + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec * 1e9 + ts.tv_nsec; +} + +int main(int argc, char **argv) { + if (argc < 3) return 2; + long n = atol(argv[2]); + long sum = 0; + void *slots[64] = {0}; + double start = now(); + if (!strcmp(argv[1], "malloc")) { + for (long i = 0; i < n; i++) { + free(slots[i & 63]); + slots[i & 63] = malloc(16 + (i & 255)); + } + } else if (!strcmp(argv[1], "syscall")) { + for (long i = 0; i < n; i++) sum += syscall(SYS_getppid); + } else if (!strcmp(argv[1], "call")) { + for (long i = 0; i < n; i++) sum += work(i); + } else return 2; + printf("%s: %.1f ns each (%ld)\n", argv[1], (now() - start) / n, sum & 1); + return 0; +} |
