geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject [3/4] incubator-geode git commit: Using System.nanoTime in RemoteDUnitVM
Date Mon, 25 Jan 2016 19:47:59 GMT
Using System.nanoTime in RemoteDUnitVM

This should be more efficient than System.currentTimeMillis.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/20d47eb4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/20d47eb4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/20d47eb4

Branch: refs/heads/develop
Commit: 20d47eb4104b558e5fae0b10ca21673f7b787f06
Parents: 68e9ec2
Author: Dan Smith <upthewaterspout@apache.org>
Authored: Thu Jan 21 15:33:47 2016 -0800
Committer: Dan Smith <upthewaterspout@apache.org>
Committed: Mon Jan 25 11:37:47 2016 -0800

----------------------------------------------------------------------
 .../test/dunit/standalone/RemoteDUnitVM.java    | 41 ++++++++++----------
 1 file changed, 21 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/20d47eb4/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
index 51c6177..6d016bc 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/test/dunit/standalone/RemoteDUnitVM.java
@@ -18,6 +18,7 @@ package com.gemstone.gemfire.test.dunit.standalone;
 
 import java.rmi.RemoteException;
 import java.rmi.server.UnicastRemoteObject;
+import java.util.concurrent.TimeUnit;
 
 import org.apache.logging.log4j.Logger;
 
@@ -50,15 +51,24 @@ public class RemoteDUnitVM extends UnicastRemoteObject implements RemoteDUnitVMI
    public MethExecutorResult executeMethodOnObject( Object obj, String methodName ) {
      String name = obj.getClass().getName() + "." + methodName + 
        " on object: " + obj;
-     logger.info("Received method: " + name);
-     long start = System.currentTimeMillis();
+     long start = start(name);
      MethExecutorResult result = MethExecutor.executeObject( obj, methodName );
-     long delta = System.currentTimeMillis() - start;
-     logger.info( "Got result: " + result.toString().trim()  + " from " +
-               name + " (took " + delta + " ms)");
+     logDelta(name, start, result);
      return result;
    }
 
+  protected long start(String name) {
+    logger.info("Received method: " + name);
+    long start = System.nanoTime();
+    return start;
+  }
+
+  protected void logDelta(String name, long start, MethExecutorResult result) {
+    long delta = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - start);
+     logger.info( "Got result: " + result.toString() + " from " + name + 
+               " (took " + delta + " ms)");
+  }
+
    /**
     * Executes a given instance method on a given object with the given
     * arguments. 
@@ -69,13 +79,10 @@ public class RemoteDUnitVM extends UnicastRemoteObject implements RemoteDUnitVMI
      String name = obj.getClass().getName() + "." + methodName + 
               (args != null ? " with " + args.length + " args": "") +
        " on object: " + obj;
-     logger.info("Received method: " + name);
-     long start = System.currentTimeMillis();
+     long start = start(name);
      MethExecutorResult result = 
        MethExecutor.executeObject(obj, methodName, args);
-     long delta = System.currentTimeMillis() - start;
-     logger.info( "Got result: " + result.toString() + " from " + name + 
-               " (took " + delta + " ms)");
+     logDelta(name, start, result);
      return result;
    }
 
@@ -90,12 +97,9 @@ public class RemoteDUnitVM extends UnicastRemoteObject implements RemoteDUnitVMI
    */ 
    public MethExecutorResult executeMethodOnClass( String className, String methodName )
{
      String name = className + "." + methodName;
-     logger.info("Received method: " +  name);
-     long start = System.currentTimeMillis();
+     long start = start(name);
      MethExecutorResult result = MethExecutor.execute( className, methodName );
-     long delta = System.currentTimeMillis() - start;
-     logger.info( "Got result: " + result.toString() + " from " + name + 
-               " (took " + delta + " ms)");
+     logDelta(name, start, result);
      
      return result;
    }
@@ -109,13 +113,10 @@ public class RemoteDUnitVM extends UnicastRemoteObject implements RemoteDUnitVMI
                                                   Object[] args) {
      String name = className + "." + methodName + 
        (args != null ? " with " + args.length + " args": "");
-     logger.info("Received method: " + name);
-     long start = System.currentTimeMillis();
+     long start = start(name);
      MethExecutorResult result = 
        MethExecutor.execute(className, methodName, args);
-     long delta = System.currentTimeMillis() - start;
-     logger.info( "Got result: " + result.toString() + " from " + name +
-               " (took " + delta + " ms)");
+     logDelta(name, start, result);
      return result;
    }
 


Mime
View raw message