src/share/vm/runtime/timer.hpp

Wed, 19 Nov 2014 14:21:09 -0800

author
mchung
date
Wed, 19 Nov 2014 14:21:09 -0800
changeset 7368
fa6adc194d48
parent 5237
f2110083203d
child 6876
710a3c8b516e
permissions
-rw-r--r--

8064667: Add -XX:+CheckEndorsedAndExtDirs flag to JDK 8
Reviewed-by: coleenp, ccheung

duke@435 1 /*
sla@5237 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. 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 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_RUNTIME_TIMER_HPP
stefank@2314 26 #define SHARE_VM_RUNTIME_TIMER_HPP
stefank@2314 27
stefank@2314 28 #include "utilities/globalDefinitions.hpp"
stefank@2314 29
duke@435 30 // Timers for simple measurement.
duke@435 31
duke@435 32 class elapsedTimer VALUE_OBJ_CLASS_SPEC {
duke@435 33 friend class VMStructs;
duke@435 34 private:
duke@435 35 jlong _counter;
duke@435 36 jlong _start_counter;
duke@435 37 bool _active;
duke@435 38 public:
duke@435 39 elapsedTimer() { _active = false; reset(); }
duke@435 40 void add(elapsedTimer t);
duke@435 41 void start();
duke@435 42 void stop();
duke@435 43 void reset() { _counter = 0; }
duke@435 44 double seconds() const;
duke@435 45 jlong milliseconds() const;
duke@435 46 jlong ticks() const { return _counter; }
duke@435 47 jlong active_ticks() const;
duke@435 48 bool is_active() const { return _active; }
duke@435 49 };
duke@435 50
duke@435 51 // TimeStamp is used for recording when an event took place.
duke@435 52 class TimeStamp VALUE_OBJ_CLASS_SPEC {
duke@435 53 private:
duke@435 54 jlong _counter;
duke@435 55 public:
duke@435 56 TimeStamp() { _counter = 0; }
duke@435 57 void clear() { _counter = 0; }
duke@435 58 // has the timestamp been updated since being created or cleared?
duke@435 59 bool is_updated() const { return _counter != 0; }
duke@435 60 // update to current elapsed time
duke@435 61 void update();
duke@435 62 // update to given elapsed time
duke@435 63 void update_to(jlong ticks);
duke@435 64 // returns seconds since updated
duke@435 65 // (must not be in a cleared state: must have been previously updated)
duke@435 66 double seconds() const;
duke@435 67 jlong milliseconds() const;
duke@435 68 // ticks elapsed between VM start and last update
duke@435 69 jlong ticks() const { return _counter; }
duke@435 70 // ticks elapsed since last update
duke@435 71 jlong ticks_since_update() const;
duke@435 72 };
duke@435 73
duke@435 74 // TraceTime is used for tracing the execution time of a block
duke@435 75 // Usage:
duke@435 76 // { TraceTime t("block time")
duke@435 77 // some_code();
duke@435 78 // }
duke@435 79 //
duke@435 80
duke@435 81 class TraceTime: public StackObj {
duke@435 82 private:
duke@435 83 bool _active; // do timing
duke@435 84 bool _verbose; // report every timing
duke@435 85 elapsedTimer _t; // timer
duke@435 86 elapsedTimer* _accum; // accumulator
duke@435 87 public:
sla@5237 88 // Constructors
duke@435 89 TraceTime(const char* title,
sla@5237 90 bool doit = true);
duke@435 91 TraceTime(const char* title,
duke@435 92 elapsedTimer* accumulator,
duke@435 93 bool doit = true,
sla@5237 94 bool verbose = false);
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 };
stefank@2314 122
sla@5237 123 class TimeHelper {
sla@5237 124 public:
sla@5237 125 static double counter_to_seconds(jlong counter);
sla@5237 126 };
sla@5237 127
stefank@2314 128 #endif // SHARE_VM_RUNTIME_TIMER_HPP

mercurial