LCOV - code coverage report
Current view: top level - source/common/stats - timespan_impl.cc (source / functions) Hit Total Coverage
Test: coverage.dat Lines: 20 39 51.3 %
Date: 2024-01-05 06:35:25 Functions: 4 5 80.0 %

          Line data    Source code
       1             : #include "source/common/stats/timespan_impl.h"
       2             : 
       3             : #include "source/common/common/assert.h"
       4             : #include "source/common/common/fmt.h"
       5             : 
       6             : namespace Envoy {
       7             : namespace Stats {
       8             : 
       9             : HistogramCompletableTimespanImpl::HistogramCompletableTimespanImpl(Histogram& histogram,
      10             :                                                                    TimeSource& time_source)
      11        3157 :     : time_source_(time_source), histogram_(histogram), start_(time_source.monotonicTime()) {
      12        3157 :   ensureTimeHistogram(histogram);
      13        3157 : }
      14             : 
      15           0 : std::chrono::milliseconds HistogramCompletableTimespanImpl::elapsed() const {
      16           0 :   return HistogramCompletableTimespanImpl::elapsedDuration<std::chrono::milliseconds>();
      17           0 : }
      18             : 
      19        2901 : void HistogramCompletableTimespanImpl::complete() { histogram_.recordValue(tickCount()); }
      20             : 
      21        3157 : void HistogramCompletableTimespanImpl::ensureTimeHistogram(const Histogram& histogram) const {
      22        3157 :   switch (histogram.unit()) {
      23           0 :   case Histogram::Unit::Null:
      24           0 :   case Histogram::Unit::Microseconds:
      25        3157 :   case Histogram::Unit::Milliseconds:
      26        3157 :     return;
      27           0 :   case Histogram::Unit::Unspecified:
      28           0 :   case Histogram::Unit::Bytes:
      29           0 :   case Histogram::Unit::Percent:
      30           0 :     RELEASE_ASSERT(
      31        3157 :         false,
      32        3157 :         fmt::format("Cannot create a timespan flushing the duration to histogram '{}' because "
      33        3157 :                     "it does not measure time. This is a programming error, either pass a "
      34        3157 :                     "histogram measuring time or fix the unit of the passed histogram.",
      35        3157 :                     histogram.name()));
      36        3157 :   }
      37        3157 : }
      38             : 
      39        2901 : uint64_t HistogramCompletableTimespanImpl::tickCount() const {
      40        2901 :   switch (histogram_.unit()) {
      41           0 :   case Histogram::Unit::Null:
      42           0 :     return 0;
      43           0 :   case Histogram::Unit::Microseconds:
      44           0 :     return HistogramCompletableTimespanImpl::elapsedDuration<std::chrono::microseconds>().count();
      45        2901 :   case Histogram::Unit::Milliseconds:
      46        2901 :     return HistogramCompletableTimespanImpl::elapsedDuration<std::chrono::milliseconds>().count();
      47           0 :   case Histogram::Unit::Unspecified:
      48           0 :   case Histogram::Unit::Bytes:
      49           0 :   case Histogram::Unit::Percent:
      50           0 :     PANIC("not implemented");
      51        2901 :   }
      52           0 :   PANIC_DUE_TO_CORRUPT_ENUM;
      53           0 : }
      54             : 
      55             : } // namespace Stats
      56             : } // namespace Envoy

Generated by: LCOV version 1.15