From fa8dd952e279a87f6027ddd2e2119bf2ae2f9943 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 2 Sep 2024 16:39:21 +0200 Subject: [PATCH 1/2] bench: Use LogInfo instead of the deprecated alias LogPrintf --- src/bench/logging.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bench/logging.cpp b/src/bench/logging.cpp index 86891af8fe0..9fd203d01d9 100644 --- a/src/bench/logging.cpp +++ b/src/bench/logging.cpp @@ -64,21 +64,21 @@ static void LogPrintfCategoryWithoutThreadNames(benchmark::Bench& bench) }); } -static void LogPrintfWithThreadNames(benchmark::Bench& bench) +static void LogWithThreadNames(benchmark::Bench& bench) { - Logging(bench, {"-logthreadnames=1"}, [] { LogPrintf("%s\n", "test"); }); + Logging(bench, {"-logthreadnames=1"}, [] { LogInfo("%s\n", "test"); }); } -static void LogPrintfWithoutThreadNames(benchmark::Bench& bench) +static void LogWithoutThreadNames(benchmark::Bench& bench) { - Logging(bench, {"-logthreadnames=0"}, [] { LogPrintf("%s\n", "test"); }); + Logging(bench, {"-logthreadnames=0"}, [] { LogInfo("%s\n", "test"); }); } static void LogWithoutWriteToFile(benchmark::Bench& bench) { // Disable writing the log to a file, as used for unit tests and fuzzing in `MakeNoLogFileContext`. Logging(bench, {"-nodebuglogfile", "-debug=1"}, [] { - LogPrintf("%s\n", "test"); + LogInfo("%s\n", "test"); LogDebug(BCLog::NET, "%s\n", "test"); }); } @@ -89,6 +89,6 @@ BENCHMARK(LogWithDebug, benchmark::PriorityLevel::HIGH); BENCHMARK(LogWithoutDebug, benchmark::PriorityLevel::HIGH); BENCHMARK(LogPrintfCategoryWithThreadNames, benchmark::PriorityLevel::HIGH); BENCHMARK(LogPrintfCategoryWithoutThreadNames, benchmark::PriorityLevel::HIGH); -BENCHMARK(LogPrintfWithThreadNames, benchmark::PriorityLevel::HIGH); -BENCHMARK(LogPrintfWithoutThreadNames, benchmark::PriorityLevel::HIGH); +BENCHMARK(LogWithThreadNames, benchmark::PriorityLevel::HIGH); +BENCHMARK(LogWithoutThreadNames, benchmark::PriorityLevel::HIGH); BENCHMARK(LogWithoutWriteToFile, benchmark::PriorityLevel::HIGH); From fadbcd51fc77a3f4e877851463f3c7425fb751d2 Mon Sep 17 00:00:00 2001 From: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> Date: Mon, 2 Sep 2024 14:34:28 +0200 Subject: [PATCH 2/2] bench: Remove redundant logging benchmarks LogPrint*ThreadNames is redundant with LogWith(out)ThreadNames, because they all measure toggling the thread names (and check that it has no effect on performance). This also allows to remove unused and deprecated macros. --- src/bench/logging.cpp | 30 ------------------------------ src/logging.h | 1 - src/test/logging_tests.cpp | 2 -- test/lint/lint-format-strings.py | 1 - 4 files changed, 34 deletions(-) diff --git a/src/bench/logging.cpp b/src/bench/logging.cpp index 9fd203d01d9..3bf2b7edb29 100644 --- a/src/bench/logging.cpp +++ b/src/bench/logging.cpp @@ -28,18 +28,6 @@ static void Logging(benchmark::Bench& bench, const std::vector& ext bench.run([&] { log(); }); } -static void LogPrintLevelWithThreadNames(benchmark::Bench& bench) -{ - Logging(bench, {"-logthreadnames=1", "-debug=net"}, [] { - LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", "test"); }); -} - -static void LogPrintLevelWithoutThreadNames(benchmark::Bench& bench) -{ - Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { - LogPrintLevel(BCLog::NET, BCLog::Level::Error, "%s\n", "test"); }); -} - static void LogWithDebug(benchmark::Bench& bench) { Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); }); @@ -50,20 +38,6 @@ static void LogWithoutDebug(benchmark::Bench& bench) Logging(bench, {"-logthreadnames=0", "-debug=0"}, [] { LogDebug(BCLog::NET, "%s\n", "test"); }); } -static void LogPrintfCategoryWithThreadNames(benchmark::Bench& bench) -{ - Logging(bench, {"-logthreadnames=1", "-debug=net"}, [] { - LogPrintfCategory(BCLog::NET, "%s\n", "test"); - }); -} - -static void LogPrintfCategoryWithoutThreadNames(benchmark::Bench& bench) -{ - Logging(bench, {"-logthreadnames=0", "-debug=net"}, [] { - LogPrintfCategory(BCLog::NET, "%s\n", "test"); - }); -} - static void LogWithThreadNames(benchmark::Bench& bench) { Logging(bench, {"-logthreadnames=1"}, [] { LogInfo("%s\n", "test"); }); @@ -83,12 +57,8 @@ static void LogWithoutWriteToFile(benchmark::Bench& bench) }); } -BENCHMARK(LogPrintLevelWithThreadNames, benchmark::PriorityLevel::HIGH); -BENCHMARK(LogPrintLevelWithoutThreadNames, benchmark::PriorityLevel::HIGH); BENCHMARK(LogWithDebug, benchmark::PriorityLevel::HIGH); BENCHMARK(LogWithoutDebug, benchmark::PriorityLevel::HIGH); -BENCHMARK(LogPrintfCategoryWithThreadNames, benchmark::PriorityLevel::HIGH); -BENCHMARK(LogPrintfCategoryWithoutThreadNames, benchmark::PriorityLevel::HIGH); BENCHMARK(LogWithThreadNames, benchmark::PriorityLevel::HIGH); BENCHMARK(LogWithoutThreadNames, benchmark::PriorityLevel::HIGH); BENCHMARK(LogWithoutWriteToFile, benchmark::PriorityLevel::HIGH); diff --git a/src/logging.h b/src/logging.h index 032f4d883b9..d583419d3a5 100644 --- a/src/logging.h +++ b/src/logging.h @@ -273,7 +273,6 @@ static inline void LogPrintf_(std::string_view logging_function, std::string_vie // Deprecated unconditional logging. #define LogPrintf(...) LogInfo(__VA_ARGS__) -#define LogPrintfCategory(category, ...) LogPrintLevel_(category, BCLog::Level::Info, __VA_ARGS__) // Use a macro instead of a function for conditional logging to prevent // evaluating arguments when logging for the category is not enabled. diff --git a/src/test/logging_tests.cpp b/src/test/logging_tests.cpp index fdac760d7f7..a6fd44e395a 100644 --- a/src/test/logging_tests.cpp +++ b/src/test/logging_tests.cpp @@ -116,7 +116,6 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacrosDeprecated, LogSetup) LogPrintLevel(BCLog::NET, BCLog::Level::Info, "foo8: %s\n", "bar8"); LogPrintLevel(BCLog::NET, BCLog::Level::Warning, "foo9: %s\n", "bar9"); LogPrintLevel(BCLog::NET, BCLog::Level::Error, "foo10: %s\n", "bar10"); - LogPrintfCategory(BCLog::VALIDATION, "foo11: %s\n", "bar11"); std::ifstream file{tmp_log_path}; std::vector log_lines; for (std::string log; std::getline(file, log);) { @@ -128,7 +127,6 @@ BOOST_FIXTURE_TEST_CASE(logging_LogPrintMacrosDeprecated, LogSetup) "[net:info] foo8: bar8", "[net:warning] foo9: bar9", "[net:error] foo10: bar10", - "[validation:info] foo11: bar11", }; BOOST_CHECK_EQUAL_COLLECTIONS(log_lines.begin(), log_lines.end(), expected.begin(), expected.end()); } diff --git a/test/lint/lint-format-strings.py b/test/lint/lint-format-strings.py index 002c59e9a38..9f5e0f312ec 100755 --- a/test/lint/lint-format-strings.py +++ b/test/lint/lint-format-strings.py @@ -26,7 +26,6 @@ FUNCTION_NAMES_AND_NUMBER_OF_LEADING_ARGUMENTS = [ 'LogDebug,1', 'LogTrace,1', 'LogPrintf,0', - 'LogPrintfCategory,1', 'LogPrintLevel,2', 'printf,0', 'snprintf,2',