Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit a793d01

Browse files
meastpg-easy
authored andcommitted
CMake: Add Google Benchmark (with FetchContent) (#296)
1 parent 1f12445 commit a793d01

File tree

8 files changed

+77
-7
lines changed

8 files changed

+77
-7
lines changed

.appveyor.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ test_script:
3131
3232
& $_.FullName $cmdArgList
3333
}
34+
Get-ChildItem -Recurse -Path $env:APPVEYOR_BUILD_FOLDER -Filter "*_benchmark.exe" | ForEach-Object {
35+
Write-Output $_.FullName
36+
37+
& $_.FullName
38+
}
3439
3540
on_finish:
3641
- ps: |

cmake/OpenCensusDeps.cmake

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,17 @@ fetchcontent_declare(abseil
2323
GIT_REPOSITORY
2424
https://github.com/abseil/abseil-cpp
2525
GIT_TAG
26-
master)
26+
2c8421e1c6cef0da9e8a20b01c15256ec9ec116d)
2727
fetchcontent_declare(prometheus
2828
GIT_REPOSITORY
2929
https://github.com/jupp0r/prometheus-cpp
3030
GIT_TAG
3131
master)
32+
fetchcontent_declare(benchmark
33+
GIT_REPOSITORY
34+
https://github.com/google/benchmark
35+
GIT_TAG
36+
master)
3237

3338
fetchcontent_getproperties(googletest)
3439
if(BUILD_TESTING)
@@ -72,3 +77,16 @@ if(NOT prometheus_POPULATED)
7277
add_subdirectory(${prometheus_SOURCE_DIR} ${prometheus_BINARY_DIR}
7378
EXCLUDE_FROM_ALL)
7479
endif()
80+
81+
fetchcontent_getproperties(benchmark)
82+
if(NOT benchmark_POPULATED)
83+
set(BENCHMARK_ENABLE_TESTING OFF
84+
CACHE BOOL "Enable testing of the benchmark library."
85+
FORCE)
86+
set(BENCHMARK_ENABLE_GTEST_TESTS OFF
87+
CACHE BOOL "Enable building the unit tests which depend on gtest"
88+
FORCE)
89+
fetchcontent_populate(benchmark)
90+
add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR}
91+
EXCLUDE_FROM_ALL)
92+
endif()

cmake/OpenCensusHelpers.cmake

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,19 @@ function(opencensus_test NAME SRC)
3838
endif()
3939
endfunction()
4040

41+
# Helper function like bazel's cc_benchmark. Usage:
42+
#
43+
# opencensus_benchmark(trace_some_benchmark internal/some_benchmark.cc dep1
44+
# dep2...)
45+
function(opencensus_benchmark NAME SRC)
46+
if(BUILD_TESTING)
47+
set(_NAME "opencensus_${NAME}")
48+
add_executable(${_NAME} ${SRC})
49+
prepend_opencensus(DEPS "${ARGN}")
50+
target_link_libraries(${_NAME} "${DEPS}" benchmark)
51+
endif()
52+
endfunction()
53+
4154
# Helper function like bazel's cc_library. Libraries are namespaced as
4255
# opencensus_* and public libraries are also aliased as opencensus-cpp::*.
4356
function(opencensus_lib NAME)

opencensus/common/internal/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@ opencensus_lib(common_string_vector_hash)
3232

3333
opencensus_test(common_random_test random_test.cc common_random)
3434

35+
opencensus_benchmark(common_random_benchmark random_benchmark.cc common_random)
36+
3537
opencensus_test(common_stats_object_test
3638
stats_object_test.cc
3739
common_stats_object
3840
absl::strings
3941
absl::span)
40-
41-
# TODO: random_benchmark

opencensus/context/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,5 @@ opencensus_test(context_context_test
3131

3232
opencensus_test(context_with_context_test internal/with_context_test.cc context)
3333

34-
# TODO: context_benchmark
34+
opencensus_benchmark(context_context_benchmark internal/context_benchmark.cc
35+
context)

opencensus/stats/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,10 @@ opencensus_test(stats_view_data_impl_test
116116
stats_core
117117
absl::time)
118118

119-
# TODO: benchmarks
119+
opencensus_benchmark(stats_stats_manager_benchmark
120+
internal/stats_manager_benchmark.cc
121+
stats_core
122+
stats_recording
123+
absl::memory
124+
absl::strings
125+
absl::time)

opencensus/tags/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,7 @@ opencensus_test(tags_with_tag_map_test
5757
tags_with_tag_map
5858
context)
5959

60-
# TODO: benchmarks
60+
opencensus_benchmark(tags_tag_map_benchmark
61+
internal/tag_map_benchmark.cc
62+
tags
63+
absl::strings)

opencensus/trace/CMakeLists.txt

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,28 @@ opencensus_test(trace_with_span_test
190190
trace_with_span
191191
context)
192192

193-
# TODO: benchmarks
193+
opencensus_benchmark(trace_attribute_value_ref_benchmark
194+
internal/attribute_value_ref_benchmark.cc trace)
195+
196+
opencensus_benchmark(trace_cloud_trace_context_benchmark
197+
internal/cloud_trace_context_benchmark.cc
198+
trace_cloud_trace_context)
199+
200+
opencensus_benchmark(trace_grpc_trace_bin_benchmark
201+
internal/grpc_trace_bin_benchmark.cc trace_grpc_trace_bin)
202+
203+
opencensus_benchmark(trace_span_benchmark
204+
internal/span_benchmark.cc
205+
trace_span_context
206+
trace)
207+
208+
opencensus_benchmark(trace_span_id_benchmark internal/span_id_benchmark.cc
209+
trace_span_context)
210+
211+
opencensus_benchmark(trace_context_benchmark internal/trace_context_benchmark.cc
212+
trace_trace_context)
213+
214+
opencensus_benchmark(trace_with_span_benchmark
215+
internal/with_span_benchmark.cc
216+
trace
217+
trace_with_span)

0 commit comments

Comments
 (0)