runners: Intercept logs/printf and exclude from stack/heap measurements

Logging is one of those things that's very useful to keep around, but
has a high-risk of stack/heap costs that shouldn't count towards any
benchmarks (you can always disable logging).

So, lets exclude them from stack/heap measurements.

This could've been done by defining all of littlefs's LFS3_DEBUG/INFO/
WARN/ERROR macros, but intercepting printf directly is a bit less
tedious. As a plus, we eliminate logging costs from any other filesystem
we benchmark, without need to fiddle with everyone's logging APIs.

---

Hmm. Actually, now that I've done a test run, these changes seem to have
no effect.

Which makes sense in hindsight:

1. For efficiencies sake, printf likely tries to allocate infrequently.
   Maybe only during the first call?

   And we print the bench id before entering the bench.

2. The way our stack measurements work, we only count them if we enter a
   bd op or call BENCH_STACK_PAUSE().

   So any printfs encountered previously would have been ignored by our
   stack measurements.

Still, better safe than sorry.
This commit is contained in:
Christopher Haster
2026-02-06 00:15:58 -06:00
parent c1b86ac9db
commit c722bc08f5
5 changed files with 168 additions and 44 deletions
+8
View File
@@ -105,24 +105,32 @@ TEST_CFLAGS += -Wno-unused-function
TEST_CFLAGS += -Wno-format-overflow
ifdef STACK
TEST_CFLAGS += -DTEST_STACK
TEST_CFLAGS += -Wl,--wrap=printf
TEST_CFLAGS += -Wl,--wrap=vprintf
endif
ifdef HEAP
TEST_CFLAGS += -DTEST_HEAP
TEST_CFLAGS += -Wl,--wrap=malloc
TEST_CFLAGS += -Wl,--wrap=free
TEST_CFLAGS += -Wl,--wrap=realloc
TEST_CFLAGS += -Wl,--wrap=printf
TEST_CFLAGS += -Wl,--wrap=vprintf
endif
BENCH_CFLAGS += -Wno-unused-function
BENCH_CFLAGS += -Wno-format-overflow
ifndef NO_STACK
BENCH_CFLAGS += -DBENCH_STACK
BENCH_CFLAGS += -Wl,--wrap=printf
BENCH_CFLAGS += -Wl,--wrap=vprintf
endif
ifndef NO_HEAP
BENCH_CFLAGS += -DBENCH_HEAP
BENCH_CFLAGS += -Wl,--wrap=malloc
BENCH_CFLAGS += -Wl,--wrap=free
BENCH_CFLAGS += -Wl,--wrap=realloc
BENCH_CFLAGS += -Wl,--wrap=printf
BENCH_CFLAGS += -Wl,--wrap=vprintf
endif
ifdef VERBOSE