From 329d6052b64a7f6ffe3d40d4af9e258f75a21027 Mon Sep 17 00:00:00 2001 From: Scott Fines Date: Tue, 9 Mar 2021 08:41:10 -0600 Subject: [PATCH] making times record counts too --- .../apple/foundationdb/MapEventKeeper.java | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/bindings/java/src/main/com/apple/foundationdb/MapEventKeeper.java b/bindings/java/src/main/com/apple/foundationdb/MapEventKeeper.java index d9d53526b5..1232d95e13 100644 --- a/bindings/java/src/main/com/apple/foundationdb/MapEventKeeper.java +++ b/bindings/java/src/main/com/apple/foundationdb/MapEventKeeper.java @@ -29,30 +29,44 @@ import java.util.concurrent.atomic.AtomicLong; * This class is thread-safe(per the {@link EventKeeper} spec). It holds all counters in memory; */ public class MapEventKeeper implements EventKeeper { - private final ConcurrentMap map = new ConcurrentHashMap<>(); + private final ConcurrentMap map = new ConcurrentHashMap<>(); @Override public void count(Event event, long amt) { - AtomicLong cnt = map.computeIfAbsent(event, (l) -> new AtomicLong(0L)); - cnt.addAndGet(amt); + Count counter = map.computeIfAbsent(event, (l) -> new Count()); + counter.cnt.addAndGet(amt); } @Override public void timeNanos(Event event, long nanos) { - count(event, nanos); + Count counter = map.computeIfAbsent(event, (l)->new Count()); + counter.cnt.incrementAndGet(); + counter.duration.addAndGet(nanos); } @Override public long getCount(Event event) { - AtomicLong lng = map.get(event); + Count lng = map.get(event); if (lng == null) { return 0L; } - return lng.get(); + return lng.cnt.get(); } @Override public long getTimeNanos(Event event) { - return getCount(event); + Count lng = map.get(event); + if (lng == null) { + return 0L; + } + return lng.duration.get(); + } + + private static class Count { + private final AtomicLong cnt = new AtomicLong(0L); + + private final AtomicLong duration = new AtomicLong(0L); + + Count(){ } } }