Repository: incubator-systemml
Updated Branches:
  refs/heads/master d8390d4d2 -> c5eddccf8


[SYSTEMML-1402] Scalable statistics counters and atomic id sequence

Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/143e6143
Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/143e6143
Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/143e6143

Branch: refs/heads/master
Commit: 143e61430cd24a39aa41818b8017fe95dd953020
Parents: d8390d4
Author: Matthias Boehm <[email protected]>
Authored: Wed Mar 15 10:57:14 2017 -0700
Committer: Matthias Boehm <[email protected]>
Committed: Wed Mar 15 10:57:14 2017 -0700

----------------------------------------------------------------------
 .../java/org/apache/sysml/api/DMLScript.java    |   2 +-
 .../controlprogram/caching/CacheStatistics.java | 239 +++++++---------
 .../controlprogram/parfor/util/IDSequence.java  |  39 ++-
 .../org/apache/sysml/utils/GPUStatistics.java   |   1 +
 .../java/org/apache/sysml/utils/Statistics.java | 273 ++++++++-----------
 5 files changed, 231 insertions(+), 323 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/143e6143/src/main/java/org/apache/sysml/api/DMLScript.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/api/DMLScript.java 
b/src/main/java/org/apache/sysml/api/DMLScript.java
index d8db84c..9959aea 100644
--- a/src/main/java/org/apache/sysml/api/DMLScript.java
+++ b/src/main/java/org/apache/sysml/api/DMLScript.java
@@ -760,7 +760,7 @@ public class DMLScript
                CacheableData.initCaching();
                                                
                //reset statistics (required if multiple scripts executed in 
