hotspot/src/share/vm/runtime/timer.hpp
changeset 37161 e881f320966e
parent 36178 9739f8c767da
equal deleted inserted replaced
37157:2a0fdb3e2a19 37161:e881f320966e
    23  */
    23  */
    24 
    24 
    25 #ifndef SHARE_VM_RUNTIME_TIMER_HPP
    25 #ifndef SHARE_VM_RUNTIME_TIMER_HPP
    26 #define SHARE_VM_RUNTIME_TIMER_HPP
    26 #define SHARE_VM_RUNTIME_TIMER_HPP
    27 
    27 
    28 #include "logging/logTag.hpp"
       
    29 #include "utilities/globalDefinitions.hpp"
    28 #include "utilities/globalDefinitions.hpp"
    30 
    29 
    31 // Timers for simple measurement.
    30 // Timers for simple measurement.
    32 
    31 
    33 class elapsedTimer VALUE_OBJ_CLASS_SPEC {
    32 class elapsedTimer VALUE_OBJ_CLASS_SPEC {
    71   jlong ticks() const { return _counter; }
    70   jlong ticks() const { return _counter; }
    72   // ticks elapsed since last update
    71   // ticks elapsed since last update
    73   jlong ticks_since_update() const;
    72   jlong ticks_since_update() const;
    74 };
    73 };
    75 
    74 
    76 // TraceTime is used for tracing the execution time of a block
       
    77 // Usage:
       
    78 //  { TraceTime t("block time")
       
    79 //    some_code();
       
    80 //  }
       
    81 //
       
    82 
       
    83 class TraceTime: public StackObj {
       
    84  private:
       
    85   bool          _active;    // do timing
       
    86   bool          _verbose;   // report every timing
       
    87   elapsedTimer  _t;         // timer
       
    88   elapsedTimer* _accum;     // accumulator
       
    89   const char*   _title;     // name of timer
       
    90   LogTagType    _tag;       // stream to print to
       
    91 
       
    92  public:
       
    93   // Constructors
       
    94   TraceTime(const char* title,
       
    95             bool doit = true,
       
    96             LogTagType tag = LogTag::__NO_TAG);
       
    97   TraceTime(const char* title,
       
    98             elapsedTimer* accumulator,
       
    99             bool doit = true,
       
   100             bool verbose = false,
       
   101             LogTagType tag = LogTag::__NO_TAG);
       
   102   ~TraceTime();
       
   103 
       
   104   // Accessors
       
   105   void set_verbose(bool verbose)  { _verbose = verbose; }
       
   106   bool verbose() const            { return _verbose;    }
       
   107 
       
   108   // Activation
       
   109   void suspend()  { if (_active) _t.stop();  }
       
   110   void resume()   { if (_active) _t.start(); }
       
   111 };
       
   112 
       
   113 class TraceCPUTime: public StackObj {
    75 class TraceCPUTime: public StackObj {
   114  private:
    76  private:
   115   bool _active;                 // true if times will be measured and printed
    77   bool _active;                 // true if times will be measured and printed
   116   bool _print_cr;               // if true print carriage return at end
    78   bool _print_cr;               // if true print carriage return at end
   117   double _starting_user_time;   // user time at start of measurement
    79   double _starting_user_time;   // user time at start of measurement