make PerformanceMontior's list thread safe
diff --git a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/PerformanceMonitor.java b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/PerformanceMonitor.java
index fa75460..6acf825 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/flowmanager/PerformanceMonitor.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/flowmanager/PerformanceMonitor.java
@@ -4,7 +4,9 @@
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Queue;
import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentLinkedQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -13,7 +15,7 @@
* Class for collecting performance measurements
*/
public class PerformanceMonitor {
- private final static Map<String, List<Measurement>> map = new ConcurrentHashMap<>();;
+ private final static Map<String, Queue<Measurement>> map = new ConcurrentHashMap<>();;
private final static Logger log = LoggerFactory.getLogger(PerformanceMonitor.class);
private static long overhead;
private static long experimentStart = Long.MAX_VALUE;
@@ -32,9 +34,9 @@
if(start < experimentStart) {
experimentStart = start;
}
- List<Measurement> list = map.get(tag);
+ Queue<Measurement> list = map.get(tag);
if(list == null) {
- list = new ArrayList<Measurement>();
+ list = new ConcurrentLinkedQueue<Measurement>();
map.put(tag, list);
}
Measurement m = new Measurement();
@@ -53,11 +55,11 @@
*/
public static void stop(String tag) {
long time = System.nanoTime();
- List<Measurement> list = map.get(tag);
+ Queue<Measurement> list = map.get(tag);
if(list == null || list.size() == 0) {
log.error("Tag {} does not exist", tag);
}
- list.get(0).stop(time);
+ list.peek().stop(time);
if(list.size() > 1) {
log.error("Tag {} has multiple measurements", tag);
}
@@ -84,9 +86,9 @@
return;
}
long experimentEnd = -1;
- for(Entry<String, List<Measurement>> e : map.entrySet()) {
+ for(Entry<String, Queue<Measurement>> e : map.entrySet()) {
String key = e.getKey();
- List<Measurement> list = e.getValue();
+ Queue<Measurement> list = e.getValue();
int total = 0, count = 0;
long start = Long.MAX_VALUE, stop = -1;
for(Measurement m : list) {
@@ -130,12 +132,12 @@
* @param tag the tag name.
*/
public static void report(String tag) {
- List<Measurement> list = map.get(tag);
+ Queue<Measurement> list = map.get(tag);
if(list == null) {
return; //TODO
}
//TODO: fix this;
- Measurement m = list.get(0);
+ Measurement m = list.peek();
if (m != null) {
log.error("Performance Result: tag = {} start = {} stop = {} elapsed = {}",
tag, m.start, m.stop, m.toString());