From 07a4f6f53c16971d6f2287d28d4caaa8768a4f07 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Tue, 8 Jul 2025 09:40:12 -0600 Subject: [PATCH] fixes --- esphome/components/runtime_stats/runtime_stats.cpp | 8 ++++---- esphome/components/runtime_stats/runtime_stats.h | 14 +++++++++----- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/esphome/components/runtime_stats/runtime_stats.cpp b/esphome/components/runtime_stats/runtime_stats.cpp index 72411ffd6f..9d87534fec 100644 --- a/esphome/components/runtime_stats/runtime_stats.cpp +++ b/esphome/components/runtime_stats/runtime_stats.cpp @@ -58,10 +58,10 @@ void RuntimeStatsCollector::log_stats_() { // Log top components by period runtime for (const auto &it : stats_to_display) { - const std::string &source = it.name; + const char *source = it.name; const ComponentRuntimeStats *stats = it.stats; - ESP_LOGI(TAG, " %s: count=%" PRIu32 ", avg=%.2fms, max=%" PRIu32 "ms, total=%" PRIu32 "ms", source.c_str(), + ESP_LOGI(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()); } @@ -76,10 +76,10 @@ void RuntimeStatsCollector::log_stats_() { }); for (const auto &it : stats_to_display) { - const std::string &source = it.name; + const char *source = it.name; const ComponentRuntimeStats *stats = it.stats; - ESP_LOGI(TAG, " %s: count=%" PRIu32 ", avg=%.2fms, max=%" PRIu32 "ms, total=%" PRIu32 "ms", source.c_str(), + ESP_LOGI(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()); } diff --git a/esphome/components/runtime_stats/runtime_stats.h b/esphome/components/runtime_stats/runtime_stats.h index 5f258469a1..36572e2094 100644 --- a/esphome/components/runtime_stats/runtime_stats.h +++ b/esphome/components/runtime_stats/runtime_stats.h @@ -5,9 +5,9 @@ #ifdef USE_RUNTIME_STATS #include -#include #include #include +#include #include "esphome/core/helpers.h" #include "esphome/core/log.h" @@ -79,7 +79,7 @@ class ComponentRuntimeStats { // For sorting components by run time struct ComponentStatPair { - std::string name; + const char *name; const ComponentRuntimeStats *stats; bool operator>(const ComponentStatPair &other) const { @@ -109,9 +109,13 @@ class RuntimeStatsCollector { } } - // Back to string keys, but we'll cache the source name per component - std::map component_stats_; - std::map component_names_cache_; + // Use const char* keys for efficiency + // Custom comparator for const char* keys in map + struct CStrCompare { + bool operator()(const char *a, const char *b) const { return std::strcmp(a, b) < 0; } + }; + std::map component_stats_; + std::map component_names_cache_; uint32_t log_interval_; uint32_t next_log_time_; };