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:28 UTC

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

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(-)
----------------------------------------------------------------------