Skip to content

Commit d124ed9

Browse files
JoeMattclaude
andcommitted
perf_counters: always-export symbols + benchmark BENCH_STATE knob
Two small follow-ups to the perf_counters baseline: * Move the perf_counters_register/dump/reset declarations out of the BENCH_PROFILE ifdef in the header, and provide always-defined no-op bodies in perf_counters.c. This lets the test ABI export the symbols unconditionally (added back to exports-test.list / link-test.T) so test_benchmark can dlsym them in any build flavor; in non-BENCH_PROFILE builds the bodies are empty. * Makefile benchmark target gains a BENCH_STATE knob: make benchmark BENCH_ROM=foo.j64 BENCH_STATE=foo.state6 Plumbed through to test_benchmark --load-state, which already supports both raw retro_serialize payloads and RetroArch RASTATE containers (lands via PR #128). Lets us profile actual gameplay scenes instead of boot/menu idle. Co-Authored-By: Claude Opus 4.7 <[email protected]>
1 parent 28b56ce commit d124ed9

3 files changed

Lines changed: 24 additions & 11 deletions

File tree

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -893,7 +893,8 @@ benchmark:
893893
-o test/tools/test_benchmark test/tools/test_benchmark.c \
894894
$(if $(filter Linux,$(shell uname -s)),-ldl)
895895
./test/tools/test_benchmark ./$(TARGET) "$(BENCH_ROM)" $(BENCH_FRAMES) \
896-
--warmup $(BENCH_WARMUP) --blitter $(BENCH_BLITTER)
896+
--warmup $(BENCH_WARMUP) --blitter $(BENCH_BLITTER) \
897+
$(if $(BENCH_STATE),--load-state "$(BENCH_STATE)")
897898

898899
print-%:
899900
@echo '$*=$($*)'

src/core/perf_counters.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
11
/*
22
* perf_counters.c - registry + dump for opt-in instrumentation counters.
3-
* Only compiled into the program when BENCH_PROFILE is defined; the header
4-
* provides no-op stubs otherwise.
3+
*
4+
* The register/dump/reset functions are *always* defined so they can be
5+
* exported through the test ABI without conditional linker scripts.
6+
* In !BENCH_PROFILE builds the bodies are no-ops and no PERF_COUNTER
7+
* calls perf_counters_register, so the registry stays empty.
58
*/
69
#include "perf_counters.h"
710

811
#ifdef BENCH_PROFILE
9-
1012
static perf_counter_entry_t *perf_head = (perf_counter_entry_t *)0;
13+
#endif
1114

1215
void perf_counters_register(perf_counter_entry_t *entry)
1316
{
17+
#ifdef BENCH_PROFILE
1418
if (!entry || entry->next)
1519
return; /* already linked */
1620
entry->next = perf_head;
1721
perf_head = entry;
22+
#else
23+
(void)entry;
24+
#endif
1825
}
1926

2027
void perf_counters_reset(void)
2128
{
29+
#ifdef BENCH_PROFILE
2230
perf_counter_entry_t *e;
2331
for (e = perf_head; e; e = e->next)
2432
*e->value = 0;
33+
#endif
2534
}
2635

2736
void perf_counters_dump(FILE *out)
2837
{
38+
#ifdef BENCH_PROFILE
2939
perf_counter_entry_t *e;
3040
if (!out)
3141
out = stderr;
@@ -36,6 +46,7 @@ void perf_counters_dump(FILE *out)
3646
fprintf(out, "[perf] counter dump:\n");
3747
for (e = perf_head; e; e = e->next)
3848
fprintf(out, "[perf] %-40s %llu\n", e->name, *e->value);
49+
#else
50+
(void)out;
51+
#endif
3952
}
40-
41-
#endif /* BENCH_PROFILE */

src/core/perf_counters.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,10 @@
3333
extern "C" {
3434
#endif
3535

36-
#ifdef BENCH_PROFILE
36+
/* Registry types and entry points are *always* declared so the test
37+
* ABI can export them unconditionally. When BENCH_PROFILE is undefined
38+
* the bodies (in perf_counters.c) become no-ops and no PERF_COUNTER
39+
* macro registers anything, so the registry stays empty. */
3740

3841
typedef struct perf_counter_entry
3942
{
@@ -46,6 +49,8 @@ void perf_counters_register(perf_counter_entry_t *entry);
4649
void perf_counters_dump(FILE *out);
4750
void perf_counters_reset(void);
4851

52+
#ifdef BENCH_PROFILE
53+
4954
#define PERF_COUNTER(name) \
5055
static unsigned long long perf_##name = 0; \
5156
static perf_counter_entry_t perf_entry_##name = \
@@ -72,10 +77,6 @@ void perf_counters_reset(void);
7277
#define PERF_INC(name) (0)
7378
#define PERF_ADD(name, n) ((void)(n), 0)
7479

75-
/* Stubs so callers don't need their own #ifdef around dump/reset. */
76-
static __inline void perf_counters_dump(FILE *out) { (void)out; }
77-
static __inline void perf_counters_reset(void) { }
78-
7980
#endif /* BENCH_PROFILE */
8081

8182
#ifdef __cplusplus

0 commit comments

Comments
 (0)