-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathmeasurement.hpp
More file actions
91 lines (75 loc) · 2.61 KB
/
measurement.hpp
File metadata and controls
91 lines (75 loc) · 2.61 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#ifndef MEASUREMENT_H
#define MEASUREMENT_H
#include <cassert>
#include <string>
#ifdef _WIN32
#include <process.h>
#define getpid _getpid
#define ALWAYS_INLINE __forceinline
#else
#include <unistd.h>
#define ALWAYS_INLINE __attribute__((always_inline)) inline
#endif
extern "C" {
#include "core.h"
}
extern InstrumentHooks* g_hooks;
void measurement_init();
inline std::string get_version() {
#ifdef CODSPEED_VERSION
return {CODSPEED_VERSION};
#else
return {""};
#endif
}
inline bool measurement_is_instrumented() {
return instrument_hooks_is_instrumented(g_hooks);
}
inline void measurement_set_metadata() {
std::string version = get_version();
instrument_hooks_set_integration(g_hooks, "codspeed-cpp", version.c_str());
// Report C++ toolchain information
#ifdef CODSPEED_CXX_COMPILER_ID
instrument_hooks_set_environment(g_hooks, "C++ Compiler", "compiler_id",
CODSPEED_CXX_COMPILER_ID);
#endif
#ifdef CODSPEED_CXX_COMPILER_VERSION
instrument_hooks_set_environment(g_hooks, "C++ Compiler", "version",
CODSPEED_CXX_COMPILER_VERSION);
#endif
#ifdef CODSPEED_CXX_COMPILER_FULL_VERSION
instrument_hooks_set_environment(g_hooks, "C++ Compiler", "build",
CODSPEED_CXX_COMPILER_FULL_VERSION);
#endif
#ifdef CODSPEED_BUILD_TYPE
instrument_hooks_set_environment(g_hooks, "C++ Compiler", "build_type",
CODSPEED_BUILD_TYPE);
#endif
instrument_hooks_write_environment(g_hooks, static_cast<uint32_t>(getpid()));
}
ALWAYS_INLINE void measurement_start() {
instrument_hooks_start_benchmark_inline(g_hooks);
}
ALWAYS_INLINE void measurement_stop() {
instrument_hooks_stop_benchmark_inline(g_hooks);
}
ALWAYS_INLINE void measurement_set_executed_benchmark(const std::string& name) {
auto current_pid = getpid();
instrument_hooks_executed_benchmark(g_hooks, current_pid, name.c_str());
}
ALWAYS_INLINE uint64_t measurement_current_timestamp() {
return instrument_hooks_current_timestamp();
}
ALWAYS_INLINE uint8_t measurement_add_marker(uint8_t marker_type,
uint64_t timestamp) {
auto pid = static_cast<uint32_t>(getpid());
return instrument_hooks_add_marker(g_hooks, pid, marker_type, timestamp);
}
ALWAYS_INLINE void measurement_add_benchmark_timestamps(uint64_t start,
uint64_t end) {
assert(start <= end);
assert(start != 0 && end != 0);
measurement_add_marker(MARKER_TYPE_BENCHMARK_START, start);
measurement_add_marker(MARKER_TYPE_BENCHMARK_END, end);
}
#endif // MEASUREMENT_H