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->in_loop_ = false; | ||||||
|   this->app_state_ = new_app_state; |   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 |   // Use the last component's end time instead of calling millis() again | ||||||
|   auto elapsed = last_op_end_time - this->last_loop_; |   auto elapsed = last_op_end_time - this->last_loop_; | ||||||
|   if (elapsed >= this->loop_interval_ || HighFrequencyLoopRequester::is_high_frequency()) { |   if (elapsed >= this->loop_interval_ || HighFrequencyLoopRequester::is_high_frequency()) { | ||||||
|   | |||||||
| @@ -28,11 +28,7 @@ void RuntimeStatsCollector::record_component_time(Component *component, uint32_t | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   if (current_time >= this->next_log_time_) { |   // Don't print stats here anymore - let process_pending_stats handle it | ||||||
|     this->log_stats_(); |  | ||||||
|     this->reset_stats_(); |  | ||||||
|     this->next_log_time_ = current_time + this->log_interval_; |  | ||||||
|   } |  | ||||||
| } | } | ||||||
|  |  | ||||||
| void RuntimeStatsCollector::log_stats_() { | 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 | }  // namespace esphome | ||||||
| @@ -95,6 +95,9 @@ class RuntimeStatsCollector { | |||||||
|  |  | ||||||
|   void record_component_time(Component *component, uint32_t duration_ms, uint32_t current_time); |   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: |  protected: | ||||||
|   void log_stats_(); |   void log_stats_(); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user