Преглед изворни кода

Merge pull request #13712 from ghalliday/issue23989

HPCC-23989 Provide a version of mergeStatistic specialised for summing counters

Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman пре 5 година
родитељ
комит
5cd211e273
2 измењених фајлова са 9 додато и 1 уклоњено
  1. 7 1
      system/jlib/jstats.cpp
  2. 2 0
      system/jlib/jstats.h

+ 7 - 1
system/jlib/jstats.cpp

@@ -2151,7 +2151,8 @@ void CRuntimeStatistic::merge(unsigned __int64 otherValue, StatsMergeAction merg
         value = otherValue;
         break;
     case StatsMergeSum:
-        addAtomic(otherValue);
+        if (otherValue)
+            addAtomic(otherValue);
         break;
     case StatsMergeMin:
         value.store_min(otherValue);
@@ -2253,6 +2254,11 @@ void CRuntimeStatisticCollection::mergeStatistic(StatisticKind kind, unsigned __
     queryStatistic(kind).merge(value, queryMergeMode(kind));
 }
 
+void CRuntimeStatisticCollection::sumStatistic(StatisticKind kind, unsigned __int64 value)
+{
+    queryStatistic(kind).sum(value);
+}
+
 void CRuntimeStatisticCollection::mergeStatistic(StatisticKind kind, unsigned __int64 value, unsigned node)
 {
     mergeStatistic(kind, value);

+ 2 - 0
system/jlib/jstats.h

@@ -460,6 +460,7 @@ public:
     }
     inline void clear() { set(0); }
     void merge(unsigned __int64 otherValue, StatsMergeAction mergeAction);
+    void sum(unsigned __int64 otherValue) { if (otherValue) addAtomic(otherValue); }
     inline void set(unsigned __int64 _value) { value = _value; }
 
 protected:
@@ -509,6 +510,7 @@ public:
         queryStatistic(kind).addAtomic(value);
     }
     void mergeStatistic(StatisticKind kind, unsigned __int64 value);
+    void sumStatistic(StatisticKind kind, unsigned __int64 value);      // Special more efficient version of mergeStatistic useful in time critical sections
     void setStatistic(StatisticKind kind, unsigned __int64 value)
     {
         queryStatistic(kind).set(value);