Debian Codegraph @

debian/rust-vendor/codspeed/instrument-hooks/includes/core.h

raw
1 // This file was manually created and exposes the functions of this library.
2 // TODO: Can we automatically generate this file?
3
4 #ifndef CORE_H
5 #define CORE_H
6
7 #include <stdbool.h>
8 #include <stdint.h>
9 #include <stdio.h>
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 #ifndef _WIN32
16 #include "callgrind.h"
17 #include "valgrind.h"
18 #else
19 #define CALLGRIND_START_INSTRUMENTATION
20 #define CALLGRIND_STOP_INSTRUMENTATION
21 #define CALLGRIND_ZERO_STATS
22 #endif
23
24 typedef struct InstrumentHooks InstrumentHooks;
25
26 InstrumentHooks *instrument_hooks_init(void);
27 void instrument_hooks_deinit(InstrumentHooks *);
28
29 bool instrument_hooks_is_instrumented(InstrumentHooks *);
30 uint8_t instrument_hooks_start_benchmark(InstrumentHooks *);
31 uint8_t instrument_hooks_stop_benchmark(InstrumentHooks *);
32 uint8_t instrument_hooks_set_executed_benchmark(InstrumentHooks *, int32_t pid,
33 const char *uri);
34 // Deprecated: use instrument_hooks_set_executed_benchmark instead
35 uint8_t instrument_hooks_executed_benchmark(InstrumentHooks *, int32_t pid,
36 const char *uri);
37 uint8_t instrument_hooks_set_integration(InstrumentHooks *, const char *name,
38 const char *version);
39
40 #define MARKER_TYPE_SAMPLE_START 0
41 #define MARKER_TYPE_SAMPLE_END 1
42 #define MARKER_TYPE_BENCHMARK_START 2
43 #define MARKER_TYPE_BENCHMARK_END 3
44
45 uint8_t instrument_hooks_add_marker(InstrumentHooks *, int32_t pid,
46 uint8_t marker_type, uint64_t timestamp);
47 uint64_t instrument_hooks_current_timestamp(void);
48
49 void callgrind_start_instrumentation();
50 void callgrind_stop_instrumentation();
51
52 // Feature flags for instrument hooks
53
54 typedef enum {
55 FEATURE_DISABLE_CALLGRIND_MARKERS = 0,
56 } instrument_hooks_feature_t;
57
58 void instrument_hooks_set_feature(uint64_t feature, bool enabled);
59
60 // Environment collection
61 // Call set_environment to register key-value pairs grouped by section.
62 // Call collect_linked_libraries to gather linked library metadata.
63 // Then call write_environment to flush everything to
64 // $CODSPEED_PROFILE_FOLDER/environment-<pid>.json.
65 uint8_t instrument_hooks_set_environment(InstrumentHooks *,
66 const char *section_name,
67 const char *key, const char *value);
68 uint8_t instrument_hooks_set_environment_list(InstrumentHooks *,
69 const char *section_name,
70 const char *key,
71 const char *const *values,
72 uint32_t count);
73 uint8_t instrument_hooks_write_environment(InstrumentHooks *, int32_t pid);
74
75 // Header functions that will be inlined. This can be used by languages that
76 // directly consume the headers such as C or C++. This will allow for more
77 // precise tracking of the benchmark performance.
78
79 static inline uint8_t instrument_hooks_start_benchmark_inline(
80 InstrumentHooks *instance) {
81 instrument_hooks_set_feature(FEATURE_DISABLE_CALLGRIND_MARKERS, true);
82 if (instrument_hooks_start_benchmark(instance) != 0) {
83 return 1;
84 }
85
86 CALLGRIND_ZERO_STATS;
87 CALLGRIND_START_INSTRUMENTATION;
88 return 0;
89 }
90
91 static inline uint8_t instrument_hooks_stop_benchmark_inline(
92 InstrumentHooks *instance) {
93 CALLGRIND_STOP_INSTRUMENTATION;
94 return instrument_hooks_stop_benchmark(instance);
95 }
96
97 #ifdef __cplusplus
98 }
99 #endif
100
101 #endif