Skip to content

Commit e30ac1f

Browse files
committed
chore(example): demonstrate __codspeed_root_frame__ pattern
Wraps the benchmarked call in a noinline __codspeed_root_frame__ helper so the example matches the pattern documented in the custom harness guide.
1 parent 5cb3235 commit e30ac1f

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

example/main.c

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,32 @@
88

99
#include "core.h"
1010

11+
#if defined(_MSC_VER)
12+
#define CODSPEED_NOINLINE __declspec(noinline)
13+
#else
14+
#define CODSPEED_NOINLINE __attribute__((noinline))
15+
#endif
16+
1117
static int fib(int n) {
1218
if (n <= 1) return n;
1319
return fib(n - 1) + fib(n - 2);
1420
}
1521

1622
static void expensive_setup(void) { fib(30); }
1723

18-
void example_function() {
24+
void example_function(void) {
1925
// Simulate some work
2026
for (volatile int i = 0; i < 100000; i++)
2127
;
2228
printf("Benchmark executed\n");
2329
}
2430

25-
int main() {
26-
instrument_hooks_set_feature(FEATURE_DISABLE_CALLGRIND_MARKERS, true);
31+
CODSPEED_NOINLINE void __codspeed_root_frame__example(
32+
void (*benchmark_fn)(void)) {
33+
benchmark_fn();
34+
}
2735

36+
int main() {
2837
InstrumentHooks *hooks = instrument_hooks_init();
2938
if (!hooks) {
3039
printf("Failed to initialize instrument hooks\n");
@@ -37,7 +46,7 @@ int main() {
3746
printf("Not running under instrumentation\n");
3847
}
3948

40-
instrument_hooks_set_integration(hooks, "example", "1.0.0");
49+
instrument_hooks_set_integration(hooks, "custom-integration", "1.0.0");
4150

4251
printf("Starting benchmark...\n");
4352
if (instrument_hooks_start_benchmark_inline(hooks) != 0) {
@@ -53,7 +62,7 @@ int main() {
5362
expensive_setup();
5463

5564
uint64_t start_time = instrument_hooks_current_timestamp();
56-
example_function();
65+
__codspeed_root_frame__example(example_function);
5766
uint64_t end_time = instrument_hooks_current_timestamp();
5867

5968
// Add the markers which mark when the benchmarked function was running

0 commit comments

Comments
 (0)