diff --git a/.appveyor.yml b/.appveyor.yml index 4e2c99ee..f2b321c9 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -31,6 +31,11 @@ test_script: & $_.FullName $cmdArgList } + Get-ChildItem -Recurse -Path $env:APPVEYOR_BUILD_FOLDER -Filter "*_benchmark.exe" | ForEach-Object { + Write-Output $_.FullName + + & $_.FullName + } on_finish: - ps: | diff --git a/cmake/OpenCensusDeps.cmake b/cmake/OpenCensusDeps.cmake index 0cac7250..5bf475ca 100644 --- a/cmake/OpenCensusDeps.cmake +++ b/cmake/OpenCensusDeps.cmake @@ -23,12 +23,17 @@ fetchcontent_declare(abseil GIT_REPOSITORY https://github.com/abseil/abseil-cpp GIT_TAG - master) + 2c8421e1c6cef0da9e8a20b01c15256ec9ec116d) fetchcontent_declare(prometheus GIT_REPOSITORY https://github.com/jupp0r/prometheus-cpp GIT_TAG master) +fetchcontent_declare(benchmark + GIT_REPOSITORY + https://github.com/google/benchmark + GIT_TAG + master) fetchcontent_getproperties(googletest) if(BUILD_TESTING) @@ -72,3 +77,16 @@ if(NOT prometheus_POPULATED) add_subdirectory(${prometheus_SOURCE_DIR} ${prometheus_BINARY_DIR} EXCLUDE_FROM_ALL) endif() + +fetchcontent_getproperties(benchmark) +if(NOT benchmark_POPULATED) + set(BENCHMARK_ENABLE_TESTING OFF + CACHE BOOL "Enable testing of the benchmark library." + FORCE) + set(BENCHMARK_ENABLE_GTEST_TESTS OFF + CACHE BOOL "Enable building the unit tests which depend on gtest" + FORCE) + fetchcontent_populate(benchmark) + add_subdirectory(${benchmark_SOURCE_DIR} ${benchmark_BINARY_DIR} + EXCLUDE_FROM_ALL) +endif() diff --git a/cmake/OpenCensusHelpers.cmake b/cmake/OpenCensusHelpers.cmake index d511ac09..5f7b9ce5 100644 --- a/cmake/OpenCensusHelpers.cmake +++ b/cmake/OpenCensusHelpers.cmake @@ -38,6 +38,19 @@ function(opencensus_test NAME SRC) endif() endfunction() +# Helper function like bazel's cc_benchmark. Usage: +# +# opencensus_benchmark(trace_some_benchmark internal/some_benchmark.cc dep1 +# dep2...) +function(opencensus_benchmark NAME SRC) + if(BUILD_TESTING) + set(_NAME "opencensus_${NAME}") + add_executable(${_NAME} ${SRC}) + prepend_opencensus(DEPS "${ARGN}") + target_link_libraries(${_NAME} "${DEPS}" benchmark) + endif() +endfunction() + # Helper function like bazel's cc_library. Libraries are namespaced as # opencensus_* and public libraries are also aliased as opencensus-cpp::*. function(opencensus_lib NAME) diff --git a/opencensus/common/internal/CMakeLists.txt b/opencensus/common/internal/CMakeLists.txt index b6ee2671..c18859dd 100644 --- a/opencensus/common/internal/CMakeLists.txt +++ b/opencensus/common/internal/CMakeLists.txt @@ -32,10 +32,10 @@ opencensus_lib(common_string_vector_hash) opencensus_test(common_random_test random_test.cc common_random) +opencensus_benchmark(common_random_benchmark random_benchmark.cc common_random) + opencensus_test(common_stats_object_test stats_object_test.cc common_stats_object absl::strings absl::span) - -# TODO: random_benchmark diff --git a/opencensus/context/CMakeLists.txt b/opencensus/context/CMakeLists.txt index 589a7209..525885b9 100644 --- a/opencensus/context/CMakeLists.txt +++ b/opencensus/context/CMakeLists.txt @@ -31,4 +31,5 @@ opencensus_test(context_context_test opencensus_test(context_with_context_test internal/with_context_test.cc context) -# TODO: context_benchmark +opencensus_benchmark(context_context_benchmark internal/context_benchmark.cc + context) diff --git a/opencensus/stats/CMakeLists.txt b/opencensus/stats/CMakeLists.txt index 6194fedf..bcb5870b 100644 --- a/opencensus/stats/CMakeLists.txt +++ b/opencensus/stats/CMakeLists.txt @@ -116,4 +116,10 @@ opencensus_test(stats_view_data_impl_test stats_core absl::time) -# TODO: benchmarks +opencensus_benchmark(stats_stats_manager_benchmark + internal/stats_manager_benchmark.cc + stats_core + stats_recording + absl::memory + absl::strings + absl::time) diff --git a/opencensus/tags/CMakeLists.txt b/opencensus/tags/CMakeLists.txt index 26581460..dbc4c9bd 100644 --- a/opencensus/tags/CMakeLists.txt +++ b/opencensus/tags/CMakeLists.txt @@ -57,4 +57,7 @@ opencensus_test(tags_with_tag_map_test tags_with_tag_map context) -# TODO: benchmarks +opencensus_benchmark(tags_tag_map_benchmark + internal/tag_map_benchmark.cc + tags + absl::strings) diff --git a/opencensus/trace/CMakeLists.txt b/opencensus/trace/CMakeLists.txt index a0f77232..ecbc107c 100644 --- a/opencensus/trace/CMakeLists.txt +++ b/opencensus/trace/CMakeLists.txt @@ -190,4 +190,28 @@ opencensus_test(trace_with_span_test trace_with_span context) -# TODO: benchmarks +opencensus_benchmark(trace_attribute_value_ref_benchmark + internal/attribute_value_ref_benchmark.cc trace) + +opencensus_benchmark(trace_cloud_trace_context_benchmark + internal/cloud_trace_context_benchmark.cc + trace_cloud_trace_context) + +opencensus_benchmark(trace_grpc_trace_bin_benchmark + internal/grpc_trace_bin_benchmark.cc trace_grpc_trace_bin) + +opencensus_benchmark(trace_span_benchmark + internal/span_benchmark.cc + trace_span_context + trace) + +opencensus_benchmark(trace_span_id_benchmark internal/span_id_benchmark.cc + trace_span_context) + +opencensus_benchmark(trace_context_benchmark internal/trace_context_benchmark.cc + trace_trace_context) + +opencensus_benchmark(trace_with_span_benchmark + internal/with_span_benchmark.cc + trace + trace_with_span)