mirror of
https://github.com/esphome/esphome.git
synced 2026-06-01 09:25:09 +08:00
[core] Reduce runtime_stats measurement overhead (#15359)
This commit is contained in:
@@ -519,13 +519,6 @@ WarnIfComponentBlockingGuard::warn_blocking(Component *component, uint32_t block
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_RUNTIME_STATS
|
||||
void WarnIfComponentBlockingGuard::record_runtime_stats_() {
|
||||
uint32_t duration_us = micros() - this->started_us_;
|
||||
this->component_->runtime_stats_.record_time(duration_us);
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef USE_SETUP_PRIORITY_OVERRIDE
|
||||
void clear_setup_priority_overrides() {
|
||||
// Free the setup priority map completely
|
||||
|
||||
@@ -630,17 +630,17 @@ class WarnIfComponentBlockingGuard {
|
||||
{
|
||||
}
|
||||
|
||||
// Finish the timing operation and return the current time
|
||||
// Finish the timing operation and return the current time (millis)
|
||||
// Inlined: the fast path is just millis() + subtract + compare
|
||||
inline uint32_t HOT finish() {
|
||||
uint32_t curr_time = millis();
|
||||
uint32_t blocking_time = curr_time - this->started_;
|
||||
#ifdef USE_RUNTIME_STATS
|
||||
this->record_runtime_stats_();
|
||||
this->component_->runtime_stats_.record_time(micros() - this->started_us_);
|
||||
#endif
|
||||
uint32_t curr_time = millis();
|
||||
#ifndef USE_BENCHMARK
|
||||
// Fast path: compare against constant threshold in ms (computed at compile time from centiseconds)
|
||||
static constexpr uint32_t WARN_IF_BLOCKING_OVER_MS = static_cast<uint32_t>(WARN_IF_BLOCKING_OVER_CS) * 10U;
|
||||
uint32_t blocking_time = curr_time - this->started_;
|
||||
if (blocking_time > WARN_IF_BLOCKING_OVER_MS) [[unlikely]] {
|
||||
warn_blocking(this->component_, blocking_time);
|
||||
}
|
||||
@@ -655,7 +655,6 @@ class WarnIfComponentBlockingGuard {
|
||||
Component *component_;
|
||||
#ifdef USE_RUNTIME_STATS
|
||||
uint32_t started_us_;
|
||||
void record_runtime_stats_();
|
||||
#endif
|
||||
|
||||
private:
|
||||
|
||||
Reference in New Issue
Block a user