From 7620049214051187263d69e0be100eeb40c6c489 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 17 Jun 2025 16:05:48 +0200 Subject: [PATCH] tweak --- esphome/core/runtime_stats.cpp | 4 ++-- esphome/core/runtime_stats.h | 20 +++++++++++--------- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/esphome/core/runtime_stats.cpp b/esphome/core/runtime_stats.cpp index 893f056856..b0cbe2fcdd 100644 --- a/esphome/core/runtime_stats.cpp +++ b/esphome/core/runtime_stats.cpp @@ -9,8 +9,8 @@ void RuntimeStatsCollector::record_component_time(Component *component, uint32_t if (!this->enabled_ || component == nullptr) return; - const char *component_source = component->get_component_source(); - this->component_stats_[component_source].record_time(duration_ms); + // Use component pointer directly as key - no string operations + this->component_stats_[component].record_time(duration_ms); // If next_log_time_ is 0, initialize it if (this->next_log_time_ == 0) { diff --git a/esphome/core/runtime_stats.h b/esphome/core/runtime_stats.h index c0b82ef114..cea11be873 100644 --- a/esphome/core/runtime_stats.h +++ b/esphome/core/runtime_stats.h @@ -74,7 +74,7 @@ class ComponentRuntimeStats { // For sorting components by run time struct ComponentStatPair { - std::string name; + Component *component; const ComponentRuntimeStats *stats; bool operator>(const ComponentStatPair &other) const { @@ -116,12 +116,13 @@ class RuntimeStatsCollector { // Log top components by period runtime for (const auto &it : stats_to_display) { - const std::string &source = it.name; + // Only get component name when actually logging + const char *source = it.component->get_component_source(); const ComponentRuntimeStats *stats = it.stats; - ESP_LOGI(RUNTIME_TAG, " %s: count=%" PRIu32 ", avg=%.2fms, max=%" PRIu32 "ms, total=%" PRIu32 "ms", - source.c_str(), stats->get_period_count(), stats->get_period_avg_time_ms(), - stats->get_period_max_time_ms(), stats->get_period_time_ms()); + ESP_LOGI(RUNTIME_TAG, " %s: count=%" PRIu32 ", avg=%.2fms, max=%" PRIu32 "ms, total=%" PRIu32 "ms", source, + stats->get_period_count(), stats->get_period_avg_time_ms(), stats->get_period_max_time_ms(), + stats->get_period_time_ms()); } // Log total stats since boot @@ -134,11 +135,12 @@ class RuntimeStatsCollector { }); for (const auto &it : stats_to_display) { - const std::string &source = it.name; + // Only get component name when actually logging + const char *source = it.component->get_component_source(); const ComponentRuntimeStats *stats = it.stats; - ESP_LOGI(RUNTIME_TAG, " %s: count=%" PRIu32 ", avg=%.2fms, max=%" PRIu32 "ms, total=%" PRIu32 "ms", - source.c_str(), stats->get_total_count(), stats->get_total_avg_time_ms(), stats->get_total_max_time_ms(), + ESP_LOGI(RUNTIME_TAG, " %s: count=%" PRIu32 ", avg=%.2fms, max=%" PRIu32 "ms, total=%" PRIu32 "ms", source, + stats->get_total_count(), stats->get_total_avg_time_ms(), stats->get_total_max_time_ms(), stats->get_total_time_ms()); } } @@ -149,7 +151,7 @@ class RuntimeStatsCollector { } } - std::map component_stats_; + std::map component_stats_; uint32_t log_interval_; uint32_t next_log_time_; bool enabled_;