Merge blueprints-ramcloud-graph into ONOS code
diff --git a/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java.hashversion b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java.hashversion
new file mode 100644
index 0000000..9847cbd
--- /dev/null
+++ b/src/main/java/com/tinkerpop/blueprints/impls/ramcloud/PerfMon.java.hashversion
@@ -0,0 +1,290 @@
+package com.tinkerpop.blueprints.impls.ramcloud;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import sun.reflect.Reflection;
+
+
+public final class PerfMon {
+   private static final PerfMon instance = new PerfMon();
+   public final long measureAllTimeProp = Long.valueOf(System.getProperty("benchmark.measureAll", "0"));
+   private final static Logger log = LoggerFactory.getLogger(PerfMon.class);
+
+   private static final int debug = 0;
+
+   private static long read_latency_sum;
+   private static long read_latency_cnt;
+   private static int read_flag;
+
+   private static long write_latency_sum;
+   private static long write_latency_cnt;
+   private static int write_flag;
+
+   private static long serialize_latency_sum;
+   private static long serialize_latency_cnt;
+   private static HashMap<String, Long> ser_flag = new HashMap<String, Long>();
+   //private static int ser_flag;
+
+   private static long deserialize_latency_sum;
+   private static long deserialize_latency_cnt;
+   private static int deser_flag;
+
+   private static long addsw_time;
+   private static long addport_time;
+   private static long addlink_time;
+   private static long addport_cnt;
+   private static HashMap<String, Long> ser_time = new HashMap<String, Long>();
+   private static HashMap<String, Long> deser_time = new HashMap<String, Long>();
+   private static HashMap<String, Long> write_time = new HashMap<String, Long>();
+   private static HashMap<String, Long> read_time = new HashMap<String, Long>();
+
+   public static PerfMon getInstance() {
+        return instance;
+    }
+   private PerfMon(){
+   }
+
+   private void clear(){
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+   	read_latency_sum=0L;
+   	read_latency_cnt=0L;
+   	write_latency_sum=0L;
+   	write_latency_cnt=0L;
+   	serialize_latency_sum=0L;
+   	serialize_latency_cnt=0L;
+   	deserialize_latency_sum=0L;
+   	deserialize_latency_cnt=0L;
+	read_flag=write_flag=deser_flag=0;
+        for (Iterator<Map.Entry<String, Long>> it = ser_flag.entrySet().iterator(); it.hasNext(); ) {
+            Map.Entry<String, Long> entry = it.next();
+	    entry.setValue(0L);
+        }
+        //log.error("flag cleared");
+   }
+   public void addswitch_start(){
+        if(measureAllTimeProp==0)
+		return;
+
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	clear();
+	addsw_time = System.nanoTime();
+   }
+   public void addswitch_end(){
+        if(measureAllTimeProp==0)
+		return;
+
+        long delta;
+        long sum;
+
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+        delta = System.nanoTime() - addsw_time;
+        sum = read_latency_sum + write_latency_sum + serialize_latency_sum +  deserialize_latency_sum;
+        log.error("Performance add_switch {} read {} ({}) write {} ({}) serialize {} ({}) deserialize {} ({}) rwsd total {} other {} ({})", 
+	delta, read_latency_sum, read_latency_cnt, write_latency_sum, write_latency_cnt, serialize_latency_sum, serialize_latency_cnt, deserialize_latency_sum, deserialize_latency_cnt, sum, delta-sum, ((float)(delta-sum))*100.0/((float) delta));
+   }
+   public void addport_start(){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	clear();
+        addport_cnt = 0;
+	addport_time = System.nanoTime();
+   }
+   public void addport_incr(){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	clear();
+       addport_cnt ++;
+   }
+   public void addport_end(){
+        if(measureAllTimeProp==0)
+		return;
+        long delta;
+        long sum;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+        delta = System.nanoTime() - addport_time;
+        sum = read_latency_sum + write_latency_sum + serialize_latency_sum +  deserialize_latency_sum;
+        log.error("Performance add_port {} ( {} ports ) read {} ({}) write {} ({}) serialize {} ({}) deserialize {} ({}) rwsd total {} other {} ({})", 
+	delta, addport_cnt, read_latency_sum, read_latency_cnt, write_latency_sum, write_latency_cnt, serialize_latency_sum, serialize_latency_cnt, deserialize_latency_sum, deserialize_latency_cnt, sum, delta-sum, ((float)(delta-sum))*100.0/((float) delta));
+   }
+   public void addlink_start(){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	clear();
+	addlink_time = System.nanoTime();
+   }
+   public void addlink_end(){
+        if(measureAllTimeProp==0)
+		return;
+        long delta;
+        long sum;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+        delta = System.nanoTime() - addlink_time;
+        sum = read_latency_sum + write_latency_sum + serialize_latency_sum +  deserialize_latency_sum;
+        log.error("Performance add_link {} read {} ({}) write {} ({}) serialize {} ({}) deserialize {} ({}) rwsd total {} other {} ({})", 
+	delta, read_latency_sum, read_latency_cnt, write_latency_sum, write_latency_cnt, serialize_latency_sum, serialize_latency_cnt, deserialize_latency_sum, deserialize_latency_cnt, sum, delta-sum, ((float)(delta-sum))*100.0/((float) delta));
+   }
+
+   public void read_start(String key){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        } 
+	if ( debug==1 )
+            log.error("read start {}", key);
+	read_time.put(key, System.nanoTime());
+	//read_time = System.nanoTime();
+        if ( read_flag != 0){
+            log.error("read is already started");
+	}
+	read_flag = 1;
+   }
+   public void read_end(String key){
+        if(measureAllTimeProp==0)
+		return;
+        long delta;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+        //read_latency_sum += System.nanoTime() - read_time;
+	if ( debug==1 )
+            log.error("read end {}", key);
+        delta = System.nanoTime() - read_time.get(key);
+        read_latency_sum += delta;
+        read_latency_cnt ++;
+        if ( read_flag != 1){
+            log.error("read is not started");
+	}
+	read_flag = 0;
+   }
+   public void write_start(String key){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	if ( debug==1 )
+            log.error("write start {}", key);
+	write_time.put(key, System.nanoTime());
+	//write_time = System.nanoTime();
+        if ( write_flag != 0){
+            log.error("write is already started");
+	}
+	write_flag = 1;
+   }
+   public void write_end(String key){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	if ( debug==1 )
+            log.error("write end {}", key);
+        write_latency_sum += (System.nanoTime() - write_time.get(key));
+        //write_latency_sum += System.nanoTime() - write_time;
+        write_latency_cnt ++;
+        if ( write_flag != 1){
+            log.error("write is not started");
+	}
+	write_flag = 0;
+   }
+   public void ser_add(long time){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+        serialize_latency_sum += time;
+        serialize_latency_cnt ++;
+   }
+   public void ser_start(String key){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	//ser_time = System.nanoTime();
+	if ( debug==1 )
+            log.error("ser start {}", key);
+	ser_time.put(key, System.nanoTime());
+//        log.error("ser {} start at {} flag {}", key, ser_time, ser_flag);
+        if ( ser_flag.containsKey(key) ){
+        	if ( ser_flag.get(key) != 0L){
+            		log.error("ser {} sarted but has been already started", key);
+		}
+	}
+	ser_flag.put(key, 1L);
+   }
+   public void ser_end(String key){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	if ( debug==1 )
+            log.error("ser end {}", key);
+        //serialize_latency_sum += System.nanoTime() - ser_time;
+        serialize_latency_sum += (System.nanoTime() - ser_time.get(key));
+        serialize_latency_cnt ++;
+ //       log.error("ser {} end at {} flag {}", key, ser_time, ser_flag);
+        if ( ser_flag.containsKey(key) ){
+        	if ( ser_flag.get(key) != 1L){
+            		log.error("ser {} ended but hasn't started", key);
+		}
+	}
+	ser_flag.put(key, 0L);
+   }
+   public void deser_start(String key){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	if ( debug==1 )
+            log.error("deser start {}", key);
+	deser_time.put(key, System.nanoTime());
+	//deser_time = System.nanoTime();
+        if ( deser_flag != 0){
+            log.error("deser is already started");
+	}
+	deser_flag = 1;
+   }
+   public void deser_end(String key){
+        if(measureAllTimeProp==0)
+		return;
+        if(! Thread.currentThread().getName().equals("main")){
+		return;
+        }
+	if ( debug==1 )
+            log.error("deser end {}", key);
+        //deserialize_latency_sum += System.nanoTime() - deser_time;
+        deserialize_latency_sum += System.nanoTime() - deser_time.get(key);
+        deserialize_latency_cnt ++;
+        if ( deser_flag != 1){
+            log.error("deser is not started");
+	}
+	deser_flag = 0;
+   }
+}