< prev index next >

src/share/vm/runtime/timer.cpp

Print this page
rev 7854 : imported patch 8027962-per-phase-timing-measurements-for-strong-roots-processing


   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 count = (double) counter;
  32   double freq  = (double) os::elapsed_frequency();
  33   return counter/freq;
  34 }
  35 
  36 void elapsedTimer::add(elapsedTimer t) {
  37   _counter += t._counter;
  38 }
  39 
  40 void elapsedTimer::start() {
  41   if (!_active) {
  42     _active = true;
  43     _start_counter = os::elapsed_counter();
  44   }
  45 }
  46 
  47 void elapsedTimer::stop() {
  48   if (_active) {


 120   _verbose = verbose;
 121   if (_active) {
 122     if (_verbose) {
 123       tty->stamp(PrintGCTimeStamps);
 124       tty->print("[%s", title);
 125       tty->flush();
 126     }
 127     _accum = accumulator;
 128     _t.start();
 129   }
 130 }
 131 
 132 TraceTime::~TraceTime() {
 133   if (_active) {
 134     _t.stop();
 135     if (_accum!=NULL) _accum->add(_t);
 136     if (_verbose) {
 137       tty->print_cr(", %3.7f secs]", _t.seconds());
 138       tty->flush();
 139     }














 140   }
 141 }
 142 
 143 TraceCPUTime::TraceCPUTime(bool doit,
 144                bool print_cr,
 145                outputStream *logfile) :
 146   _active(doit),
 147   _print_cr(print_cr),
 148   _starting_user_time(0.0),
 149   _starting_system_time(0.0),
 150   _starting_real_time(0.0),
 151   _logfile(logfile),
 152   _error(false) {
 153   if (_active) {
 154     if (logfile != NULL) {
 155       _logfile = logfile;
 156     } else {
 157       _logfile = tty;
 158     }
 159 




   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  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 #ifdef INCLUDE_ALL_GCS
  30 #include "gc_implementation/g1/g1GCPhaseTimes.hpp"
  31 #endif
  32 
  33 double TimeHelper::counter_to_seconds(jlong counter) {
  34   double count = (double) counter;
  35   double freq  = (double) os::elapsed_frequency();
  36   return counter/freq;
  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) {


 123   _verbose = verbose;
 124   if (_active) {
 125     if (_verbose) {
 126       tty->stamp(PrintGCTimeStamps);
 127       tty->print("[%s", title);
 128       tty->flush();
 129     }
 130     _accum = accumulator;
 131     _t.start();
 132   }
 133 }
 134 
 135 TraceTime::~TraceTime() {
 136   if (_active) {
 137     _t.stop();
 138     if (_accum!=NULL) _accum->add(_t);
 139     if (_verbose) {
 140       tty->print_cr(", %3.7f secs]", _t.seconds());
 141       tty->flush();
 142     }
 143   }
 144 }
 145 
 146 TrackPhaseTime::TrackPhaseTime(GCPhaseTimeTracker *data, uint phase) :
 147   _data(data), _phase(phase) {
 148   if (_data != NULL && _data->active()) {
 149     _last = os::elapsed_counter();
 150   }
 151 }
 152 
 153 TrackPhaseTime::~TrackPhaseTime() {
 154   if (_data != NULL && _data->active()) {
 155     double time = (double)(os::elapsed_counter() - _last) * 1000.0 / os::elapsed_frequency();
 156     _data->set_value(_phase, time);
 157   }
 158 }
 159 
 160 TraceCPUTime::TraceCPUTime(bool doit,
 161                bool print_cr,
 162                outputStream *logfile) :
 163   _active(doit),
 164   _print_cr(print_cr),
 165   _starting_user_time(0.0),
 166   _starting_system_time(0.0),
 167   _starting_real_time(0.0),
 168   _logfile(logfile),
 169   _error(false) {
 170   if (_active) {
 171     if (logfile != NULL) {
 172       _logfile = logfile;
 173     } else {
 174       _logfile = tty;
 175     }
 176 


< prev index next >