diff --git a/common/workunit/workunit.cpp b/common/workunit/workunit.cpp index 1f6c92c0fe2..beab6707501 100644 --- a/common/workunit/workunit.cpp +++ b/common/workunit/workunit.cpp @@ -2751,7 +2751,7 @@ class SubGraphUpdaterCollection : public CInterfaceOf { return rootCollection->addStatistic(kind,value); } - virtual void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction) override + virtual bool updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction) override { return rootCollection->updateStatistic(kind, value, mergeAction); } @@ -2879,8 +2879,8 @@ void updateAggregates(IWorkUnit *wu, GlobalStatisticCollection & statsCollection // 2) Serialize the aggregates into a blob in GraphProgress rather than to global stats std::vector aggregateKinds = {StCostFileAccess, StSizeGraphSpill, StSizeSpillFile}; StatisticsAggregatesWriter statsAggregatorWriter(wu, aggregateKinds); - statsCollection.refreshAggregates(aggregateKinds); - statsCollection.visit(statsAggregatorWriter); + if(statsCollection.refreshAggregates(aggregateKinds)) // Only serialize if the aggregates has changed + statsCollection.visit(statsAggregatorWriter); } //--------------------------------------------------------------------------------------------------------------------- diff --git a/system/jlib/jstats.cpp b/system/jlib/jstats.cpp index d105536fe87..f76e4e5ee87 100644 --- a/system/jlib/jstats.cpp +++ b/system/jlib/jstats.cpp @@ -1923,7 +1923,7 @@ class CStatisticCollection : public CInterfaceOf stats.append(s); } - void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction) + virtual bool updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction) override { if (mergeAction != StatsMergeAppend) { @@ -1932,13 +1932,19 @@ class CStatisticCollection : public CInterfaceOf Statistic & cur = stats.element(i); if (cur.kind == kind) { + if (mergeAction==StatsMergeReplace) + { + if (cur.value==value) + return false; + } cur.value = mergeStatisticValue(cur.value, value, mergeAction); - return; + return true; } } } Statistic s(kind, value); stats.append(s); + return true; } CStatisticCollection * ensureSubScope(const StatsScopeId & search, bool hasChildren) @@ -2083,8 +2089,7 @@ class CStatisticCollection : public CInterfaceOf if (iteratorVec!=aggregateKinds.end()) { unsigned pos = iteratorVec-aggregateKinds.begin(); - StatsMergeAction mergeAction = queryMergeMode(kind); - totals[pos] = mergeStatisticValue(totals[pos], stat.queryValue(), mergeAction); + totals[pos] += stat.queryValue(); updated = true; } } @@ -2099,14 +2104,15 @@ class CStatisticCollection : public CInterfaceOf } if (updated) { + updated=false; std::vector::iterator totalIter = totals.begin(); std::vector::iterator subTotalIter = childTotals.begin(); std::vector::iterator kindIter = aggregateKinds.begin(); while (totalIter != totals.end()) { - StatsMergeAction mergeAction = queryMergeMode(*kindIter); - updateStatistic(*kindIter, *subTotalIter, mergeAction); - (*totalIter) = mergeStatisticValue(*totalIter, *subTotalIter, mergeAction); + if (updateStatistic(*kindIter, *subTotalIter, StatsMergeReplace)) + updated=true; + (*totalIter) += *subTotalIter; ++totalIter; ++subTotalIter; diff --git a/system/jlib/jstats.h b/system/jlib/jstats.h index 5d775fbd3bb..ffcadc15ca9 100644 --- a/system/jlib/jstats.h +++ b/system/jlib/jstats.h @@ -125,7 +125,7 @@ interface IStatisticCollection : public IInterface virtual void visitChildren(IStatisticVisitor & target) const = 0; virtual IStatisticCollection * ensureSubScope(const StatsScopeId & search, bool hasChildren) = 0; virtual void addStatistic(StatisticKind kind, unsigned __int64 value) = 0; - virtual void updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction) = 0; + virtual bool updateStatistic(StatisticKind kind, unsigned __int64 value, StatsMergeAction mergeAction) = 0; virtual bool refreshAggregates(std::vector & aggregateKinds, std::vector & totals) = 0; virtual void deserialize(MemoryBuffer & in, unsigned version, StatisticScopeType minScope=SSTnone) = 0; virtual void deserializeChild(StatsScopeId scopeId, MemoryBuffer & in, unsigned version, StatisticScopeType minScope=SSTnone) = 0;