1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/runtime/timer.hpp Sat Dec 01 00:00:00 2007 +0000 1.3 @@ -0,0 +1,121 @@ 1.4 +/* 1.5 + * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or 1.24 + * have any questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +// Timers for simple measurement. 1.29 + 1.30 +class elapsedTimer VALUE_OBJ_CLASS_SPEC { 1.31 + friend class VMStructs; 1.32 + private: 1.33 + jlong _counter; 1.34 + jlong _start_counter; 1.35 + bool _active; 1.36 + public: 1.37 + elapsedTimer() { _active = false; reset(); } 1.38 + void add(elapsedTimer t); 1.39 + void start(); 1.40 + void stop(); 1.41 + void reset() { _counter = 0; } 1.42 + double seconds() const; 1.43 + jlong milliseconds() const; 1.44 + jlong ticks() const { return _counter; } 1.45 + jlong active_ticks() const; 1.46 + bool is_active() const { return _active; } 1.47 +}; 1.48 + 1.49 +// TimeStamp is used for recording when an event took place. 1.50 +class TimeStamp VALUE_OBJ_CLASS_SPEC { 1.51 + private: 1.52 + jlong _counter; 1.53 + public: 1.54 + TimeStamp() { _counter = 0; } 1.55 + void clear() { _counter = 0; } 1.56 + // has the timestamp been updated since being created or cleared? 1.57 + bool is_updated() const { return _counter != 0; } 1.58 + // update to current elapsed time 1.59 + void update(); 1.60 + // update to given elapsed time 1.61 + void update_to(jlong ticks); 1.62 + // returns seconds since updated 1.63 + // (must not be in a cleared state: must have been previously updated) 1.64 + double seconds() const; 1.65 + jlong milliseconds() const; 1.66 + // ticks elapsed between VM start and last update 1.67 + jlong ticks() const { return _counter; } 1.68 + // ticks elapsed since last update 1.69 + jlong ticks_since_update() const; 1.70 +}; 1.71 + 1.72 +// TraceTime is used for tracing the execution time of a block 1.73 +// Usage: 1.74 +// { TraceTime t("block time") 1.75 +// some_code(); 1.76 +// } 1.77 +// 1.78 + 1.79 +class TraceTime: public StackObj { 1.80 + private: 1.81 + bool _active; // do timing 1.82 + bool _verbose; // report every timing 1.83 + bool _print_cr; // add a CR to the end of the timer report 1.84 + elapsedTimer _t; // timer 1.85 + elapsedTimer* _accum; // accumulator 1.86 + outputStream* _logfile; // output log file 1.87 + public: 1.88 + // Constuctors 1.89 + TraceTime(const char* title, 1.90 + bool doit = true, 1.91 + bool print_cr = true, 1.92 + outputStream *logfile = NULL); 1.93 + TraceTime(const char* title, 1.94 + elapsedTimer* accumulator, 1.95 + bool doit = true, 1.96 + bool verbose = false, 1.97 + outputStream *logfile = NULL ); 1.98 + ~TraceTime(); 1.99 + 1.100 + // Accessors 1.101 + void set_verbose(bool verbose) { _verbose = verbose; } 1.102 + bool verbose() const { return _verbose; } 1.103 + 1.104 + // Activation 1.105 + void suspend() { if (_active) _t.stop(); } 1.106 + void resume() { if (_active) _t.start(); } 1.107 +}; 1.108 + 1.109 +class TraceCPUTime: public StackObj { 1.110 + private: 1.111 + bool _active; // true if times will be measured and printed 1.112 + bool _print_cr; // if true print carriage return at end 1.113 + double _starting_user_time; // user time at start of measurement 1.114 + double _starting_system_time; // system time at start of measurement 1.115 + double _starting_real_time; // real time at start of measurement 1.116 + outputStream* _logfile; // output is printed to this stream 1.117 + bool _error; // true if an error occurred, turns off output 1.118 + 1.119 + public: 1.120 + TraceCPUTime(bool doit = true, 1.121 + bool print_cr = true, 1.122 + outputStream *logfile = NULL); 1.123 + ~TraceCPUTime(); 1.124 +};