Skip to content

Commit

Permalink
Trace current active requests info. #751
Browse files Browse the repository at this point in the history
change AtomicInteger to IntAdder
  • Loading branch information
koo-taejin committed Jul 30, 2015
1 parent 9e05f7b commit f7c8453
Showing 1 changed file with 19 additions and 5 deletions.
Expand Up @@ -32,7 +32,6 @@
import org.apache.thrift.TBase;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;

/**
* @author Taejin Koo
Expand Down Expand Up @@ -69,22 +68,21 @@ public ActiveThreadService(ActiveTraceLocator activeTraceLocator) {
return fail;
}

Map<SlotType, AtomicInteger> mappedSlot = new LinkedHashMap<SlotType, AtomicInteger>(activeThreadSlotsCount);
Map<SlotType, IntAdder> mappedSlot = new LinkedHashMap<SlotType, IntAdder>(activeThreadSlotsCount);
for (SlotType slotType : ACTIVE_THREAD_SLOTS_ORDER) {
mappedSlot.put(slotType, new AtomicInteger(0));
mappedSlot.put(slotType, new IntAdder(0));
}

long currentTime = System.currentTimeMillis();

List<ActiveTraceInfo> activeTraceInfoCollect = activeTraceLocator.collect();
for (ActiveTraceInfo activeTraceInfo : activeTraceInfoCollect) {
HistogramSlot slot = histogramSchema.findHistogramSlot((int) (System.currentTimeMillis() - activeTraceInfo.getStartTime()));
System.out.println(slot);
mappedSlot.get(slot.getSlotType()).incrementAndGet();
}

List<Integer> activeThreadCount = new ArrayList<Integer>(activeThreadSlotsCount);
for (AtomicInteger statusCount : mappedSlot.values()) {
for (IntAdder statusCount : mappedSlot.values()) {
activeThreadCount.add(statusCount.get());
}

Expand All @@ -100,4 +98,20 @@ public Class<? extends TBase> getCommandClazz() {
return TActiveThread.class;
}

private static class IntAdder {
private int value = 0;

public IntAdder(int defaultValue) {
this.value = defaultValue;
}

public int incrementAndGet() {
return ++value;
}

public int get() {
return this.value;
}
}

}

0 comments on commit f7c8453

Please sign in to comment.