/proc/self/cwd/source/common/stats/timespan_impl.cc
Line | Count | Source (jump to first uncovered line) |
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 | 208k | : time_source_(time_source), histogram_(histogram), start_(time_source.monotonicTime()) { |
12 | 208k | ensureTimeHistogram(histogram); |
13 | 208k | } |
14 | | |
15 | 29 | std::chrono::milliseconds HistogramCompletableTimespanImpl::elapsed() const { |
16 | 29 | return HistogramCompletableTimespanImpl::elapsedDuration<std::chrono::milliseconds>(); |
17 | 29 | } |
18 | | |
19 | 14.5k | void HistogramCompletableTimespanImpl::complete() { histogram_.recordValue(tickCount()); } |
20 | | |
21 | 208k | void HistogramCompletableTimespanImpl::ensureTimeHistogram(const Histogram& histogram) const { |
22 | 208k | switch (histogram.unit()) { |
23 | 0 | case Histogram::Unit::Null: |
24 | 0 | case Histogram::Unit::Microseconds: |
25 | 208k | case Histogram::Unit::Milliseconds: |
26 | 208k | return; |
27 | 0 | case Histogram::Unit::Unspecified: |
28 | 0 | case Histogram::Unit::Bytes: |
29 | 0 | case Histogram::Unit::Percent: |
30 | 0 | RELEASE_ASSERT( |
31 | 208k | false, |
32 | 208k | fmt::format("Cannot create a timespan flushing the duration to histogram '{}' because " |
33 | 208k | "it does not measure time. This is a programming error, either pass a " |
34 | 208k | "histogram measuring time or fix the unit of the passed histogram.", |
35 | 208k | histogram.name())); |
36 | 208k | } |
37 | 208k | } |
38 | | |
39 | 14.5k | uint64_t HistogramCompletableTimespanImpl::tickCount() const { |
40 | 14.5k | 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 | 14.5k | case Histogram::Unit::Milliseconds: |
46 | 14.5k | 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 | 14.5k | } |
52 | 0 | PANIC_DUE_TO_CORRUPT_ENUM; |
53 | 0 | } |
54 | | |
55 | | } // namespace Stats |
56 | | } // namespace Envoy |