runners: A number of stack/heap measurement tweaks

- Renamed BENCH_STACK/HEAP -> BENCH_STACK/HEAP_WATERMARK

- Renamed BENCH_YES_STACK/HEAP -> BENCH_STACK/HEAP

- Tweaked stack/heap watermarks to hopefully be easier to access when
  debugging. Now also exposed as global variables
  (bench_stack/heap_watermark).

  I considered changing BENCH_STACK/HEAP_WATERMARK to be the variable
  itself, to be consistent with TEST_PLS, but decided against it:

  1. BENCH_STACK_CURRENT() is a bit magic in that it relies on
     __attribute__((noinline)) to force a new stack frame. This wouldn't
     really be possible with a variable.

  2. TEST_PLS is at least constant from the _current run_'s perspective.
     This isn't true for the stack/heap watermarks.

- Reworked internals a bit to hopefully be simpler
This commit is contained in:
Christopher Haster
2026-02-05 23:24:32 -06:00
parent a914057407
commit c1b86ac9db
7 changed files with 168 additions and 318 deletions
+20 -12
View File
@@ -148,36 +148,44 @@ void bench_permutation(size_t i, uint32_t *buffer, size_t size);
#define BENCH_FACTORIAL(x) bench_factorial(x)
#define BENCH_PERMUTATION(i, buffer, size) bench_permutation(i, buffer, size)
#ifdef BENCH_YES_STACK
#ifdef BENCH_STACK
// get the maximum/current stack usage for this run
size_t bench_stack(void);
__attribute__((noinline))
size_t bench_stack_current(void);
__attribute__((noinline))
void bench_stack_pause(void);
extern size_t bench_stack_watermark;
__attribute__((noinline)) size_t bench_stack_current(void);
__attribute__((noinline)) void bench_stack_pause(void);
void bench_stack_resume(void);
#define BENCH_STACK() bench_stack()
#define BENCH_STACK_WATERMARK() bench_stack_watermark
#define BENCH_STACK_CURRENT() bench_stack_current()
#define BENCH_STACK_PAUSE() bench_stack_pause()
#define BENCH_STACK_RESUME() bench_stack_resume()
#else
// stubs if not measuring stack
#define BENCH_STACK_PAUSE()
#define BENCH_STACK_RESUME()
#endif
#ifdef BENCH_YES_HEAP
#ifdef BENCH_HEAP
// get the maximum/current heap usage for this run
size_t bench_heap(void);
size_t bench_heap_current(void);
extern size_t bench_heap_watermark;
extern size_t bench_heap_current;
void bench_heap_pause(void);
void bench_heap_resume(void);
void bench_heap_inc(size_t size);
void bench_heap_dec(size_t size);
#define BENCH_HEAP() bench_heap()
#define BENCH_HEAP_CURRENT() bench_heap_current()
#define BENCH_HEAP_WATERMARK() bench_heap_watermark
#define BENCH_HEAP_CURRENT() bench_heap_current
#define BENCH_HEAP_PAUSE() bench_heap_pause()
#define BENCH_HEAP_RESUME() bench_heap_resume()
#define BENCH_HEAP_INC(size) bench_heap_inc(size)
#define BENCH_HEAP_DEC(size) bench_heap_dec(size)
#else
// stubs if not measuring heap
#define BENCH_HEAP_PAUSE()
#define BENCH_HEAP_RESUME()
#define BENCH_HEAP_INC(size)
#define BENCH_HEAP_DEC(size)
#endif