Line data Source code
1 : #pragma once 2 : 3 : #include "envoy/common/time.h" 4 : #include "envoy/stats/histogram.h" 5 : #include "envoy/stats/stats.h" 6 : #include "envoy/stats/timespan.h" 7 : 8 : namespace Envoy { 9 : namespace Stats { 10 : 11 : /** 12 : * An individual timespan that flushes its measured value to the histogram on completion. 13 : * The start time is captured on construction. The timespan must be 14 : * completed via complete() for it to be stored. If the timespan is deleted this will be treated as 15 : * a cancellation. The target histogram must represent a quantity of time. 16 : */ 17 : class HistogramCompletableTimespanImpl : public CompletableTimespan { 18 : public: 19 : HistogramCompletableTimespanImpl(Histogram& histogram, TimeSource& time_source); 20 : 21 : // Stats::CompletableTimespan 22 : std::chrono::milliseconds elapsed() const override; 23 : void complete() override; 24 : 25 : private: 26 : void ensureTimeHistogram(const Histogram& histogram) const; 27 2901 : template <typename TimeUnit> TimeUnit elapsedDuration() const { 28 2901 : return std::chrono::duration_cast<TimeUnit>(time_source_.monotonicTime() - start_); 29 2901 : } 30 : uint64_t tickCount() const; 31 : 32 : TimeSource& time_source_; 33 : Histogram& histogram_; 34 : const MonotonicTime start_; 35 : }; 36 : 37 : } // namespace Stats 38 : } // namespace Envoy