one JVM)
-               Statistics.resetNoOfExecutedJobs( 0 );
+               Statistics.resetNoOfExecutedJobs();
                if( STATISTICS ) {
                        CacheStatistics.reset();
                        Statistics.reset();

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/143e6143/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheStatistics.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheStatistics.java
 
b/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheStatistics.java
index f40ae62..c569787 100644
--- 
a/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheStatistics.java
+++ 
b/src/main/java/org/apache/sysml/runtime/controlprogram/caching/CacheStatistics.java
@@ -19,7 +19,7 @@
 
 package org.apache.sysml.runtime.controlprogram.caching;
 
-import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.LongAdder;
 
 /**
  * This singleton provides basic caching statistics in CP.
@@ -34,7 +34,6 @@ import java.util.concurrent.atomic.AtomicLong;
  */
 public class CacheStatistics 
 {
-       
        //enum used for MR counters
        public enum Stat {
                CACHE_HITS_MEM,
@@ -51,234 +50,188 @@ public class CacheStatistics
        }
        
        //hit statistics (for acquire read)
-       private static AtomicLong _numHitsMem    = null;
-       private static AtomicLong _numHitsFSBuff = null;
-       private static AtomicLong _numHitsFS     = null;
-       private static AtomicLong _numHitsHDFS   = null;
+       private static final LongAdder _numHitsMem      = new LongAdder();
+       private static final LongAdder _numHitsFSBuff   = new LongAdder();
+       private static final LongAdder _numHitsFS       = new LongAdder();
+       private static final LongAdder _numHitsHDFS     = new LongAdder();
        
        //write statistics caching
-       private static AtomicLong _numWritesFSBuff = null;
-       private static AtomicLong _numWritesFS     = null;
-       private static AtomicLong _numWritesHDFS   = null;
+       private static final LongAdder _numWritesFSBuff = new LongAdder();
+       private static final LongAdder _numWritesFS     = new LongAdder();
+       private static final LongAdder _numWritesHDFS   = new LongAdder();
        
        //time statistics caching
-       private static AtomicLong _ctimeAcquireR   = null; //in nano sec
-       private static AtomicLong _ctimeAcquireM   = null; //in nano sec
-       private static AtomicLong _ctimeRelease    = null; //in nano sec
-       private static AtomicLong _ctimeExport     = null; //in nano sec
+       private static final LongAdder _ctimeAcquireR   = new LongAdder(); //in 
nano sec
+       private static final LongAdder _ctimeAcquireM   = new LongAdder(); //in 
nano sec
+       private static final LongAdder _ctimeRelease    = new LongAdder(); //in 
nano sec
+       private static final LongAdder _ctimeExport     = new LongAdder(); //in 
nano sec
 
-       static
-       {
-               reset();
-       }
-       
-       public static void reset()
-       {
-               _numHitsMem = new AtomicLong(0);
-               _numHitsFSBuff = new AtomicLong(0);
-               _numHitsFS = new AtomicLong(0);
-               _numHitsHDFS = new AtomicLong(0);
+       public static void reset() {
+               _numHitsMem.reset();
+               _numHitsFSBuff.reset();
+               _numHitsFS.reset();
+               _numHitsHDFS.reset();
                
-               _numWritesFSBuff = new AtomicLong(0);
-               _numWritesFS = new AtomicLong(0);
-               _numWritesHDFS = new AtomicLong(0);
+               _numWritesFSBuff.reset();
+               _numWritesFS.reset();
+               _numWritesHDFS.reset();
                
-               _ctimeAcquireR = new AtomicLong(0);
-               _ctimeAcquireM = new AtomicLong(0);
-               _ctimeRelease = new AtomicLong(0);
-               _ctimeExport = new AtomicLong(0);
+               _ctimeAcquireR.reset();
+               _ctimeAcquireM.reset();
+               _ctimeRelease.reset();
+               _ctimeExport.reset();
        }
 
-       public static void incrementMemHits()
-       {
-               _numHitsMem.incrementAndGet();
+       public static void incrementMemHits() {
+               _numHitsMem.increment();
        }
        
-       public static void incrementMemHits(int delta)
-       {
-               _numHitsMem.addAndGet(delta);
+       public static void incrementMemHits(int delta) {
+               _numHitsMem.add(delta);
        }
        
-       public static long getMemHits()
-       {
-               return _numHitsMem.get();
+       public static long getMemHits() {
+               return _numHitsMem.longValue();
        }
 
-       public static void incrementFSBuffHits()
-       {
-               _numHitsFSBuff.incrementAndGet();
+       public static void incrementFSBuffHits() {
+               _numHitsFSBuff.increment();
        }
        
-       public static void incrementFSBuffHits( int delta )
-       {
-               _numHitsFSBuff.addAndGet(delta);
+       public static void incrementFSBuffHits( int delta ) {
+               _numHitsFSBuff.add(delta);
        }
        
-       public static long getFSBuffHits()
-       {
-               return _numHitsFSBuff.get();
+       public static long getFSBuffHits() {
+               return _numHitsFSBuff.longValue();
        }
        
-       public static void incrementFSHits()
-       {
-               _numHitsFS.incrementAndGet();
+       public static void incrementFSHits() {
+               _numHitsFS.increment();
        }
        
-       public static void incrementFSHits(int delta)
-       {
-               _numHitsFS.addAndGet(delta);
+       public static void incrementFSHits(int delta) {
+               _numHitsFS.add(delta);
        }
        
-       public static long getFSHits()
-       {
-               return _numHitsFS.get();
+       public static long getFSHits() {
+               return _numHitsFS.longValue();
        }
        
-       public static void incrementHDFSHits()
-       {
-               _numHitsHDFS.incrementAndGet();
+       public static void incrementHDFSHits() {
+               _numHitsHDFS.increment();
        }
        
-       public static void incrementHDFSHits(int delta)
-       {
-               _numHitsHDFS.addAndGet(delta);
+       public static void incrementHDFSHits(int delta) {
+               _numHitsHDFS.add(delta);
        }
        
-       public static long getHDFSHits()
-       {
-               return _numHitsHDFS.get();
+       public static long getHDFSHits() {
+               return _numHitsHDFS.longValue();
        }
 
-       public static void incrementFSBuffWrites()
-       {
-               _numWritesFSBuff.incrementAndGet();
+       public static void incrementFSBuffWrites() {
+               _numWritesFSBuff.increment();
        }
        
-       public static void incrementFSBuffWrites(int delta)
-       {
-               _numWritesFSBuff.addAndGet(delta);
+       public static void incrementFSBuffWrites(int delta) {
+               _numWritesFSBuff.add(delta);
        }
        
-       public static long getFSBuffWrites()
-       {
-               return _numWritesFSBuff.get();
+       public static long getFSBuffWrites() {
+               return _numWritesFSBuff.longValue();
        }
        
-       public static void incrementFSWrites()
-       {
-               _numWritesFS.incrementAndGet();
+       public static void incrementFSWrites() {
+               _numWritesFS.increment();
        }
        
-       public static void incrementFSWrites(int delta)
-       {
-               _numWritesFS.addAndGet(delta);
+       public static void incrementFSWrites(int delta) {
+               _numWritesFS.add(delta);
        }
        
-       public static long getFSWrites()
-       {
-               return _numWritesFS.get();
+       public static long getFSWrites() {
+               return _numWritesFS.longValue();
        }
        
-       public static void incrementHDFSWrites()
-       {
-               _numWritesHDFS.incrementAndGet();
+       public static void incrementHDFSWrites() {
+               _numWritesHDFS.increment();
        }
        
-       public static void incrementHDFSWrites(int delta)
-       {
-               _numWritesHDFS.addAndGet(delta);
+       public static void incrementHDFSWrites(int delta) {
+               _numWritesHDFS.add(delta);
        }
        
-       public static long getHDFSWrites()
-       {
-               return _numWritesHDFS.get();
+       public static long getHDFSWrites() {
+               return _numWritesHDFS.longValue();
        }
        
-       public static void incrementAcquireRTime(long delta)
-       {
-               _ctimeAcquireR.addAndGet(delta);
+       public static void incrementAcquireRTime(long delta) {
+               _ctimeAcquireR.add(delta);
        }
        
-       public static long getAcquireRTime()
-       {
-               return _ctimeAcquireR.get();
+       public static long getAcquireRTime() {
+               return _ctimeAcquireR.longValue();
        }
        
-       public static void incrementAcquireMTime(long delta)
-       {
-               _ctimeAcquireM.addAndGet(delta);
+       public static void incrementAcquireMTime(long delta) {
+               _ctimeAcquireM.add(delta);
        }
        
-       public static long getAcquireMTime()
-       {
-               return _ctimeAcquireM.get();
+       public static long getAcquireMTime() {
+               return _ctimeAcquireM.longValue();
        }
 
-       public static void incrementReleaseTime(long delta)
-       {
-               _ctimeRelease.addAndGet(delta);
+       public static void incrementReleaseTime(long delta) {
+               _ctimeRelease.add(delta);
        }
        
-       public static long getReleaseTime()
-       {
-               return _ctimeRelease.get();
+       public static long getReleaseTime() {
+               return _ctimeRelease.longValue();
        }
 
-       
-       public static void incrementExportTime(long delta)
-       {
-               _ctimeExport.addAndGet(delta);
+       public static void incrementExportTime(long delta) {
+               _ctimeExport.add(delta);
        }
        
-       public static long getExportTime()
-       {
-               return _ctimeExport.get();
+       public static long getExportTime() {
+               return _ctimeExport.longValue();
        }
        
-
-       public static String displayHits()
-       {       
+       public static String displayHits() {    
                StringBuilder sb = new StringBuilder();
-               sb.append(_numHitsMem.get());
+               sb.append(_numHitsMem.longValue());
                sb.append("/");
-               sb.append(_numHitsFSBuff.get());
+               sb.append(_numHitsFSBuff.longValue());
                sb.append("/");
-               sb.append(_numHitsFS.get());
+               sb.append(_numHitsFS.longValue());
                sb.append("/");
-               sb.append(_numHitsHDFS.get());
-               
+               sb.append(_numHitsHDFS.longValue());
                
                return sb.toString();
        }
        
-       public static String displayWrites()
-       {       
+       public static String displayWrites() {  
                StringBuilder sb = new StringBuilder();
-               sb.append(_numWritesFSBuff.get());
+               sb.append(_numWritesFSBuff.longValue());
                sb.append("/");
-               sb.append(_numWritesFS.get());
+               sb.append(_numWritesFS.longValue());
                sb.append("/");
-               sb.append(_numWritesHDFS.get());
-               
+               sb.append(_numWritesHDFS.longValue());
                
                return sb.toString();
        }
        
-       public static String displayTime()
-       {       
+       public static String displayTime() {    
                StringBuilder sb = new StringBuilder();
-               sb.append(String.format("%.3f", 
((double)_ctimeAcquireR.get())/1000000000)); //in sec
+               sb.append(String.format("%.3f", 
((double)_ctimeAcquireR.longValue())/1000000000)); //in sec
                sb.append("/");
-               sb.append(String.format("%.3f", 
((double)_ctimeAcquireM.get())/1000000000)); //in sec
+               sb.append(String.format("%.3f", 
((double)_ctimeAcquireM.longValue())/1000000000)); //in sec
                sb.append("/");
-               sb.append(String.format("%.3f", 
((double)_ctimeRelease.get())/1000000000)); //in sec
+               sb.append(String.format("%.3f", 
((double)_ctimeRelease.longValue())/1000000000)); //in sec
                sb.append("/");
-               sb.append(String.format("%.3f", 
((double)_ctimeExport.get())/1000000000)); //in sec
-               
-               ;
+               sb.append(String.format("%.3f", 
((double)_ctimeExport.longValue())/1000000000)); //in sec
                
                return sb.toString();
        }
-       
-       
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/143e6143/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/util/IDSequence.java
----------------------------------------------------------------------
diff --git 
a/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/util/IDSequence.java
 
b/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/util/IDSequence.java
index 24056dc..cdbbc3f 100644
--- 
a/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/util/IDSequence.java
+++ 
b/src/main/java/org/apache/sysml/runtime/controlprogram/parfor/util/IDSequence.java
@@ -19,24 +19,24 @@
 
 package org.apache.sysml.runtime.controlprogram.parfor.util;
 
+import java.util.concurrent.atomic.AtomicLong;
+
 /**
  * ID sequence for generating unique long identifiers with start 0 and 
increment 1.
  * 
  */
 public class IDSequence 
 {
-       private long _current = -1;
-       private boolean wrapAround = false;
+       private final AtomicLong _current;
+       private final boolean _wrapAround;
        
-       public IDSequence()
-       {
-               reset();
+       public IDSequence() {
+               this(false);
        }
        
-       public IDSequence(boolean wrapAround)
-       {
-               reset();
-               this.wrapAround = wrapAround;
+       public IDSequence(boolean wrapAround) {
+               _current = new AtomicLong(-1);
+               _wrapAround = wrapAround;
        }
        
        /**
@@ -44,25 +44,24 @@ public class IDSequence
         * 
         * @return ID
         */
-       public synchronized long getNextID()
+       public long getNextID()
        {
-               _current++;
+               long val = _current.incrementAndGet();
                
-               if( _current == Long.MAX_VALUE ) {
-                       if (wrapAround)
-                               reset();
-                       else
+               if( val == Long.MAX_VALUE ) {
+                       if( !_wrapAround )
                                throw new RuntimeException("WARNING: IDSequence 
will produced numeric overflow.");
+                       reset();
                }
                
-               return _current;
+               return val;
        }
        
-       public synchronized long getCurrentID() {
-               return _current;
+       public long getCurrentID() {
+               return _current.get();
        }
        
-       public synchronized void reset() {
-               _current = 0;
+       public void reset() {
+               _current.set(0);
        }
 }

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/143e6143/src/main/java/org/apache/sysml/utils/GPUStatistics.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/utils/GPUStatistics.java 
b/src/main/java/org/apache/sysml/utils/GPUStatistics.java
index 1211a97..6b85d92 100644
--- a/src/main/java/org/apache/sysml/utils/GPUStatistics.java
+++ b/src/main/java/org/apache/sysml/utils/GPUStatistics.java
@@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicLong;
  */
 public class GPUStatistics {
        //TODO fix formatting 
+       //TODO replace AtomicLong with LongAdder
        
        
   // Whether or not extra per-instruction statistics will be recorded and 
shown for the GPU

http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/143e6143/src/main/java/org/apache/sysml/utils/Statistics.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/sysml/utils/Statistics.java 
b/src/main/java/org/apache/sysml/utils/Statistics.java
index f7f169f..3ded328 100644
--- a/src/main/java/org/apache/sysml/utils/Statistics.java
+++ b/src/main/java/org/apache/sysml/utils/Statistics.java
@@ -28,7 +28,7 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map.Entry;
 import java.util.Set;
-import java.util.concurrent.atomic.AtomicLong;
+import java.util.concurrent.atomic.LongAdder;
 
 import org.apache.sysml.api.DMLScript;
 import org.apache.sysml.conf.ConfigurationManager;
@@ -55,167 +55,133 @@ public class Statistics
        private static long execEndTime = 0;
 
        // number of compiled/executed MR jobs
-       private static int iNoOfExecutedMRJobs = 0;
-       private static int iNoOfCompiledMRJobs = 0;
+       private static final LongAdder numExecutedMRJobs = new LongAdder();
+       private static final LongAdder numCompiledMRJobs = new LongAdder();
 
        // number of compiled/executed SP instructions
-       private static int iNoOfExecutedSPInst = 0;
-       private static int iNoOfCompiledSPInst = 0;
-       
+       private static final LongAdder numExecutedSPInst = new LongAdder();
+       private static final LongAdder numCompiledSPInst = new LongAdder();
 
-       //JVM stats
+       //JVM stats (low frequency updates)
        private static long jitCompileTime = 0; //in milli sec
        private static long jvmGCTime = 0; //in milli sec
        private static long jvmGCCount = 0; //count
        
        //HOP DAG recompile stats (potentially high update frequency)
-       private static AtomicLong hopRecompileTime = new AtomicLong(0); //in 
nano sec
-       private static AtomicLong hopRecompilePred = new AtomicLong(0); //count
-       private static AtomicLong hopRecompileSB = new AtomicLong(0);   //count
+       private static final LongAdder hopRecompileTime = new LongAdder(); //in 
nano sec
+       private static final LongAdder hopRecompilePred = new LongAdder(); 
//count
+       private static final LongAdder hopRecompileSB = new LongAdder();   
//count
 
        //CODEGEN
-       private static AtomicLong codegenCompileTime = new AtomicLong(0); //in 
nano
-       private static AtomicLong codegenClassCompileTime = new AtomicLong(0); 
//in nano
-       private static AtomicLong codegenHopCompile = new AtomicLong(0); //count
-       private static AtomicLong codegenCPlanCompile = new AtomicLong(0); 
//count
-       private static AtomicLong codegenClassCompile = new AtomicLong(0); 
//count
-       private static AtomicLong codegenPlanCacheHits = new AtomicLong(0); 
//count
-       private static AtomicLong codegenPlanCacheTotal = new AtomicLong(0); 
//count
+       private static final LongAdder codegenCompileTime = new LongAdder(); 
//in nano
+       private static final LongAdder codegenClassCompileTime = new 
LongAdder(); //in nano
+       private static final LongAdder codegenHopCompile = new LongAdder(); 
//count
+       private static final LongAdder codegenCPlanCompile = new LongAdder(); 
//count
+       private static final LongAdder codegenClassCompile = new LongAdder(); 
//count
+       private static final LongAdder codegenPlanCacheHits = new LongAdder(); 
//count
+       private static final LongAdder codegenPlanCacheTotal = new LongAdder(); 
//count
        
        //Function recompile stats 
-       private static AtomicLong funRecompileTime = new AtomicLong(0); //in 
nano sec
-       private static AtomicLong funRecompiles = new AtomicLong(0); //count
+       private static final LongAdder funRecompileTime = new LongAdder(); //in 
nano sec
+       private static final LongAdder funRecompiles = new LongAdder(); //count
        
        //Spark-specific stats
        private static long sparkCtxCreateTime = 0; 
-       private static AtomicLong sparkParallelize = new AtomicLong(0L);
-       private static AtomicLong sparkParallelizeCount = new AtomicLong(0L);
-       private static AtomicLong sparkCollect = new AtomicLong(0L);
-       private static AtomicLong sparkCollectCount = new AtomicLong(0L);
-       private static AtomicLong sparkBroadcast = new AtomicLong(0L);
-       private static AtomicLong sparkBroadcastCount = new AtomicLong(0L);
-
-       //PARFOR optimization stats 
+       private static final LongAdder sparkParallelize = new LongAdder();
+       private static final LongAdder sparkParallelizeCount = new LongAdder();
+       private static final LongAdder sparkCollect = new LongAdder();
+       private static final LongAdder sparkCollectCount = new LongAdder();
+       private static final LongAdder sparkBroadcast = new LongAdder();
+       private static final LongAdder sparkBroadcastCount = new LongAdder();
+
+       //PARFOR optimization stats (low frequency updates)
        private static long parforOptTime = 0; //in milli sec
        private static long parforOptCount = 0; //count
        private static long parforInitTime = 0; //in milli sec
        private static long parforMergeTime = 0; //in milli sec
        
        //heavy hitter counts and times 
-       private static HashMap<String,Long> _cpInstTime   =  new 
HashMap<String, Long>();
-       private static HashMap<String,Long> _cpInstCounts =  new 
HashMap<String, Long>();
-
-       private static AtomicLong lTotalUIPVar = new AtomicLong(0);
-       private static AtomicLong lTotalLix = new AtomicLong(0);
-       private static AtomicLong lTotalLixUIP = new AtomicLong(0);
+       private static HashMap<String,Long> _cpInstTime = new HashMap<String, 
Long>();
+       private static HashMap<String,Long> _cpInstCounts = new HashMap<String, 
Long>();
 
-       public static synchronized void setNoOfExecutedMRJobs(int 
iNoOfExecutedMRJobs) {
-               Statistics.iNoOfExecutedMRJobs = iNoOfExecutedMRJobs;
-       }
+       private static final LongAdder lTotalUIPVar = new LongAdder();
+       private static final LongAdder lTotalLix = new LongAdder();
+       private static final LongAdder lTotalLixUIP = new LongAdder();
 
-       public static synchronized int getNoOfExecutedMRJobs() {
-               return iNoOfExecutedMRJobs;
+       public static synchronized long getNoOfExecutedMRJobs() {
+               return numExecutedMRJobs.longValue();
        }
        
-       public static synchronized void incrementNoOfExecutedMRJobs() {
-               iNoOfExecutedMRJobs ++;
+       public static void incrementNoOfExecutedMRJobs() {
+               numExecutedMRJobs.increment();
        }
        
-       public static synchronized void decrementNoOfExecutedMRJobs() {
-               iNoOfExecutedMRJobs --;
-       }
-
-       public static synchronized void setNoOfCompiledMRJobs(int numJobs) {
-               iNoOfCompiledMRJobs = numJobs;
+       public static void decrementNoOfExecutedMRJobs() {
+               numExecutedMRJobs.decrement();
        }
 
-       public static synchronized int getNoOfCompiledMRJobs() {
-               return iNoOfCompiledMRJobs;
+       public static long getNoOfCompiledMRJobs() {
+               return numCompiledMRJobs.longValue();
        }
        
-       public static synchronized void incrementNoOfCompiledMRJobs() {
-               iNoOfCompiledMRJobs ++;
+       public static void incrementNoOfCompiledMRJobs() {
+               numCompiledMRJobs.increment();
        }
 
-
-       public static synchronized void setNoOfExecutedSPInst(int numJobs) {
-               iNoOfExecutedSPInst = numJobs;
-       }
-       
-       public static synchronized int getNoOfExecutedSPInst() {
-               return iNoOfExecutedSPInst;
-       }
-       
-       public static synchronized void incrementNoOfExecutedSPInst() {
-               iNoOfExecutedSPInst ++;
+       public static long getNoOfExecutedSPInst() {
+               return numExecutedSPInst.longValue();
        }
        
-       public static synchronized void decrementNoOfExecutedSPInst() {
-               iNoOfExecutedSPInst --;
+       public static void incrementNoOfExecutedSPInst() {
+               numExecutedSPInst.increment();
        }
        
-       public static synchronized void setNoOfCompiledSPInst(int numJobs) {
-               iNoOfCompiledSPInst = numJobs;
+       public static void decrementNoOfExecutedSPInst() {
+               numExecutedSPInst.decrement();
        }
 
-       public static synchronized int getNoOfCompiledSPInst() {
-               return iNoOfCompiledSPInst;
+       public static long getNoOfCompiledSPInst() {
+               return numCompiledSPInst.longValue();
        }
 
-       public static synchronized void incrementNoOfCompiledSPInst() {
-               iNoOfCompiledSPInst ++;
+       public static void incrementNoOfCompiledSPInst() {
+               numCompiledSPInst.increment();
        }
        
        public static long getTotalUIPVar() {
-               return lTotalUIPVar.get();
+               return lTotalUIPVar.longValue();
        }
 
        public static void incrementTotalUIPVar() {
-               lTotalUIPVar.incrementAndGet();
+               lTotalUIPVar.increment();
        }
 
        public static long getTotalLixUIP() {
-               return lTotalLixUIP.get();
+               return lTotalLixUIP.longValue();
        }
 
        public static void incrementTotalLixUIP() {
-               lTotalLixUIP.incrementAndGet();
+               lTotalLixUIP.increment();
        }
 
        public static long getTotalLix() {
-               return lTotalLix.get();
+               return lTotalLix.longValue();
        }
 
        public static void incrementTotalLix() {
-               lTotalLix.incrementAndGet();
+               lTotalLix.increment();
        }
 
-       public static void resetNoOfCompiledJobs( int count )
-       {
+       public static void resetNoOfCompiledJobs( int count ) {
                //reset both mr/sp for multiple tests within one jvm
-               
-               if(OptimizerUtils.isSparkExecutionMode()) {
-                       setNoOfCompiledSPInst(count);
-                       setNoOfCompiledMRJobs(0);
-               }
-               else{
-                       setNoOfCompiledMRJobs(count);
-                       setNoOfCompiledSPInst(0);
-               }
+               numCompiledSPInst.reset();
+               numCompiledMRJobs.reset();
        }
 
-       public static void resetNoOfExecutedJobs( int count )
-       {
+       public static void resetNoOfExecutedJobs() {
                //reset both mr/sp for multiple tests within one jvm
-               
-               if(OptimizerUtils.isSparkExecutionMode()) {
-                       setNoOfExecutedSPInst(count);
-                       setNoOfExecutedMRJobs(0);               
-               }
-               else {
-                       setNoOfExecutedMRJobs(count);
-                       setNoOfExecutedSPInst(0);
-               }
+               numExecutedSPInst.reset();
+               numExecutedMRJobs.reset();
                
                if( DMLScript.USE_ACCELERATOR )
                        GPUStatistics.setNoOfExecutedGPUInst(0);
@@ -234,94 +200,87 @@ public class Statistics
        }
        
        public static void incrementHOPRecompileTime( long delta ) {
-               //note: not synchronized due to use of atomics
-               hopRecompileTime.addAndGet(delta);
+               hopRecompileTime.add(delta);
        }
        
        public static void incrementHOPRecompilePred() {
-               //note: not synchronized due to use of atomics
-               hopRecompilePred.incrementAndGet();
+               hopRecompilePred.increment();
        }
        
        public static void incrementHOPRecompilePred(long delta) {
-               //note: not synchronized due to use of atomics
-               hopRecompilePred.addAndGet(delta);
+               hopRecompilePred.add(delta);
        }
        
        public static void incrementHOPRecompileSB() {
-               //note: not synchronized due to use of atomics
-               hopRecompileSB.incrementAndGet();
+               hopRecompileSB.increment();
        }
        
        public static void incrementHOPRecompileSB(long delta) {
-               //note: not synchronized due to use of atomics
-               hopRecompileSB.addAndGet(delta);
+               hopRecompileSB.add(delta);
        }
        
        public static void incrementCodegenDAGCompile() {
-               codegenHopCompile.incrementAndGet();
+               codegenHopCompile.increment();
        }
        
        public static void incrementCodegenCPlanCompile(long delta) {
-               codegenCPlanCompile.addAndGet(delta);
+               codegenCPlanCompile.add(delta);
        }
        
        public static void incrementCodegenClassCompile() {
-               codegenClassCompile.incrementAndGet();
+               codegenClassCompile.increment();
        }
        
        public static void incrementCodegenCompileTime(long delta) {
-               codegenCompileTime.addAndGet(delta);
+               codegenCompileTime.add(delta);
        }
        
        public static void incrementCodegenClassCompileTime(long delta) {
-               codegenClassCompileTime.addAndGet(delta);
+               codegenClassCompileTime.add(delta);
        }
        
        public static void incrementCodegenPlanCacheHits() {
-               codegenPlanCacheHits.incrementAndGet();
+               codegenPlanCacheHits.increment();
        }
        
        public static void incrementCodegenPlanCacheTotal() {
-               codegenPlanCacheTotal.incrementAndGet();
+               codegenPlanCacheTotal.increment();
        }
        
        public static long getCodegenDAGCompile() {
-               return codegenHopCompile.get();
+               return codegenHopCompile.longValue();
        }
        
        public static long getCodegenCPlanCompile() {
-               return codegenCPlanCompile.get();
+               return codegenCPlanCompile.longValue();
        }
        
        public static long getCodegenClassCompile() {
-               return codegenClassCompile.get();
+               return codegenClassCompile.longValue();
        }
        
        public static long getCodegenCompileTime() {
-               return codegenCompileTime.get();
+               return codegenCompileTime.longValue();
        }
        
        public static long getCodegenClassCompileTime() {
-               return codegenClassCompileTime.get();
+               return codegenClassCompileTime.longValue();
        }
        
        public static long getCodegenPlanCacheHits() {
-               return codegenPlanCacheHits.get();
+               return codegenPlanCacheHits.longValue();
        }
        
        public static long getCodegenPlanCacheTotal() {
-               return codegenPlanCacheTotal.get();
+               return codegenPlanCacheTotal.longValue();
        }
 
        public static void incrementFunRecompileTime( long delta ) {
-               //note: not synchronized due to use of atomics
-               funRecompileTime.addAndGet(delta);
+               funRecompileTime.add(delta);
        }
        
        public static void incrementFunRecompiles() {
-               //note: not synchronized due to use of atomics
-               funRecompiles.incrementAndGet();
+               funRecompiles.increment();
        }
        
        public static synchronized void incrementParForOptimCount(){
@@ -381,21 +340,21 @@ public class Statistics
        
        public static void reset()
        {
-               hopRecompileTime.set(0);
-               hopRecompilePred.set(0);
-               hopRecompileSB.set(0);
+               hopRecompileTime.reset();
+               hopRecompilePred.reset();
+               hopRecompileSB.reset();
                
-               funRecompiles.set(0);
-               funRecompileTime.set(0);
+               funRecompiles.reset();
+               funRecompileTime.reset();
                
                parforOptCount = 0;
                parforOptTime = 0;
                parforInitTime = 0;
                parforMergeTime = 0;
                
-               lTotalLix.set(0);
-               lTotalLixUIP.set(0);
-               lTotalUIPVar.set(0);
+               lTotalLix.reset();
+               lTotalLixUIP.reset();
+               lTotalUIPVar.reset();
                
                resetJITCompileTime();
                resetJVMgcTime();
@@ -428,27 +387,27 @@ public class Statistics
        }
        
        public static void accSparkParallelizeTime(long t) {
-               sparkParallelize.addAndGet(t);
+               sparkParallelize.add(t);
        }
 
        public static void incSparkParallelizeCount(long c) {
-               sparkParallelizeCount.addAndGet(c);
+               sparkParallelizeCount.add(c);
        }
 
        public static void accSparkCollectTime(long t) {
-               sparkCollect.addAndGet(t);
+               sparkCollect.add(t);
        }
 
        public static void incSparkCollectCount(long c) {
-               sparkCollectCount.addAndGet(c);
+               sparkCollectCount.add(c);
        }
 
        public static void accSparkBroadCastTime(long t) {
-               sparkBroadcast.addAndGet(t);
+               sparkBroadcast.add(t);
        }
 
        public static void incSparkBroadcastCount(long c) {
-               sparkBroadcastCount.addAndGet(c);
+               sparkBroadcastCount.add(c);
        }
        
        
@@ -467,7 +426,6 @@ public class Statistics
                        if( inst instanceof FunctionCallCPInstruction ) {
                                FunctionCallCPInstruction extfunct = 
(FunctionCallCPInstruction)inst;
                                opcode = extfunct.getFunctionName();
-                               //opcode = 
extfunct.getNamespace()+Program.KEY_DELIM+extfunct.getFunctionName();
                        }       
                }
                else //CPInstructions
@@ -476,7 +434,6 @@ public class Statistics
                        if( inst instanceof FunctionCallCPInstruction ) {
                                FunctionCallCPInstruction extfunct = 
(FunctionCallCPInstruction)inst;
                                opcode = extfunct.getFunctionName();
-                               //opcode = 
extfunct.getNamespace()+Program.KEY_DELIM+extfunct.getFunctionName();
                        }               
                }
                
@@ -485,18 +442,16 @@ public class Statistics
 
        /**
         * "Maintains" or adds time to per instruction/op timers, also 
increments associated count
-        * @param instructionName       name of the instruction/op
-        * @param timeNanos                             time in nano seconds
+        * @param instructionName name of the instruction/op
+        * @param timeNanos time in nano seconds
         */
        public synchronized static void maintainCPHeavyHitters( String 
instructionName, long timeNanos )
        {
-               Long oldVal = _cpInstTime.get(instructionName);
-               Long newVal = timeNanos + ((oldVal!=null) ? oldVal : 0);
-               _cpInstTime.put(instructionName, newVal);
+               Long oldVal = _cpInstTime.getOrDefault(instructionName, 0L);
+               _cpInstTime.put(instructionName, oldVal + timeNanos);
 
-               Long oldCnt = _cpInstCounts.get(instructionName);
-               Long newCnt = 1 + ((oldCnt!=null) ? oldCnt : 0);
-               _cpInstCounts.put(instructionName, newCnt);
+               Long oldCnt = _cpInstCounts.getOrDefault(instructionName, 0L);
+               _cpInstCounts.put(instructionName, oldCnt + 1);
        }
 
 
@@ -587,23 +542,23 @@ public class Statistics
        }
        
        public static long getHopRecompileTime(){
-               return hopRecompileTime.get();
+               return hopRecompileTime.longValue();
        }
        
        public static long getHopRecompiledPredDAGs(){
-               return hopRecompilePred.get();
+               return hopRecompilePred.longValue();
        }
        
        public static long getHopRecompiledSBDAGs(){
-               return hopRecompileSB.get();
+               return hopRecompileSB.longValue();
        }
        
        public static long getFunRecompileTime(){
-               return funRecompileTime.get();
+               return funRecompileTime.longValue();
        }
        
        public static long getFunRecompiles(){
-               return funRecompiles.get();
+               return funRecompiles.longValue();
        }
                
        public static long getParforOptCount(){
@@ -681,14 +636,14 @@ public class Statistics
                                String lazy = 
SparkExecutionContext.isLazySparkContextCreation() ? "(lazy)" : "(eager)";
                                sb.append("Spark ctx create time "+lazy+":\t"+
                                                String.format("%.3f", 
((double)sparkCtxCreateTime)*1e-9)  + " sec.\n" ); // nanoSec --> sec
-                               
                                sb.append("Spark trans counts (par,bc,col):" +
-                                               String.format("%d/%d/%d.\n", 
sparkParallelizeCount.get(), sparkBroadcastCount.get(), 
sparkCollectCount.get()));
+                                               String.format("%d/%d/%d.\n", 
sparkParallelizeCount.longValue(), 
+                                                               
sparkBroadcastCount.longValue(), sparkCollectCount.longValue()));
                                sb.append("Spark trans times (par,bc,col):\t" +
                                                String.format("%.3f/%.3f/%.3f 
secs.\n", 
-                                                                
((double)sparkParallelize.get())*1e-9,
-                                                                
((double)sparkBroadcast.get())*1e-9,
-                                                                
((double)sparkCollect.get())*1e-9));
+                                                                
((double)sparkParallelize.longValue())*1e-9,
+                                                                
((double)sparkBroadcast.longValue())*1e-9,
+                                                                
((double)sparkCollect.longValue())*1e-9));
                        }
                        if( parforOptCount>0 ){
                                sb.append("ParFor loops optimized:\t\t" + 
getParforOptCount() + ".\n");

Reply via email to