cmcfarlen commented on code in PR #9114:
URL: https://github.com/apache/trafficserver/pull/9114#discussion_r984723311


##########
iocore/eventsystem/UnixEThread.cc:
##########
@@ -289,26 +292,31 @@ EThread::execute_regular()
 
     // loop cleanup
     loop_finish_time = Thread::get_hrtime_updated();
-    delta            = loop_finish_time - loop_start_time;
-
-    // This can happen due to time of day adjustments (which apparently happen 
quite frequently). I
+    // @a delta can be negative due to time of day adjustments (which 
apparently happen quite frequently). I
     // tried using the monotonic clock to get around this but it was *very* 
stuttery (up to hundreds
     // of milliseconds), far too much to be actually used.
-    if (delta > 0) {
-      if (delta > current_metric->_loop_time._max) {
-        current_metric->_loop_time._max = delta;
-      }
-      if (delta < current_metric->_loop_time._min) {
-        current_metric->_loop_time._min = delta;
-      }
+    delta = std::max<ink_hrtime>(0, loop_finish_time - loop_start_time);
+
+    if (delta > metrics.current_slice->_duration._max) {
+      metrics.current_slice->_duration._max = delta;
+    }
+    if (delta < metrics.current_slice->_duration._min) {
+      metrics.current_slice->_duration._min = delta;
     }
-    if (ev_count < current_metric->_events._min) {
-      current_metric->_events._min = ev_count;
+    if (ev_count < metrics.current_slice->_events._min) {
+      metrics.current_slice->_events._min = ev_count;
     }
-    if (ev_count > current_metric->_events._max) {
-      current_metric->_events._max = ev_count;
+    if (ev_count > metrics.current_slice->_events._max) {
+      metrics.current_slice->_events._max = ev_count;
     }
-    current_metric->_events._total += ev_count;
+    metrics.current_slice->_events._total += ev_count;
+    // Take care of any data decay.
+    while (metrics._decay_count) {
+      metrics._loop_timing.decay();
+      metrics._api_timing.decay();
+      --metrics._decay_count;
+    }
+    metrics._loop_timing(delta / 
std::chrono::duration_cast<std::chrono::nanoseconds>(Metrics::LOOP_HISTOGRAM_BUCKET_SIZE).count());

Review Comment:
   Even though metrics is a inner class of EThread, it looks odd directly 
accessing privately-named variables here.  Perhaps this could just call a 
`loop_timing` method on Metrics that does this end of loop stuff?



##########
proxy/http/HttpSM.cc:
##########
@@ -8457,5 +8454,7 @@ HttpSM::milestone_update_api_time()
       }
       milestones[TS_MILESTONE_PLUGIN_ACTIVE] += delta;
     }
+    this_ethread()->metrics._api_timing(
+      delta / 
std::chrono::duration_cast<std::chrono::nanoseconds>(EThread::Metrics::API_HISTOGRAM_BUCKET_SIZE).count());

Review Comment:
   Perhaps `_api_timing` could just take the delta and the histogram stuff 
could be handled by the Metrics class?  That way the caller doesn't need to 
know its updating a histogram.  I'd drop the underscore as well.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to