commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nico...@apache.org
Subject svn commit: r618223 - in /commons/sandbox/monitoring/trunk/src: main/java/org/apache/commons/monitoring/ main/java/org/apache/commons/monitoring/impl/ test/java/org/apache/commons/monitoring/ test/java/org/apache/commons/monitoring/impl/
Date Mon, 04 Feb 2008 10:15:00 GMT
Author: nicolas
Date: Mon Feb  4 02:14:57 2008
New Revision: 618223

URL: http://svn.apache.org/viewvc?rev=618223&view=rev
Log:
reverted change to use System.nanotime() as documented in http://wiki.apache.org/commons/Monitoring/Precision

Modified:
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java
    commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java
    commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java?rev=618223&r1=618222&r2=618223&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/StopWatch.java
Mon Feb  4 02:14:57 2008
@@ -57,7 +57,7 @@
     {
         super();
         this.monitor = monitor;
-        startedAt = time();
+        startedAt = nanotime();
         if ( monitor != null )
         {
             monitor.getGauge( Monitor.CONCURRENCY ).increment();
@@ -81,7 +81,7 @@
         else
         {
             // Still running !
-            delay = time() - startedAt - pauseDelay;
+            delay = nanotime() - startedAt - pauseDelay;
         }
         return delay;
     }
@@ -94,7 +94,7 @@
     {
         if ( !paused && !stoped )
         {
-            stopedAt = time();
+            stopedAt = nanotime();
             paused = true;
         }
     }
@@ -106,7 +106,7 @@
     {
         if ( paused && !stoped )
         {
-            pauseDelay = time() - stopedAt;
+            pauseDelay = nanotime() - stopedAt;
             paused = false;
             stopedAt = 0;
         }
@@ -120,7 +120,7 @@
     {
         if ( !stoped )
         {
-            long t = time();
+            long t = nanotime();
             if ( paused )
             {
                 pauseDelay = t - stopedAt;
@@ -210,16 +210,17 @@
     }
 
     /**
-     * Simple benchmark demonstrates that java5 System.currentTimeMillis is FAR
-     * quicker than System.nanoTime. The lack of precision for using ms as time
-     * unit is not blocking for a monitoring toolkit (it may be for a profiler)
+     * Returns the current value of the most precise available system timer, in
+     * nanoseconds. The real precision depends on the JVM and the underlying
+     * system. On JRE before java5, <tt>backport-util-concurrent</tt> provides
+     * some limited support for equivalent timer.
      *
-     * @return time with ms precision
-     * @see org.apache.commons.monitoring.bench.CurrentTimeMillisVsNanoTime
+     * @see System#nanoTime()
+     * @return time in nanosecond
      */
-    protected long time()
+    protected long nanotime()
     {
-        return System.currentTimeMillis();
+        return System.nanoTime();
     }
 
     /**

Modified: commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java?rev=618223&r1=618222&r2=618223&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java
(original)
+++ commons/sandbox/monitoring/trunk/src/main/java/org/apache/commons/monitoring/impl/ThreadSafeGauge.java
Mon Feb  4 02:14:57 2008
@@ -105,7 +105,7 @@
 
     protected void computeSums()
     {
-        long now = time();
+        long now = nanotime();
         if ( Double.isNaN( firstUse ) )
         {
             firstUse = now;
@@ -120,15 +120,15 @@
         lastUse = now;
     }
 
-    protected long time()
+    protected long nanotime()
     {
-        return System.currentTimeMillis();
+        return System.nanoTime();
     }
 
     @Override
     public synchronized double getMean()
     {
-        return ( (double) sum ) / ( time() - firstUse );
+        return ( (double) sum ) / ( nanotime() - firstUse );
     }
 
     @Override

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java?rev=618223&r1=618222&r2=618223&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java
(original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/StopWatchTest.java
Mon Feb  4 02:14:57 2008
@@ -104,7 +104,8 @@
             super( monitor );
         }
 
-        protected long time()
+        @Override
+        protected long nanotime()
         {
             return time;
         }

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java?rev=618223&r1=618222&r2=618223&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java
(original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/CompositeValuesMonitorTest.java
Mon Feb  4 02:14:57 2008
@@ -83,7 +83,7 @@
         gauge.increment();
         assertEquals( 1, gauge.get() );
         Gauge secondary = composite.createSecondary();
-        assertEquals( 0, secondary.get() );
+        assertEquals( 1, secondary.get() );
 
         gauge.increment();
         assertEquals( 2, gauge.get() );

Modified: commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java?rev=618223&r1=618222&r2=618223&view=diff
==============================================================================
--- commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java
(original)
+++ commons/sandbox/monitoring/trunk/src/test/java/org/apache/commons/monitoring/impl/ThreadSafeGaugeTest.java
Mon Feb  4 02:14:57 2008
@@ -100,7 +100,7 @@
         }
 
         @Override
-        protected long time()
+        protected long nanotime()
         {
             return time;
         }



Mime
View raw message