mirror of
				https://github.com/esphome/esphome.git
				synced 2025-10-31 07:03:55 +00:00 
			
		
		
		
	fix last component being charged for stats
This commit is contained in:
		| @@ -136,6 +136,10 @@ void Application::loop() { | ||||
|   this->in_loop_ = false; | ||||
|   this->app_state_ = new_app_state; | ||||
|  | ||||
|   // Process any pending runtime stats printing after all components have run | ||||
|   // This ensures stats printing doesn't affect component timing measurements | ||||
|   runtime_stats.process_pending_stats(last_op_end_time); | ||||
|  | ||||
|   // Use the last component's end time instead of calling millis() again | ||||
|   auto elapsed = last_op_end_time - this->last_loop_; | ||||
|   if (elapsed >= this->loop_interval_ || HighFrequencyLoopRequester::is_high_frequency()) { | ||||
|   | ||||
| @@ -28,11 +28,7 @@ void RuntimeStatsCollector::record_component_time(Component *component, uint32_t | ||||
|     return; | ||||
|   } | ||||
|  | ||||
|   if (current_time >= this->next_log_time_) { | ||||
|     this->log_stats_(); | ||||
|     this->reset_stats_(); | ||||
|     this->next_log_time_ = current_time + this->log_interval_; | ||||
|   } | ||||
|   // Don't print stats here anymore - let process_pending_stats handle it | ||||
| } | ||||
|  | ||||
| void RuntimeStatsCollector::log_stats_() { | ||||
| @@ -82,4 +78,15 @@ void RuntimeStatsCollector::log_stats_() { | ||||
|   } | ||||
| } | ||||
|  | ||||
| void RuntimeStatsCollector::process_pending_stats(uint32_t current_time) { | ||||
|   if (!this->enabled_ || this->next_log_time_ == 0) | ||||
|     return; | ||||
|  | ||||
|   if (current_time >= this->next_log_time_) { | ||||
|     this->log_stats_(); | ||||
|     this->reset_stats_(); | ||||
|     this->next_log_time_ = current_time + this->log_interval_; | ||||
|   } | ||||
| } | ||||
|  | ||||
| }  // namespace esphome | ||||
| @@ -95,6 +95,9 @@ class RuntimeStatsCollector { | ||||
|  | ||||
|   void record_component_time(Component *component, uint32_t duration_ms, uint32_t current_time); | ||||
|  | ||||
|   // Process any pending stats printing (should be called after component loop) | ||||
|   void process_pending_stats(uint32_t current_time); | ||||
|  | ||||
|  protected: | ||||
|   void log_stats_(); | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user