8079561: Add a method to convert counters to milliseconds
authorbrutisso
Fri, 08 May 2015 10:30:16 +0200
changeset 30608 d79880a5cf2f
parent 30586 23e6e981e89c
child 30609 211c22831646
8079561: Add a method to convert counters to milliseconds Reviewed-by: mgerdin, ehelin
hotspot/src/share/vm/runtime/task.cpp
hotspot/src/share/vm/runtime/timer.cpp
hotspot/src/share/vm/runtime/timer.hpp
--- a/hotspot/src/share/vm/runtime/task.cpp	Thu May 07 10:32:42 2015 +0200
+++ b/hotspot/src/share/vm/runtime/task.cpp	Fri May 08 10:30:16 2015 +0200
@@ -53,7 +53,7 @@
   if (ProfilerCheckIntervals) {
     _ticks++;
     _timer.stop();
-    int ms = (int)(_timer.seconds() * 1000.0);
+    int ms = (int)_timer.milliseconds();
     _timer.reset();
     _timer.start();
     if (ms >= PeriodicTask::max_interval) ms = PeriodicTask::max_interval - 1;
--- a/hotspot/src/share/vm/runtime/timer.cpp	Thu May 07 10:32:42 2015 +0200
+++ b/hotspot/src/share/vm/runtime/timer.cpp	Fri May 08 10:30:16 2015 +0200
@@ -28,9 +28,12 @@
 #include "utilities/ostream.hpp"
 
 double TimeHelper::counter_to_seconds(jlong counter) {
-  double count = (double) counter;
   double freq  = (double) os::elapsed_frequency();
-  return counter/freq;
+  return counter / freq;
+}
+
+double TimeHelper::counter_to_millis(jlong counter) {
+  return counter_to_seconds(counter) * 1000.0;
 }
 
 void elapsedTimer::add(elapsedTimer t) {
@@ -56,8 +59,7 @@
 }
 
 jlong elapsedTimer::milliseconds() const {
-  jlong ticks_per_ms = os::elapsed_frequency() / 1000;
-  return _counter / ticks_per_ms;
+  return TimeHelper::counter_to_millis(_counter);
 }
 
 jlong elapsedTimer::active_ticks() const {
@@ -86,11 +88,8 @@
 
 jlong TimeStamp::milliseconds() const {
   assert(is_updated(), "must not be clear");
-
   jlong new_count = os::elapsed_counter();
-  jlong count = new_count - _counter;
-  jlong ticks_per_ms = os::elapsed_frequency() / 1000;
-  return count / ticks_per_ms;
+  return TimeHelper::counter_to_millis(new_count - _counter);
 }
 
 jlong TimeStamp::ticks_since_update() const {
--- a/hotspot/src/share/vm/runtime/timer.hpp	Thu May 07 10:32:42 2015 +0200
+++ b/hotspot/src/share/vm/runtime/timer.hpp	Fri May 08 10:30:16 2015 +0200
@@ -123,6 +123,7 @@
 class TimeHelper {
  public:
   static double counter_to_seconds(jlong counter);
+  static double counter_to_millis(jlong counter);
 };
 
 #endif // SHARE_VM_RUNTIME_TIMER_HPP