Skip to content

Commit

Permalink
Add option WITH_BENCHMARK to disable building benchmarks (#1794)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomsonTan authored Nov 24, 2022
1 parent c1aa0b8 commit 3f0eee6
Show file tree
Hide file tree
Showing 16 changed files with 78 additions and 43 deletions.
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ option(WITH_NO_GETENV "Whether the platform supports environment variables" OFF)

option(BUILD_TESTING "Whether to enable tests" ON)

option(WITH_BENCHMARK "Whether to build benchmark program" ON)

option(BUILD_W3CTRACECONTEXT_TEST "Whether to build w3c trace context" OFF)

option(OTELCPP_MAINTAINER_MODE "Build in maintainer mode (-Wall -Werror)" OFF)
Expand Down Expand Up @@ -478,8 +480,10 @@ if(BUILD_TESTING)
message("GTEST_INCLUDE_DIRS = ${GTEST_INCLUDE_DIRS}")
message("GTEST_BOTH_LIBRARIES = ${GTEST_BOTH_LIBRARIES}")
enable_testing()
# Benchmark respects the CMAKE_PREFIX_PATH
find_package(benchmark CONFIG REQUIRED)
if(WITH_BENCHMARK)
# Benchmark respects the CMAKE_PREFIX_PATH
find_package(benchmark CONFIG REQUIRED)
endif()
endif()

include(CMakePackageConfigHelpers)
Expand Down
1 change: 1 addition & 0 deletions api/test/baggage/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ otel_cc_benchmark(
srcs = ["baggage_benchmark.cc"],
tags = [
"api",
"benchmark",
"test",
],
deps = ["//api"],
Expand Down
9 changes: 6 additions & 3 deletions api/test/baggage/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ foreach(testname baggage_test)
TEST_PREFIX baggage.
TEST_LIST ${testname})
endforeach()
add_executable(baggage_benchmark baggage_benchmark.cc)
target_link_libraries(baggage_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)

if(WITH_BENCHMARK)
add_executable(baggage_benchmark baggage_benchmark.cc)
target_link_libraries(baggage_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
endif()
add_subdirectory(propagation)
1 change: 1 addition & 0 deletions api/test/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ otel_cc_benchmark(
srcs = ["spinlock_benchmark.cc"],
tags = [
"api",
"benchmark",
"test",
],
deps = ["//api"],
Expand Down
8 changes: 5 additions & 3 deletions api/test/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ foreach(testname kv_properties_test string_util_test)
TEST_LIST ${testname})
endforeach()

add_executable(spinlock_benchmark spinlock_benchmark.cc)
target_link_libraries(spinlock_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
if(WITH_BENCHMARK)
add_executable(spinlock_benchmark spinlock_benchmark.cc)
target_link_libraries(spinlock_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
endif()
2 changes: 2 additions & 0 deletions api/test/trace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ otel_cc_benchmark(
srcs = ["span_id_benchmark.cc"],
tags = [
"api",
"benchmark",
"test",
"trace",
],
Expand All @@ -64,6 +65,7 @@ otel_cc_benchmark(
srcs = ["span_benchmark.cc"],
tags = [
"api",
"benchmark",
"test",
"trace",
],
Expand Down
14 changes: 8 additions & 6 deletions api/test/trace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ foreach(
TEST_LIST api_${testname})
endforeach()

add_executable(span_id_benchmark span_id_benchmark.cc)
target_link_libraries(span_id_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
add_executable(span_benchmark span_benchmark.cc)
target_link_libraries(span_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
if(WITH_BENCHMARK)
add_executable(span_id_benchmark span_id_benchmark.cc)
target_link_libraries(span_id_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
add_executable(span_benchmark span_benchmark.cc)
target_link_libraries(span_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
endif()
11 changes: 6 additions & 5 deletions exporters/etw/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ if(BUILD_TESTING)
add_executable(etw_tracer_test test/etw_tracer_test.cc)
add_executable(etw_logger_test test/etw_logger_test.cc)

add_executable(etw_perf_test test/etw_perf_test.cc)

target_link_libraries(etw_provider_test ${GTEST_BOTH_LIBRARIES}
opentelemetry_exporter_etw ${CMAKE_THREAD_LIBS_INIT})

Expand All @@ -43,9 +41,12 @@ if(BUILD_TESTING)
target_link_libraries(etw_logger_test ${GTEST_BOTH_LIBRARIES}
opentelemetry_exporter_etw ${CMAKE_THREAD_LIBS_INIT})

target_link_libraries(
etw_perf_test benchmark::benchmark ${GTEST_BOTH_LIBRARIES}
opentelemetry_exporter_etw ${CMAKE_THREAD_LIBS_INIT})
if(WITH_BENCHMARK)
add_executable(etw_perf_test test/etw_perf_test.cc)
target_link_libraries(
etw_perf_test benchmark::benchmark ${GTEST_BOTH_LIBRARIES}
opentelemetry_exporter_etw ${CMAKE_THREAD_LIBS_INIT})
endif()

gtest_add_tests(
TARGET etw_provider_test
Expand Down
1 change: 1 addition & 0 deletions exporters/otlp/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ otel_cc_benchmark(
name = "otlp_grpc_exporter_benchmark",
srcs = ["test/otlp_grpc_exporter_benchmark.cc"],
tags = [
"benchmark",
"otlp",
"otlp_grpc",
"test",
Expand Down
15 changes: 12 additions & 3 deletions sdk/test/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ cc_test(
otel_cc_benchmark(
name = "random_benchmark",
srcs = ["random_benchmark.cc"],
tags = ["test"],
tags = [
"benchmark",
"test",
],
deps = ["//sdk/src/common:random"],
)

Expand Down Expand Up @@ -82,7 +85,10 @@ cc_library(
otel_cc_benchmark(
name = "circular_buffer_benchmark",
srcs = ["circular_buffer_benchmark.cc"],
tags = ["test"],
tags = [
"benchmark",
"test",
],
deps = [
":baseline_circular_buffer",
"//sdk:headers",
Expand Down Expand Up @@ -145,7 +151,10 @@ cc_test(
otel_cc_benchmark(
name = "attributemap_hash_benchmark",
srcs = ["attributemap_hash_benchmark.cc"],
tags = ["test"],
tags = [
"benchmark",
"test",
],
deps = [
"//api",
"//sdk:headers",
Expand Down
20 changes: 11 additions & 9 deletions sdk/test/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,16 @@ add_executable(random_fork_test random_fork_test.cc)
target_link_libraries(random_fork_test opentelemetry_common)
add_test(random_fork_test random_fork_test)

add_executable(random_benchmark random_benchmark.cc)
target_link_libraries(random_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common)
if(WITH_BENCHMARK)
add_executable(random_benchmark random_benchmark.cc)
target_link_libraries(random_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common)

add_executable(circular_buffer_benchmark circular_buffer_benchmark.cc)
target_link_libraries(circular_buffer_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)
add_executable(circular_buffer_benchmark circular_buffer_benchmark.cc)
target_link_libraries(circular_buffer_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_api)

add_executable(attributemap_hash_benchmark attributemap_hash_benchmark.cc)
target_link_libraries(attributemap_hash_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common)
add_executable(attributemap_hash_benchmark attributemap_hash_benchmark.cc)
target_link_libraries(attributemap_hash_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common)
endif()
2 changes: 0 additions & 2 deletions sdk/test/instrumentationscope/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark")

cc_test(
name = "instrumentationscope_test",
srcs = [
Expand Down
2 changes: 2 additions & 0 deletions sdk/test/metrics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ otel_cc_benchmark(
"attributes_processor_benchmark.cc",
],
tags = [
"benchmark",
"metrics",
"test",
],
Expand All @@ -256,6 +257,7 @@ otel_cc_benchmark(
"attributes_hashmap_benchmark.cc",
],
tags = [
"benchmark",
"metrics",
"test",
],
Expand Down
15 changes: 9 additions & 6 deletions sdk/test/metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,15 @@ foreach(
TEST_LIST ${testname})
endforeach()

add_executable(attributes_processor_benchmark attributes_processor_benchmark.cc)
target_link_libraries(attributes_processor_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common)
if(WITH_BENCHMARK)
add_executable(attributes_processor_benchmark
attributes_processor_benchmark.cc)
target_link_libraries(attributes_processor_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common)

add_executable(attributes_hashmap_benchmark attributes_hashmap_benchmark.cc)
target_link_libraries(attributes_hashmap_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common)
add_executable(attributes_hashmap_benchmark attributes_hashmap_benchmark.cc)
target_link_libraries(attributes_hashmap_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common)
endif()

add_subdirectory(exemplar)
1 change: 1 addition & 0 deletions sdk/test/trace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ otel_cc_benchmark(
name = "sampler_benchmark",
srcs = ["sampler_benchmark.cc"],
tags = [
"benchmark",
"test",
"trace",
],
Expand Down
11 changes: 7 additions & 4 deletions sdk/test/trace/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ foreach(
TEST_LIST ${testname})
endforeach()

add_executable(sampler_benchmark sampler_benchmark.cc)
target_link_libraries(
sampler_benchmark benchmark::benchmark ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_trace opentelemetry_resources opentelemetry_exporter_in_memory)
if(WITH_BENCHMARK)
add_executable(sampler_benchmark sampler_benchmark.cc)
target_link_libraries(
sampler_benchmark benchmark::benchmark ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_trace opentelemetry_resources
opentelemetry_exporter_in_memory)
endif()

0 comments on commit 3f0eee6

Please sign in to comment.