src/share/vm/runtime/timer.cpp

Print this page
rev 4773 : 8005849: JEP 167: Event-Based JVM Tracing
Reviewed-by: acorn, coleenp, sla
Contributed-by: Karen Kinnear <karen.kinnear@oracle.com>, Bengt Rutisson <bengt.rutisson@oracle.com>, Calvin Cheung <calvin.cheung@oracle.com>, Erik Gahlin <erik.gahlin@oracle.com>, Erik Helin <erik.helin@oracle.com>, Jesper Wilhelmsson <jesper.wilhelmsson@oracle.com>, Keith McGuigan <keith.mcguigan@oracle.com>, Mattias Tobiasson <mattias.tobiasson@oracle.com>, Markus Gronlund <markus.gronlund@oracle.com>, Mikael Auno <mikael.auno@oracle.com>, Nils Eliasson <nils.eliasson@oracle.com>, Nils Loodin <nils.loodin@oracle.com>, Rickard Backman <rickard.backman@oracle.com>, Staffan Larsen <staffan.larsen@oracle.com>, Stefan Karlsson <stefan.karlsson@oracle.com>, Yekaterina Kantserova <yekaterina.kantserova@oracle.com>

@@ -1,7 +1,7 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
  * under the terms of the GNU General Public License version 2 only, as
  * published by the Free Software Foundation.

@@ -37,10 +37,15 @@
 #endif
 #ifdef TARGET_OS_FAMILY_bsd
 # include "os_bsd.inline.hpp"
 #endif
 
+double TimeHelper::counter_to_seconds(jlong counter) {
+  double count = (double) counter;
+  double freq  = (double) os::elapsed_frequency();
+  return counter/freq;
+}
 
 void elapsedTimer::add(elapsedTimer t) {
   _counter += t._counter;
 }
 

@@ -57,13 +62,11 @@
     _active = false;
   }
 }
 
 double elapsedTimer::seconds() const {
-  double count = (double) _counter;
-  double freq  = (double) os::elapsed_frequency();
-  return count/freq;
+ return TimeHelper::counter_to_seconds(_counter);
 }
 
 jlong elapsedTimer::milliseconds() const {
   jlong ticks_per_ms = os::elapsed_frequency() / 1000;
   return _counter / ticks_per_ms;

@@ -88,13 +91,11 @@
 }
 
 double TimeStamp::seconds() const {
   assert(is_updated(), "must not be clear");
   jlong new_count = os::elapsed_counter();
-  double count = (double) new_count - _counter;
-  double freq  = (double) os::elapsed_frequency();
-  return count/freq;
+  return TimeHelper::counter_to_seconds(new_count - _counter);
 }
 
 jlong TimeStamp::milliseconds() const {
   assert(is_updated(), "must not be clear");
 

@@ -108,41 +109,34 @@
   assert(is_updated(), "must not be clear");
   return os::elapsed_counter() - _counter;
 }
 
 TraceTime::TraceTime(const char* title,
-                     bool doit,
-                     bool print_cr,
-                     outputStream* logfile) {
+                     bool doit) {
   _active   = doit;
   _verbose  = true;
-  _print_cr = print_cr;
-  _logfile = (logfile != NULL) ? logfile : tty;
 
   if (_active) {
     _accum = NULL;
-    _logfile->stamp(PrintGCTimeStamps);
-    _logfile->print("[%s", title);
-    _logfile->flush();
+    tty->stamp(PrintGCTimeStamps);
+    tty->print("[%s", title);
+    tty->flush();
     _t.start();
   }
 }
 
 TraceTime::TraceTime(const char* title,
                      elapsedTimer* accumulator,
                      bool doit,
-                     bool verbose,
-                     outputStream* logfile) {
+                     bool verbose) {
   _active = doit;
   _verbose = verbose;
-  _print_cr = true;
-  _logfile = (logfile != NULL) ? logfile : tty;
   if (_active) {
     if (_verbose) {
-      _logfile->stamp(PrintGCTimeStamps);
-      _logfile->print("[%s", title);
-      _logfile->flush();
+      tty->stamp(PrintGCTimeStamps);
+      tty->print("[%s", title);
+      tty->flush();
     }
     _accum = accumulator;
     _t.start();
   }
 }

@@ -150,16 +144,12 @@
 TraceTime::~TraceTime() {
   if (_active) {
     _t.stop();
     if (_accum!=NULL) _accum->add(_t);
     if (_verbose) {
-      if (_print_cr) {
-        _logfile->print_cr(", %3.7f secs]", _t.seconds());
-      } else {
-        _logfile->print(", %3.7f secs]", _t.seconds());
-      }
-      _logfile->flush();
+      tty->print_cr(", %3.7f secs]", _t.seconds());
+      tty->flush();
     }
   }
 }
 
 TraceCPUTime::TraceCPUTime(bool doit,