src/share/vm/runtime/timer.hpp

Tue, 11 May 2010 14:35:43 -0700

author
prr
date
Tue, 11 May 2010 14:35:43 -0700
changeset 1840
fb57d4cf76c2
parent 435
a61af66fc99e
child 1907
c18cbe5936b8
permissions
-rw-r--r--

6931180: Migration to recent versions of MS Platform SDK
6951582: Build problems on win64
Summary: Changes to enable building JDK7 with Microsoft Visual Studio 2010
Reviewed-by: ohair, art, ccheung, dcubed

duke@435 1 /*
duke@435 2 * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
duke@435 19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 20 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 21 * have any questions.
duke@435 22 *
duke@435 23 */
duke@435 24
duke@435 25 // Timers for simple measurement.
duke@435 26
duke@435 27 class elapsedTimer VALUE_OBJ_CLASS_SPEC {
duke@435 28 friend class VMStructs;
duke@435 29 private:
duke@435 30 jlong _counter;
duke@435 31 jlong _start_counter;
duke@435 32 bool _active;
duke@435 33 public:
duke@435 34 elapsedTimer() { _active = false; reset(); }
duke@435 35 void add(elapsedTimer t);
duke@435 36 void start();
duke@435 37 void stop();
duke@435 38 void reset() { _counter = 0; }
duke@435 39 double seconds() const;
duke@435 40 jlong milliseconds() const;
duke@435 41 jlong ticks() const { return _counter; }
duke@435 42 jlong active_ticks() const;
duke@435 43 bool is_active() const { return _active; }
duke@435 44 };
duke@435 45
duke@435 46 // TimeStamp is used for recording when an event took place.
duke@435 47 class TimeStamp VALUE_OBJ_CLASS_SPEC {
duke@435 48 private:
duke@435 49 jlong _counter;
duke@435 50 public:
duke@435 51 TimeStamp() { _counter = 0; }
duke@435 52 void clear() { _counter = 0; }
duke@435 53 // has the timestamp been updated since being created or cleared?
duke@435 54 bool is_updated() const { return _counter != 0; }
duke@435 55 // update to current elapsed time
duke@435 56 void update();
duke@435 57 // update to given elapsed time
duke@435 58 void update_to(jlong ticks);
duke@435 59 // returns seconds since updated
duke@435 60 // (must not be in a cleared state: must have been previously updated)
duke@435 61 double seconds() const;
duke@435 62 jlong milliseconds() const;
duke@435 63 // ticks elapsed between VM start and last update
duke@435 64 jlong ticks() const { return _counter; }
duke@435 65 // ticks elapsed since last update
duke@435 66 jlong ticks_since_update() const;
duke@435 67 };
duke@435 68
duke@435 69 // TraceTime is used for tracing the execution time of a block
duke@435 70 // Usage:
duke@435 71 // { TraceTime t("block time")
duke@435 72 // some_code();
duke@435 73 // }
duke@435 74 //
duke@435 75
duke@435 76 class TraceTime: public StackObj {
duke@435 77 private:
duke@435 78 bool _active; // do timing
duke@435 79 bool _verbose; // report every timing
duke@435 80 bool _print_cr; // add a CR to the end of the timer report
duke@435 81 elapsedTimer _t; // timer
duke@435 82 elapsedTimer* _accum; // accumulator
duke@435 83 outputStream* _logfile; // output log file
duke@435 84 public:
duke@435 85 // Constuctors
duke@435 86 TraceTime(const char* title,
duke@435 87 bool doit = true,
duke@435 88 bool print_cr = true,
duke@435 89 outputStream *logfile = NULL);
duke@435 90 TraceTime(const char* title,
duke@435 91 elapsedTimer* accumulator,
duke@435 92 bool doit = true,
duke@435 93 bool verbose = false,
duke@435 94 outputStream *logfile = NULL );
duke@435 95 ~TraceTime();
duke@435 96
duke@435 97 // Accessors
duke@435 98 void set_verbose(bool verbose) { _verbose = verbose; }
duke@435 99 bool verbose() const { return _verbose; }
duke@435 100
duke@435 101 // Activation
duke@435 102 void suspend() { if (_active) _t.stop(); }
duke@435 103 void resume() { if (_active) _t.start(); }
duke@435 104 };
duke@435 105
duke@435 106 class TraceCPUTime: public StackObj {
duke@435 107 private:
duke@435 108 bool _active; // true if times will be measured and printed
duke@435 109 bool _print_cr; // if true print carriage return at end
duke@435 110 double _starting_user_time; // user time at start of measurement
duke@435 111 double _starting_system_time; // system time at start of measurement
duke@435 112 double _starting_real_time; // real time at start of measurement
duke@435 113 outputStream* _logfile; // output is printed to this stream
duke@435 114 bool _error; // true if an error occurred, turns off output
duke@435 115
duke@435 116 public:
duke@435 117 TraceCPUTime(bool doit = true,
duke@435 118 bool print_cr = true,
duke@435 119 outputStream *logfile = NULL);
duke@435 120 ~TraceCPUTime();
duke@435 121 };

mercurial