mirror of
https://github.com/esphome/esphome.git
synced 2025-08-05 18:07:47 +00:00
fixes
This commit is contained in:
parent
7d2726ab21
commit
07a4f6f53c
@ -58,10 +58,10 @@ void RuntimeStatsCollector::log_stats_() {
|
|||||||
|
|
||||||
// Log top components by period runtime
|
// Log top components by period runtime
|
||||||
for (const auto &it : stats_to_display) {
|
for (const auto &it : stats_to_display) {
|
||||||
const std::string &source = it.name;
|
const char *source = it.name;
|
||||||
const ComponentRuntimeStats *stats = it.stats;
|
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_count(), stats->get_period_avg_time_ms(), stats->get_period_max_time_ms(),
|
||||||
stats->get_period_time_ms());
|
stats->get_period_time_ms());
|
||||||
}
|
}
|
||||||
@ -76,10 +76,10 @@ void RuntimeStatsCollector::log_stats_() {
|
|||||||
});
|
});
|
||||||
|
|
||||||
for (const auto &it : stats_to_display) {
|
for (const auto &it : stats_to_display) {
|
||||||
const std::string &source = it.name;
|
const char *source = it.name;
|
||||||
const ComponentRuntimeStats *stats = it.stats;
|
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_count(), stats->get_total_avg_time_ms(), stats->get_total_max_time_ms(),
|
||||||
stats->get_total_time_ms());
|
stats->get_total_time_ms());
|
||||||
}
|
}
|
||||||
|
@ -5,9 +5,9 @@
|
|||||||
#ifdef USE_RUNTIME_STATS
|
#ifdef USE_RUNTIME_STATS
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
#include "esphome/core/helpers.h"
|
#include "esphome/core/helpers.h"
|
||||||
#include "esphome/core/log.h"
|
#include "esphome/core/log.h"
|
||||||
|
|
||||||
@ -79,7 +79,7 @@ class ComponentRuntimeStats {
|
|||||||
|
|
||||||
// For sorting components by run time
|
// For sorting components by run time
|
||||||
struct ComponentStatPair {
|
struct ComponentStatPair {
|
||||||
std::string name;
|
const char *name;
|
||||||
const ComponentRuntimeStats *stats;
|
const ComponentRuntimeStats *stats;
|
||||||
|
|
||||||
bool operator>(const ComponentStatPair &other) const {
|
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
|
// Use const char* keys for efficiency
|
||||||
std::map<std::string, ComponentRuntimeStats> component_stats_;
|
// Custom comparator for const char* keys in map
|
||||||
std::map<Component *, std::string> component_names_cache_;
|
struct CStrCompare {
|
||||||
|
bool operator()(const char *a, const char *b) const { return std::strcmp(a, b) < 0; }
|
||||||
|
};
|
||||||
|
std::map<const char *, ComponentRuntimeStats, CStrCompare> component_stats_;
|
||||||
|
std::map<Component *, const char *> component_names_cache_;
|
||||||
uint32_t log_interval_;
|
uint32_t log_interval_;
|
||||||
uint32_t next_log_time_;
|
uint32_t next_log_time_;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user