diff options
Diffstat (limited to 'metrics/src')
-rw-r--r-- | metrics/src/tests/valuemetrictest.cpp | 8 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/valuemetric.h | 25 | ||||
-rw-r--r-- | metrics/src/vespa/metrics/valuemetric.hpp | 6 |
3 files changed, 25 insertions, 14 deletions
diff --git a/metrics/src/tests/valuemetrictest.cpp b/metrics/src/tests/valuemetrictest.cpp index 745edf44081..e8c144c96aa 100644 --- a/metrics/src/tests/valuemetrictest.cpp +++ b/metrics/src/tests/valuemetrictest.cpp @@ -187,10 +187,10 @@ void ValueMetricTest::testSmallAverage() void ValueMetricTest::testAddValueBatch() { DoubleValueMetric m("test", "tag", "description"); - m.addValueBatch(100, 3); - ASSERT_AVERAGE(m, 100, 100, 100, 3, 100); - m.addValueBatch(0, 0); - ASSERT_AVERAGE(m, 100, 100, 100, 3, 100); + m.addValueBatch(100, 3, 80, 120); + ASSERT_AVERAGE(m, 100, 80, 120, 3, 100); + m.addValueBatch(123, 0, 12, 1234); + ASSERT_AVERAGE(m, 100, 80, 120, 3, 100); } namespace { diff --git a/metrics/src/vespa/metrics/valuemetric.h b/metrics/src/vespa/metrics/valuemetric.h index 3a9e90be721..0c40a0fa5ea 100644 --- a/metrics/src/vespa/metrics/valuemetric.h +++ b/metrics/src/vespa/metrics/valuemetric.h @@ -65,7 +65,10 @@ class ValueMetric : public AbstractValueMetric { void dec(const Values &values); - void addValueWithCount(AvgVal avg, TotVal tot, uint32_t count); + void addValueWithCount(AvgVal avg, TotVal tot, uint32_t count, AvgVal min, AvgVal max); + void addValueWithCount(AvgVal avg, TotVal tot, uint32_t count) { + addValueWithCount(avg, tot, count, avg, avg); + } // Finite number (not infinity/NaN) check using type trait tag dispatch. // 2nd param is instance of std::true_type iff AvgVal is floating point. @@ -110,12 +113,20 @@ public: ValueMetric t(a); t += b; return t; } - void addAvgValueWithCount(AvgVal avg, uint32_t count) - { if (count) { addValueWithCount(avg, avg * count, count); } } - void addTotalValueWithCount(TotVal tot, uint32_t count) - { if (count) { addValueWithCount(tot / count, tot, count); } } - void addValueBatch(AvgVal avg, uint32_t count) { - addAvgValueWithCount(avg, count); + void addAvgValueWithCount(AvgVal avg, uint32_t count) { + if (count > 0) { + addValueWithCount(avg, avg * count, count); + } + } + void addTotalValueWithCount(TotVal tot, uint32_t count) { + if (count > 0) { + addValueWithCount(tot / count, tot, count); + } + } + void addValueBatch(AvgVal avg, uint32_t count, AvgVal min, AvgVal max) { + if (count > 0) { + addValueWithCount(avg, avg * count, count, min, max); + } } virtual void addValue(AvgVal avg) { addAvgValueWithCount(avg, 1); } virtual void set(AvgVal avg) { addValue(avg); } diff --git a/metrics/src/vespa/metrics/valuemetric.hpp b/metrics/src/vespa/metrics/valuemetric.hpp index 18c7837efb8..f8b4d1626ab 100644 --- a/metrics/src/vespa/metrics/valuemetric.hpp +++ b/metrics/src/vespa/metrics/valuemetric.hpp @@ -157,7 +157,7 @@ ValueMetric<AvgVal, TotVal, SumOnAdd>::dec(const Values& values2) template<typename AvgVal, typename TotVal, bool SumOnAdd> void ValueMetric<AvgVal, TotVal, SumOnAdd>::addValueWithCount( - AvgVal avg, TotVal tot, uint32_t count) + AvgVal avg, TotVal tot, uint32_t count, AvgVal min, AvgVal max) { if (!checkFinite(avg, std::is_floating_point<AvgVal>())) { return; @@ -167,8 +167,8 @@ void ValueMetric<AvgVal, TotVal, SumOnAdd>::addValueWithCount( values = _values.getValues(); values._count += count; values._total += tot; - if (avg < values._min) values._min = avg; - if (avg > values._max) values._max = avg; + if (min < values._min) values._min = min; + if (max > values._max) values._max = max; values._last = avg; } while (!_values.setValues(values)); } |