< prev index next >

src/share/vm/runtime/timer.cpp

Print this page




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "oops/oop.inline.hpp"
  27 #include "runtime/timer.hpp"
  28 #include "utilities/ostream.hpp"
  29 
  30 double TimeHelper::counter_to_seconds(jlong counter) {
  31   double freq  = (double) os::elapsed_frequency();
  32   return counter / freq;
  33 }
  34 
  35 double TimeHelper::counter_to_millis(jlong counter) {
  36   return counter_to_seconds(counter) * 1000.0;
  37 }
  38 
















  39 void elapsedTimer::add(elapsedTimer t) {
  40   _counter += t._counter;
  41 }
  42 
  43 void elapsedTimer::start() {
  44   if (!_active) {
  45     _active = true;
  46     _start_counter = os::elapsed_counter();
  47   }
  48 }
  49 
  50 void elapsedTimer::stop() {
  51   if (_active) {
  52     _counter += os::elapsed_counter() - _start_counter;
  53     _active = false;
  54   }
  55 }
  56 
  57 double elapsedTimer::seconds() const {
  58  return TimeHelper::counter_to_seconds(_counter);




  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "oops/oop.inline.hpp"
  27 #include "runtime/timer.hpp"
  28 #include "utilities/ostream.hpp"
  29 
  30 double TimeHelper::counter_to_seconds(jlong counter) {
  31   double freq  = (double) os::elapsed_frequency();
  32   return counter / freq;
  33 }
  34 
  35 double TimeHelper::counter_to_millis(jlong counter) {
  36   return counter_to_seconds(counter) * 1000.0;
  37 }
  38 
  39 elapsedTimer::elapsedTimer(jlong time, jlong timeUnitsPerSecond) {
  40   _active = false;
  41   jlong osTimeUnitsPerSecond = os::elapsed_frequency();
  42   assert(osTimeUnitsPerSecond % 1000 == 0, "must be");
  43   assert(timeUnitsPerSecond % 1000 == 0, "must be");
  44   while (osTimeUnitsPerSecond < timeUnitsPerSecond) {
  45     timeUnitsPerSecond /= 1000;
  46     time *= 1000;
  47   }
  48   while (osTimeUnitsPerSecond > timeUnitsPerSecond) {
  49     timeUnitsPerSecond *= 1000;
  50     time /= 1000;
  51   }
  52   _counter = time;
  53 }
  54 
  55 void elapsedTimer::add(elapsedTimer t) {
  56   _counter += t._counter;
  57 }
  58 
  59 void elapsedTimer::start() {
  60   if (!_active) {
  61     _active = true;
  62     _start_counter = os::elapsed_counter();
  63   }
  64 }
  65 
  66 void elapsedTimer::stop() {
  67   if (_active) {
  68     _counter += os::elapsed_counter() - _start_counter;
  69     _active = false;
  70   }
  71 }
  72 
  73 double elapsedTimer::seconds() const {
  74  return TimeHelper::counter_to_seconds(_counter);


< prev index next >