From 452f51a31c34f85dcb750c592407ad533d207032 Mon Sep 17 00:00:00 2001 From: Chris McFarlen Date: Wed, 30 Aug 2023 11:08:11 -0500 Subject: [PATCH] cmake: Add support for building benchmarks --- CMakeLists.txt | 14 +++++++---- tools/benchmark/CMakeLists.txt | 44 ++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+), 4 deletions(-) create mode 100644 tools/benchmark/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 3d1ec272f51..2b76be17164 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -56,6 +56,7 @@ option(ENABLE_JEMALLOC "Use jemalloc (default OFF)") option(ENABLE_LUAJIT "Use LuaJIT (default OFF)") option(ENABLE_MIMALLOC "Use mimalloc (default OFF)") option(ENABLE_DOCS "Build docs (default OFF)") +option(ENABLE_BENCHMARKS "Build benchmarks (default OFF)") if(CMAKE_SYSTEM_NAME STREQUAL Linux) set(DEFAULT_POSIX_CAP ON) @@ -262,7 +263,7 @@ check_symbol_exists(eventfd sys/eventfd.h HAVE_EVENTFD) option(USE_IOURING "Use experimental io_uring (linux only)" 0) if (HAVE_IOURING AND USE_IOURING) - message(Using io_uring) + message(STATUS "Using io_uring") set(TS_USE_LINUX_IO_URING 1) endif(HAVE_IOURING AND USE_IOURING) @@ -308,7 +309,7 @@ set(CATCH_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/lib/catch2) include(CTest) set(TS_HAS_TESTS ${BUILD_REGRESSION_TESTING}) -message("Configuring for ${HOST_OS}") +message(STATUS "Configuring for ${HOST_OS}") if(HOST_OS STREQUAL "linux") set(CMAKE_THREAD_LIBS_INIT "-lpthread") @@ -409,6 +410,11 @@ if(ENABLE_DOCS) add_subdirectory(doc) endif() +if(ENABLE_BENCHMARKS) + message(STATUS "Building benchmarks in tools/benchmark") + add_subdirectory(tools/benchmark) +endif() + add_custom_target(clang-format-install COMMAND ${CMAKE_SOURCE_DIR}/tools/clang-format.sh --install WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} @@ -459,7 +465,7 @@ add_custom_target(format ) if(NOT EXISTS ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit) - message("Installing github hook") + message(STATUS "Installing github hook") configure_file(${CMAKE_SOURCE_DIR}/tools/git/pre-commit ${CMAKE_SOURCE_DIR}/.git/hooks/pre-commit COPYONLY) endif() @@ -469,7 +475,7 @@ install(DIRECTORY DESTINATION var/trafficserver) # Display build summary include(CMakePrintHelpers) -message("Build Summary:") +message(STATUS "Build Summary:") cmake_print_variables(CMAKE_SYSTEM_NAME) cmake_print_variables(CMAKE_SYSTEM_VERSION) cmake_print_variables(CMAKE_SYSTEM_PROCESSOR) diff --git a/tools/benchmark/CMakeLists.txt b/tools/benchmark/CMakeLists.txt new file mode 100644 index 00000000000..8e73c0681bc --- /dev/null +++ b/tools/benchmark/CMakeLists.txt @@ -0,0 +1,44 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# +####################### + +add_executable(benchmark_FreeList benchmark_FreeList.cc) +target_link_libraries(benchmark_FreeList + PRIVATE + catch2::catch2 + ts::tscore + libswoc +) +if(TS_USE_HWLOC) + target_link_libraries(benchmark_FreeList PRIVATE hwloc) +endif() + +add_executable(benchmark_ProxyAllocator benchmark_ProxyAllocator.cc) +target_link_libraries(benchmark_ProxyAllocator + PRIVATE + catch2::catch2 + ts::tscore + ts::inkevent + libswoc +) + +add_executable(benchmark_SharedMutex benchmark_SharedMutex.cc) +target_link_libraries(benchmark_SharedMutex + PRIVATE + catch2::catch2 + ts::tscore + libswoc +)