Skip to content

Commit 1ec92c8

Browse files
committed
feat: add callgrind_toggle_collect helper
Expose CALLGRIND_TOGGLE_COLLECT as a wrapper next to the existing start/stop instrumentation helpers. Unlike toggling instrumentation, toggling collection does not flush the simulated cache, so integrations can exclude code regions (e.g. google benchmark's PauseTiming sections) from measurement without paying an artificial cold-cache warmup in the measured region. Refs COD-2033.
1 parent b9ddb5b commit 1ec92c8

3 files changed

Lines changed: 15 additions & 0 deletions

File tree

dist/core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61296,6 +61296,8 @@ void callgrind_start_instrumentation() {}
6129661296

6129761297
void callgrind_stop_instrumentation() {}
6129861298

61299+
void callgrind_toggle_collect() {}
61300+
6129961301
void callgrind_add_obj_skip(uint8_t const *path) { (void)path; }
6130061302
#else
6130161303
#include "callgrind.h"
@@ -61315,6 +61317,8 @@ void callgrind_start_instrumentation() { CALLGRIND_START_INSTRUMENTATION; }
6131561317

6131661318
void callgrind_stop_instrumentation() { CALLGRIND_STOP_INSTRUMENTATION; }
6131761319

61320+
void callgrind_toggle_collect() { CALLGRIND_TOGGLE_COLLECT; }
61321+
6131861322
void callgrind_add_obj_skip(uint8_t const *path) {
6131961323
CALLGRIND_ADD_OBJ_SKIP(path);
6132061324
}

includes/core.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ uint64_t instrument_hooks_current_timestamp(void);
4949
void callgrind_start_instrumentation();
5050
void callgrind_stop_instrumentation();
5151

52+
// Toggle callgrind cost collection on/off without re-instrumenting.
53+
// Unlike start/stop instrumentation, this does not flush the simulated
54+
// cache, so it can be used to exclude code regions from measurement
55+
// without introducing artificial cold-cache costs.
56+
// Safe to call outside Valgrind: expands to a no-op.
57+
void callgrind_toggle_collect();
58+
5259
// Register an object file path on callgrind's runtime --obj-skip list.
5360
// Equivalent to passing --obj-skip=<path> on the valgrind command line.
5461
// Safe to call outside Valgrind: expands to a no-op.

src/helpers/valgrind_wrapper.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ void callgrind_start_instrumentation() {}
1717

1818
void callgrind_stop_instrumentation() {}
1919

20+
void callgrind_toggle_collect() {}
21+
2022
void callgrind_add_obj_skip(uint8_t const *path) { (void)path; }
2123
#else
2224
#include "callgrind.h"
@@ -36,6 +38,8 @@ void callgrind_start_instrumentation() { CALLGRIND_START_INSTRUMENTATION; }
3638

3739
void callgrind_stop_instrumentation() { CALLGRIND_STOP_INSTRUMENTATION; }
3840

41+
void callgrind_toggle_collect() { CALLGRIND_TOGGLE_COLLECT; }
42+
3943
void callgrind_add_obj_skip(uint8_t const *path) {
4044
CALLGRIND_ADD_OBJ_SKIP(path);
4145
}

0 commit comments

Comments
 (0)