From 3fdb201f592b4e68100a1fa6f2fc83f2721edada Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 Mar 2026 00:16:44 -1000 Subject: [PATCH] Suppress blocking warnings in scheduler benchmarks Under valgrind, 2000 inner iterations take long enough in wall clock to trigger WarnIfComponentBlockingGuard. Use a BenchComponent subclass that sets warn_if_blocking_over_ to UINT16_MAX to prevent log noise. --- tests/benchmarks/core/bench_scheduler.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/core/bench_scheduler.cpp b/tests/benchmarks/core/bench_scheduler.cpp index babcfc0be3..c32bfebcde 100644 --- a/tests/benchmarks/core/bench_scheduler.cpp +++ b/tests/benchmarks/core/bench_scheduler.cpp @@ -10,6 +10,15 @@ namespace esphome::benchmarks { // sub-microsecond benchmarks. static constexpr int kInnerIterations = 2000; +// Component subclass that suppresses blocking warnings. +// Under valgrind, 2000 inner iterations take long enough in wall clock +// to trigger WarnIfComponentBlockingGuard. Setting the threshold to max +// prevents log noise without affecting the benchmarked code path. +class BenchComponent : public Component { + public: + BenchComponent() { this->warn_if_blocking_over_ = UINT16_MAX; } +}; + // --- Scheduler fast path: no work to do --- static void Scheduler_Call_NoWork(benchmark::State &state) { @@ -30,7 +39,7 @@ BENCHMARK(Scheduler_Call_NoWork); static void Scheduler_Call_TimersNotDue(benchmark::State &state) { Scheduler scheduler; - Component dummy_component; + BenchComponent dummy_component; // Add some timeouts far in the future for (int i = 0; i < 10; i++) { @@ -54,7 +63,7 @@ BENCHMARK(Scheduler_Call_TimersNotDue); static void Scheduler_Call_5IntervalsFiring(benchmark::State &state) { Scheduler scheduler; - Component dummy_component; + BenchComponent dummy_component; int fire_count = 0; // Add 5 intervals with 1ms period — they fire every call when time advances @@ -82,7 +91,7 @@ BENCHMARK(Scheduler_Call_5IntervalsFiring); static void Scheduler_NextScheduleIn(benchmark::State &state) { Scheduler scheduler; - Component dummy_component; + BenchComponent dummy_component; // Add some timeouts for (int i = 0; i < 10; i++) {