hotspot/src/share/vm/runtime/timer.cpp
changeset 18025 b7bcf7497f93
parent 14634 fdd9909928ae
child 22827 07d991d45a51
equal deleted inserted replaced
18024:f9e300086063 18025:b7bcf7497f93
     1 /*
     1 /*
     2  * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.
     7  * published by the Free Software Foundation.
    37 #endif
    37 #endif
    38 #ifdef TARGET_OS_FAMILY_bsd
    38 #ifdef TARGET_OS_FAMILY_bsd
    39 # include "os_bsd.inline.hpp"
    39 # include "os_bsd.inline.hpp"
    40 #endif
    40 #endif
    41 
    41 
       
    42 double TimeHelper::counter_to_seconds(jlong counter) {
       
    43   double count = (double) counter;
       
    44   double freq  = (double) os::elapsed_frequency();
       
    45   return counter/freq;
       
    46 }
    42 
    47 
    43 void elapsedTimer::add(elapsedTimer t) {
    48 void elapsedTimer::add(elapsedTimer t) {
    44   _counter += t._counter;
    49   _counter += t._counter;
    45 }
    50 }
    46 
    51 
    57     _active = false;
    62     _active = false;
    58   }
    63   }
    59 }
    64 }
    60 
    65 
    61 double elapsedTimer::seconds() const {
    66 double elapsedTimer::seconds() const {
    62   double count = (double) _counter;
    67  return TimeHelper::counter_to_seconds(_counter);
    63   double freq  = (double) os::elapsed_frequency();
       
    64   return count/freq;
       
    65 }
    68 }
    66 
    69 
    67 jlong elapsedTimer::milliseconds() const {
    70 jlong elapsedTimer::milliseconds() const {
    68   jlong ticks_per_ms = os::elapsed_frequency() / 1000;
    71   jlong ticks_per_ms = os::elapsed_frequency() / 1000;
    69   return _counter / ticks_per_ms;
    72   return _counter / ticks_per_ms;
    88 }
    91 }
    89 
    92 
    90 double TimeStamp::seconds() const {
    93 double TimeStamp::seconds() const {
    91   assert(is_updated(), "must not be clear");
    94   assert(is_updated(), "must not be clear");
    92   jlong new_count = os::elapsed_counter();
    95   jlong new_count = os::elapsed_counter();
    93   double count = (double) new_count - _counter;
    96   return TimeHelper::counter_to_seconds(new_count - _counter);
    94   double freq  = (double) os::elapsed_frequency();
       
    95   return count/freq;
       
    96 }
    97 }
    97 
    98 
    98 jlong TimeStamp::milliseconds() const {
    99 jlong TimeStamp::milliseconds() const {
    99   assert(is_updated(), "must not be clear");
   100   assert(is_updated(), "must not be clear");
   100 
   101 
   108   assert(is_updated(), "must not be clear");
   109   assert(is_updated(), "must not be clear");
   109   return os::elapsed_counter() - _counter;
   110   return os::elapsed_counter() - _counter;
   110 }
   111 }
   111 
   112 
   112 TraceTime::TraceTime(const char* title,
   113 TraceTime::TraceTime(const char* title,
   113                      bool doit,
   114                      bool doit) {
   114                      bool print_cr,
       
   115                      outputStream* logfile) {
       
   116   _active   = doit;
   115   _active   = doit;
   117   _verbose  = true;
   116   _verbose  = true;
   118   _print_cr = print_cr;
       
   119   _logfile = (logfile != NULL) ? logfile : tty;
       
   120 
   117 
   121   if (_active) {
   118   if (_active) {
   122     _accum = NULL;
   119     _accum = NULL;
   123     _logfile->stamp(PrintGCTimeStamps);
   120     tty->stamp(PrintGCTimeStamps);
   124     _logfile->print("[%s", title);
   121     tty->print("[%s", title);
   125     _logfile->flush();
   122     tty->flush();
   126     _t.start();
   123     _t.start();
   127   }
   124   }
   128 }
   125 }
   129 
   126 
   130 TraceTime::TraceTime(const char* title,
   127 TraceTime::TraceTime(const char* title,
   131                      elapsedTimer* accumulator,
   128                      elapsedTimer* accumulator,
   132                      bool doit,
   129                      bool doit,
   133                      bool verbose,
   130                      bool verbose) {
   134                      outputStream* logfile) {
       
   135   _active = doit;
   131   _active = doit;
   136   _verbose = verbose;
   132   _verbose = verbose;
   137   _print_cr = true;
       
   138   _logfile = (logfile != NULL) ? logfile : tty;
       
   139   if (_active) {
   133   if (_active) {
   140     if (_verbose) {
   134     if (_verbose) {
   141       _logfile->stamp(PrintGCTimeStamps);
   135       tty->stamp(PrintGCTimeStamps);
   142       _logfile->print("[%s", title);
   136       tty->print("[%s", title);
   143       _logfile->flush();
   137       tty->flush();
   144     }
   138     }
   145     _accum = accumulator;
   139     _accum = accumulator;
   146     _t.start();
   140     _t.start();
   147   }
   141   }
   148 }
   142 }
   150 TraceTime::~TraceTime() {
   144 TraceTime::~TraceTime() {
   151   if (_active) {
   145   if (_active) {
   152     _t.stop();
   146     _t.stop();
   153     if (_accum!=NULL) _accum->add(_t);
   147     if (_accum!=NULL) _accum->add(_t);
   154     if (_verbose) {
   148     if (_verbose) {
   155       if (_print_cr) {
   149       tty->print_cr(", %3.7f secs]", _t.seconds());
   156         _logfile->print_cr(", %3.7f secs]", _t.seconds());
   150       tty->flush();
   157       } else {
       
   158         _logfile->print(", %3.7f secs]", _t.seconds());
       
   159       }
       
   160       _logfile->flush();
       
   161     }
   151     }
   162   }
   152   }
   163 }
   153 }
   164 
   154 
   165 TraceCPUTime::TraceCPUTime(bool doit,
   155 TraceCPUTime::TraceCPUTime(bool doit,