-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmeasurement.hpp
More file actions
44 lines (36 loc) · 1.08 KB
/
measurement.hpp
File metadata and controls
44 lines (36 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef MEASUREMENT_H
#define MEASUREMENT_H
#include <string>
#ifdef CODSPEED_INSTRUMENTATION
#include "callgrind.h"
#endif
inline std::string get_version() {
#ifdef CODSPEED_VERSION
return {CODSPEED_VERSION};
#else
return {""};
#endif
}
#ifdef CODSPEED_INSTRUMENTATION
inline bool measurement_is_instrumented() { return RUNNING_ON_VALGRIND; }
inline void measurement_set_metadata() {
std::string metadata = "Metadata: codspeed-cpp " + get_version();
CALLGRIND_DUMP_STATS_AT(metadata.c_str());
}
__attribute__((always_inline)) inline void measurement_start() {
CALLGRIND_ZERO_STATS;
CALLGRIND_START_INSTRUMENTATION;
}
__attribute__((always_inline)) inline void measurement_stop(
const std::string &name) {
CALLGRIND_STOP_INSTRUMENTATION;
CALLGRIND_DUMP_STATS_AT(name.c_str());
};
#else
// Stub implementations for non-instrumentation builds
inline bool measurement_is_instrumented() { return false; }
inline void measurement_set_metadata() {}
inline void measurement_start() {}
inline void measurement_stop(const std::string &name) { (void)name; }
#endif
#endif // MEASUREMENT_H