← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1989: Added debug timing util class

 

------------------------------------------------------------
revno: 1989
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Mon 2010-06-14 19:48:23 +0200
message:
  Added debug timing util class
added:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Timer.java


--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk

Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Timer.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Timer.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Timer.java	2010-06-14 17:48:23 +0000
@@ -0,0 +1,51 @@
+package org.hisp.dhis.system.util;
+
+public class Timer
+{
+    private long startTime;
+    
+    private boolean printDisabled;
+    
+    public void start()
+    {
+        startTime = System.nanoTime();
+    }
+    
+    public long getSplitTime()
+    {
+        return getSplitTime( "Split" );
+    }
+    
+    public long getSplitTime( String msg )
+    {
+        long endTime = System.nanoTime();
+        
+        long time = ( endTime - startTime ) / 1000;
+     
+        if ( !printDisabled )
+        {
+            System.out.println( msg  + ": " + time );
+        }
+        
+        return time;
+    }
+    
+    public long getTime( String msg )
+    {
+        long time = getSplitTime( msg );
+                
+        start();
+        
+        return time;
+    }
+    
+    public long getTime()
+    {
+        return getTime( "Time" );
+    }
+    
+    public void disablePrint()
+    {
+        this.printDisabled = true;
+    }
+}