Skip to content

Commit 7b14501

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 7b14501

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

example/main.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,12 @@ void example_function() {
2222
printf("Benchmark executed\n");
2323
}
2424

25-
int main() {
26-
instrument_hooks_set_feature(FEATURE_DISABLE_CALLGRIND_MARKERS, true);
25+
__attribute__((noinline)) void __codspeed_root_frame__example(
26+
void (*benchmark_fn)(void)) {
27+
benchmark_fn();
28+
}
2729

30+
int main() {
2831
InstrumentHooks *hooks = instrument_hooks_init();
2932
if (!hooks) {
3033
printf("Failed to initialize instrument hooks\n");
@@ -37,7 +40,7 @@ int main() {
3740
printf("Not running under instrumentation\n");
3841
}
3942

40-
instrument_hooks_set_integration(hooks, "example", "1.0.0");
43+
instrument_hooks_set_integration(hooks, "custom-integration", "1.0.0");
4144

4245
printf("Starting benchmark...\n");
4346
if (instrument_hooks_start_benchmark_inline(hooks) != 0) {
@@ -53,7 +56,7 @@ int main() {
5356
expensive_setup();
5457

5558
uint64_t start_time = instrument_hooks_current_timestamp();
56-
example_function();
59+
__codspeed_root_frame__example(example_function);
5760
uint64_t end_time = instrument_hooks_current_timestamp();
5861

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

0 commit comments

Comments
 (0)