aboutsummaryrefslogtreecommitdiff
path: root/test/instr_demo.c
diff options
context:
space:
mode:
authorhachem <im@hachem.wtf>2026-09-04 05:46:36 +0200
committerhachem <im@hachem.wtf>2026-09-04 05:46:36 +0200
commitd3a1b908fd3b0c47da2c33c16d18ebeb00da3b97 (patch)
tree1e8861de97ebd0c580a0cfaa4c759cf3e5be8e3b /test/instr_demo.c
parent9023d106c61db0be0de6460a397bbad42bbc3d96 (diff)
refactor: reorganize tests
Diffstat (limited to 'test/instr_demo.c')
-rw-r--r--test/instr_demo.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/instr_demo.c b/test/instr_demo.c
new file mode 100644
index 0000000..7983b82
--- /dev/null
+++ b/test/instr_demo.c
@@ -0,0 +1,51 @@
+// a fully instrumented demo: built with -finstrument-functions so EVERY function
+// here is traced automatically, no hand-picking. kept in plain C with only
+// printf and nanosleep so the trace is exactly these functions
+#include <stdio.h>
+#include <time.h>
+
+static void nap(long ms)
+{
+ struct timespec ts = { ms / 1000, (ms % 1000) * 1000000L };
+ nanosleep(&ts, NULL);
+}
+
+static long leaf(int n)
+{
+ long total = 0;
+ for (int i = 0; i < n * 40000; ++i)
+ total += i % 7;
+
+ return total;
+}
+
+static long inner(int round)
+{
+ long total = 0;
+ for (int i = 1; i <= 3; ++i)
+ total += leaf(round % 4 + i);
+
+ return total;
+}
+
+static long outer(int round)
+{
+ const long a = inner(round);
+ nap(20);
+ const long b = inner(round + 1);
+ return a + b;
+}
+
+int main(void)
+{
+ for (int round = 0; round < 15; ++round)
+ {
+ const long result = outer(round);
+ printf("round %d -> %ld\n", round, result);
+ fflush(stdout);
+ nap(120);
+ }
+
+ puts("done");
+ return 0;
+}