You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by re...@apache.org on 2016/01/11 16:21:27 UTC

[1/2] git commit: updated refs/heads/master to 4014169

Repository: cloudstack
Updated Branches:
  refs/heads/master 2a9927a55 -> 4014169cc


Factor in inaccurancy of System.nanoTime


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/dbb10a4e
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/dbb10a4e
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/dbb10a4e

Branch: refs/heads/master
Commit: dbb10a4ed5dc763b4c603e5cc3f2b70a202c0a2b
Parents: d681574
Author: Bob <bv...@schubergphilis.com>
Authored: Fri Jan 8 13:31:27 2016 +0100
Committer: Bob <bv...@schubergphilis.com>
Committed: Fri Jan 8 13:31:27 2016 +0100

----------------------------------------------------------------------
 utils/src/test/java/com/cloud/utils/TestProfiler.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/dbb10a4e/utils/src/test/java/com/cloud/utils/TestProfiler.java
----------------------------------------------------------------------
diff --git a/utils/src/test/java/com/cloud/utils/TestProfiler.java b/utils/src/test/java/com/cloud/utils/TestProfiler.java
index 25b6518..f0e163e 100644
--- a/utils/src/test/java/com/cloud/utils/TestProfiler.java
+++ b/utils/src/test/java/com/cloud/utils/TestProfiler.java
@@ -28,9 +28,12 @@ import com.cloud.utils.testcase.Log4jEnabledTestCase;
 public class TestProfiler extends Log4jEnabledTestCase {
     protected final static Logger s_logger = Logger.getLogger(TestProfiler.class);
 
-    private static final long ONE_SECOND = 1000l;
     private static final long MILLIS_FACTOR = 1000l;
     private static final int MARGIN = 100;
+    // Profiler uses System.nanoTime which is not reliable on the millisecond
+    // A sleep of 1000 milliseconds CAN be measured as 999 milliseconds
+    // Therefore make the second larger, by 10% of the margin
+    private static final long ONE_SECOND = 1000l + (MARGIN / 10);
     private static final double EXPONENT = 3d;
 
     @Test


[2/2] git commit: updated refs/heads/master to 4014169

Posted by re...@apache.org.
Merge pull request #1324 from bheuvel/testprofiler-second

Factor in inaccurancy of System.nanoTime in class ProfilerThe time diff measurement by the class Profiler, is done by System.nanoTime().
System.nanoTime() is not 100% accurate (lots of info on this on the web). The inaccurance seems to vary/depend with different dependencies (multi-core/OS/kernels).

Problem:
In my case the code which measures `Thread.sleep(ONE_SECOND);` ~~takes~~ measures 999 milliseconds, which breaks the test expecting the sleep of 1000 milliseconds to ~~take~~ measure at least 1000 milliseconds.

Solution:
A `MARGIN` (of 100 milliseconds) is already present to factor in some time for overhead/surrounding code which adds time. Another margin could be added to factor in the possible time measurement error.
To limit additional lines of code, the constant `ONE_SECOND`, which is used by the testcase (sleep), is increased from 1000 milliseconds to `1000l + (MARGIN / 10)` (effectively 1010 milliseconds).

Thereby the inaccurancy on my system of ~1% ("faster") is caught as the `sleep(1010)` is measured as '1009' milliseconds.

* pr/1324:
  Factor in inaccurancy of System.nanoTime

Signed-off-by: Remi Bergsma <gi...@remi.nl>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4014169c
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4014169c
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4014169c

Branch: refs/heads/master
Commit: 4014169ccb5fd47a875f2593f663c27866d5aa0b
Parents: 2a9927a dbb10a4
Author: Remi Bergsma <gi...@remi.nl>
Authored: Mon Jan 11 16:20:51 2016 +0100
Committer: Remi Bergsma <gi...@remi.nl>
Committed: Mon Jan 11 16:20:51 2016 +0100

----------------------------------------------------------------------
 utils/src/test/java/com/cloud/utils/TestProfiler.java | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
----------------------------------------------------------------------