Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added benchmark test to rcl_logging_spdlog #52

Merged
merged 9 commits into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions rcl_logging_spdlog/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
ament_lint_auto_find_test_dependencies()

find_package(performance_test_fixture REQUIRED)
# Give cppcheck hints about macro definitions coming from outside this package
get_target_property(ament_cmake_cppcheck_ADDITIONAL_INCLUDE_DIRS
performance_test_fixture::performance_test_fixture INTERFACE_INCLUDE_DIRECTORIES)

find_package(ament_cmake_gtest REQUIRED)
find_package(rcpputils REQUIRED)
ament_add_gtest(test_logging_interface test/test_logging_interface.cpp)
Expand All @@ -49,6 +54,11 @@ if(BUILD_TESTING)
target_compile_definitions(test_logging_interface PUBLIC RCUTILS_ENABLE_FAULT_INJECTION)
ament_target_dependencies(test_logging_interface rcpputils)
endif()
add_performance_test(benchmark_logging_interface test/benchmark/benchmark_logging_interface.cpp)
if(TARGET benchmark_logging_interface)
target_include_directories(benchmark_logging_interface PUBLIC include)
target_link_libraries(benchmark_logging_interface ${PROJECT_NAME})
endif()
endif()

ament_export_dependencies(ament_cmake rcl_logging_interface rcutils spdlog_vendor spdlog)
Expand Down
1 change: 1 addition & 0 deletions rcl_logging_spdlog/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
<test_depend>performance_test_fixture</test_depend>
<test_depend>rcpputils</test_depend>

<member_of_group>rcl_logging_packages</member_of_group>
Expand Down
102 changes: 102 additions & 0 deletions rcl_logging_spdlog/test/benchmark/benchmark_logging_interface.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright 2020 Open Source Robotics Foundation, Inc.
//
// Licensed 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.


#include <rcutils/allocator.h>
#include <rcutils/logging.h>

#include <rcl_logging_interface/rcl_logging_interface.h>

#include <string>

#include "performance_test_fixture/performance_test_fixture.hpp"

using performance_test_fixture::PerformanceTest;

namespace
{
constexpr const uint64_t kSize = 4096;
}

class LoggingBenchmarkPerformance : public PerformanceTest
{
public:
void SetUp(benchmark::State & st)
{
rcl_logging_ret_t ret = rcl_logging_external_initialize(
nullptr,
rcutils_get_default_allocator());
if (ret != RCL_LOGGING_RET_OK) {
st.SkipWithError(rcutils_get_error_string().str);
}

data = std::string(kSize, '0');
PerformanceTest::SetUp(st);
}
void TearDown(benchmark::State & st)
{
PerformanceTest::TearDown(st);
rcl_logging_ret_t ret = rcl_logging_external_shutdown();
if (ret != RCL_LOGGING_RET_OK) {
st.SkipWithError(rcutils_get_error_string().str);
}
}

static void setLogLevel(int logger_level, benchmark::State & st)
{
rcl_logging_ret_t ret = rcl_logging_external_set_logger_level(nullptr, logger_level);
if (ret != RCL_LOGGING_RET_OK) {
st.SkipWithError(rcutils_get_error_string().str);
}
}

std::string data;
};

BENCHMARK_F(LoggingBenchmarkPerformance, log_level_hit)(benchmark::State & st)
{
setLogLevel(RCUTILS_LOG_SEVERITY_INFO, st);
for (auto _ : st) {
rcl_logging_external_log(RCUTILS_LOG_SEVERITY_INFO, nullptr, data.c_str());
}
}

BENCHMARK_F(LoggingBenchmarkPerformance, log_level_miss)(benchmark::State & st)
{
setLogLevel(RCUTILS_LOG_SEVERITY_INFO, st);
for (auto _ : st) {
rcl_logging_external_log(RCUTILS_LOG_SEVERITY_DEBUG, nullptr, data.c_str());
}
}

BENCHMARK_F(PerformanceTest, logging_initialize)(benchmark::State & st)
{
rcutils_allocator_t allocator = rcutils_get_default_allocator();
for (auto _ : st) {
rcl_logging_ret_t ret = rcl_logging_external_initialize(nullptr, allocator);
if (ret != RCL_LOGGING_RET_OK) {
st.SkipWithError(rcutils_get_error_string().str);
}
}
}

BENCHMARK_F(PerformanceTest, logging_shutdown)(benchmark::State & st)
{
for (auto _ : st) {
rcl_logging_ret_t ret = rcl_logging_external_shutdown();
if (ret != RCL_LOGGING_RET_OK) {
st.SkipWithError(rcutils_get_error_string().str);
}
}
}