-
Notifications
You must be signed in to change notification settings - Fork 4
/
CMakeLists.txt
209 lines (172 loc) · 8.24 KB
/
CMakeLists.txt
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
cmake_minimum_required(VERSION 3.10)
project(libperf-cpp VERSION 0.9.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Wpedantic -Wconversion -Wcast-align -Wunused -Wshadow -Wold-style-cast -Wpointer-arith -Wcast-qual -Wno-missing-braces")
set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g3")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -g -DNDEBUG")
set(CMAKE_BUILD_TYPE RELEASE)
# Include include/ folder.
include_directories(include/)
#############################################################
# Options #
#############################################################
option(BUILD_EXAMPLES "Build examples in examples/ directory." OFF)
option(BUILD_LIB_SHARED "Build the library as a shared library (default is static)." OFF)
option(BUILD_TESTS "Build the unit tests." OFF)
#############################################################
# perf-cpp library definition #
#############################################################
set(PERF_CPP_SRC
src/counter.cpp
src/group.cpp
src/counter_definition.cpp
src/event_counter.cpp
src/sampler.cpp
src/hardware_info.cpp
src/metric_expression.cpp
src/requested_event.cpp
src/analyzer/memory_access.cpp
)
if (BUILD_LIB_SHARED)
add_library(perf-cpp SHARED ${PERF_CPP_SRC})
else ()
add_library(perf-cpp STATIC ${PERF_CPP_SRC})
endif ()
#############################################################
# Examples definition #
#############################################################
if(BUILD_EXAMPLES)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/examples/bin)
## Single-threaded
add_executable(single-thread EXCLUDE_FROM_ALL examples/single_thread.cpp examples/access_benchmark.cpp)
target_link_libraries(single-thread perf-cpp)
## Multi-threaded; but inherit counter from main-thread
add_executable(inherit-thread EXCLUDE_FROM_ALL examples/inherit_thread.cpp examples/access_benchmark.cpp)
target_link_libraries(inherit-thread perf-cpp)
## Multi-threaded with thread-local counter
add_executable(multi-thread EXCLUDE_FROM_ALL examples/multi_thread.cpp examples/access_benchmark.cpp)
target_link_libraries(multi-thread perf-cpp)
## Multi-CPU with per-CPU counter
add_executable(multi-cpu EXCLUDE_FROM_ALL examples/multi_cpu.cpp examples/access_benchmark.cpp)
target_link_libraries(multi-cpu perf-cpp)
## Multi-Process with per-process counter
add_executable(multi-process EXCLUDE_FROM_ALL examples/multi_process.cpp examples/access_benchmark.cpp)
target_link_libraries(multi-process perf-cpp)
## Sampling instruction pointers
add_executable(instruction-pointer-sampling EXCLUDE_FROM_ALL examples/instruction_pointer_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(instruction-pointer-sampling perf-cpp)
## Sampling instruction pointers
add_executable(counter-sampling EXCLUDE_FROM_ALL examples/counter_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(counter-sampling perf-cpp)
## Branch sampling
add_executable(branch-sampling EXCLUDE_FROM_ALL examples/branch_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(branch-sampling perf-cpp)
## Memory address sampling
add_executable(address-sampling EXCLUDE_FROM_ALL examples/address_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(address-sampling perf-cpp)
## Sampling user_registers
add_executable(register-sampling EXCLUDE_FROM_ALL examples/register_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(register-sampling perf-cpp)
## Sampling on multiple threads
add_executable(multi-thread-sampling EXCLUDE_FROM_ALL examples/multi_thread_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(multi-thread-sampling perf-cpp)
## Sampling on multiple threads
add_executable(multi-cpu-sampling EXCLUDE_FROM_ALL examples/multi_cpu_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(multi-cpu-sampling perf-cpp)
## Sampling with multiple events
add_executable(multi-event-sampling EXCLUDE_FROM_ALL examples/multi_event_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(multi-event-sampling perf-cpp)
## Sampling with raw values
add_executable(amd-ibs-raw-sampling EXCLUDE_FROM_ALL examples/amd_ibs_raw_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(amd-ibs-raw-sampling perf-cpp)
## Sampling with raw values
add_executable(context-switch-sampling EXCLUDE_FROM_ALL examples/context_switch_sampling.cpp examples/access_benchmark.cpp)
target_link_libraries(context-switch-sampling perf-cpp)
## Analyze Samples with DataAnalyzer
add_executable(memory-access-analyzer EXCLUDE_FROM_ALL examples/memory_access_analyzer.cpp examples/access_benchmark.cpp)
target_link_libraries(memory-access-analyzer perf-cpp)
## Live Events
add_executable(live-events EXCLUDE_FROM_ALL examples/live_events.cpp examples/access_benchmark.cpp)
target_link_libraries(live-events perf-cpp)
## One target for all examples
add_custom_target(examples)
add_dependencies(examples
single-thread inherit-thread multi-thread multi-cpu multi-process
instruction-pointer-sampling counter-sampling branch-sampling
address-sampling register-sampling multi-thread-sampling multi-cpu-sampling
multi-event-sampling amd-ibs-raw-sampling context-switch-sampling
memory-access-analyzer live-events)
endif()
#############################################################
# Unit tests definition #
#############################################################
if(BUILD_TESTS)
Include(FetchContent)
FetchContent_Declare(
Catch2
GIT_REPOSITORY https://github.com/catchorg/Catch2.git
GIT_TAG v3.4.0 # or a later release
)
FetchContent_MakeAvailable(Catch2)
set(PERF_CPP_TEST
test/counter_definition.cpp
test/metric.cpp
test/event_counter.cpp
)
add_executable(tests ${PERF_CPP_TEST})
target_link_libraries(tests PRIVATE Catch2::Catch2WithMain perf-cpp)
target_include_directories(tests PRIVATE Catch2::Catch2WithMain)
set_target_properties(tests
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}"
)
endif()
#############################################################
# Custom target to extract hardware events into CSV file #
#############################################################
add_custom_target(perf-list python3 ${CMAKE_SOURCE_DIR}/script/create_perf_list.py)
#############################################################
# Rules for installing the library #
#############################################################
if(PROJECT_IS_TOP_LEVEL)
include(CPack)
set(CMAKE_INSTALL_INCLUDEDIR include CACHE PATH "")
set(CMAKE_INSTALL_LIBRARY_DIR bin CACHE PATH "")
endif()
include(CMakePackageConfigHelpers)
include(GNUInstallDirs)
# Allow package maintainers to freely override the path for the configs
set(package perf-cpp)
install(DIRECTORY include/ DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" COMPONENT perf-cpp)
install(TARGETS perf-cpp EXPORT perf-cppTargets DESTINATION "${CMAKE_INSTALL_LIBRARY_DIR}")
write_basic_package_version_file(
"${package}ConfigVersion.cmake"
COMPATIBILITY SameMajorVersion
ARCH_INDEPENDENT
)
set(
perf-cpp_INSTALL_CMAKEDIR "${CMAKE_INSTALL_DATADIR}/${package}"
CACHE PATH "CMake package config location relative to the install prefix"
)
mark_as_advanced(perf-cpp_INSTALL_CMAKEDIR)
file(
WRITE
"${PROJECT_BINARY_DIR}/${package}Config.cmake"
"include(\"${CMAKE_INSTALL_PREFIX}/${perf-cpp_INSTALL_CMAKEDIR}/${package}Targets.cmake\")"
)
install(
FILES "${PROJECT_BINARY_DIR}/${package}Config.cmake"
DESTINATION "${perf-cpp_INSTALL_CMAKEDIR}"
COMPONENT perf-cpp
)
install(
FILES "${PROJECT_BINARY_DIR}/${package}ConfigVersion.cmake"
DESTINATION "${perf-cpp_INSTALL_CMAKEDIR}"
COMPONENT perf-cpp
)
install(
EXPORT perf-cppTargets
NAMESPACE perf-cpp::
DESTINATION "${perf-cpp_INSTALL_CMAKEDIR}"
COMPONENT perf-cpp
)