Skip to content

Commit

Permalink
[improvement](profile) do not remove value 0 counter (apache#24487)
Browse files Browse the repository at this point in the history
do not remove value 0 counter
  • Loading branch information
Mryange authored Sep 18, 2023
1 parent 1d1eeae commit b9f1ac1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
public class Counter {
private volatile long value;
private volatile int type;
private volatile boolean remove = false;

public long getValue() {
return value;
Expand Down Expand Up @@ -68,4 +69,12 @@ public boolean isTimeType() {
TUnit ttype = TUnit.findByValue(type);
return ttype == TUnit.TIME_MS || ttype == TUnit.TIME_NS || ttype == TUnit.TIME_S;
}

public void setCanRemove() {
this.remove = true;
}

public boolean isRemove() {
return this.remove;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ private static void mergeProfileCounter(RuntimeProfile src, String counterName,

mergeProfileCounter(src, childCounterName, rhs);
mergeCounter(src, childCounterName, counter, rhsCounter);
removeZeroeCounter(childCounterSet, childCounterName, counter);
removeCounter(childCounterSet, childCounterName, counter);

}
}
Expand All @@ -423,8 +423,8 @@ private static void mergeProfileInfoStr(RuntimeProfile src, LinkedList<RuntimePr
}
}

private static void removeZeroeCounter(Set<String> childCounterSet, String childCounterName, Counter counter) {
if (counter.getValue() == 0) {
private static void removeCounter(Set<String> childCounterSet, String childCounterName, Counter counter) {
if (counter.isRemove()) {
childCounterSet.remove(childCounterName);
}
}
Expand Down Expand Up @@ -476,7 +476,7 @@ private static void mergeCounter(RuntimeProfile src, String counterName, Counter
+ MIN_TIME_PRE + printCounter(minCounter.getValue(), minCounter.getType()) + " ]";
src.infoStrings.put(counterName, infoString);
}
counter.setValue(0); // value 0 will remove in removeZeroeCounter
counter.setCanRemove(); // value will remove in removeCounter
} else {
if (rhsCounter.size() == 0) {
return;
Expand Down

0 comments on commit b9f1ac1

Please sign in to comment.