author | pliden |
Fri, 11 Apr 2014 11:00:12 +0200 | |
changeset 24093 | 095cc0a63ed9 |
parent 23223 | d38d6390733f |
child 24424 | 2658d7834c6e |
permissions | -rw-r--r-- |
1 | 1 |
/* |
18025 | 2 |
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
#include "precompiled.hpp" |
26 |
#include "oops/oop.inline.hpp" |
|
27 |
#include "runtime/timer.hpp" |
|
28 |
#include "utilities/ostream.hpp" |
|
29 |
#ifdef TARGET_OS_FAMILY_linux |
|
30 |
# include "os_linux.inline.hpp" |
|
31 |
#endif |
|
32 |
#ifdef TARGET_OS_FAMILY_solaris |
|
33 |
# include "os_solaris.inline.hpp" |
|
34 |
#endif |
|
35 |
#ifdef TARGET_OS_FAMILY_windows |
|
36 |
# include "os_windows.inline.hpp" |
|
37 |
#endif |
|
22827 | 38 |
#ifdef TARGET_OS_FAMILY_aix |
39 |
# include "os_aix.inline.hpp" |
|
40 |
#endif |
|
10565 | 41 |
#ifdef TARGET_OS_FAMILY_bsd |
42 |
# include "os_bsd.inline.hpp" |
|
43 |
#endif |
|
1 | 44 |
|
18025 | 45 |
double TimeHelper::counter_to_seconds(jlong counter) { |
46 |
double count = (double) counter; |
|
47 |
double freq = (double) os::elapsed_frequency(); |
|
48 |
return counter/freq; |
|
49 |
} |
|
1 | 50 |
|
51 |
void elapsedTimer::add(elapsedTimer t) { |
|
52 |
_counter += t._counter; |
|
53 |
} |
|
54 |
||
55 |
void elapsedTimer::start() { |
|
56 |
if (!_active) { |
|
57 |
_active = true; |
|
58 |
_start_counter = os::elapsed_counter(); |
|
59 |
} |
|
60 |
} |
|
61 |
||
62 |
void elapsedTimer::stop() { |
|
63 |
if (_active) { |
|
64 |
_counter += os::elapsed_counter() - _start_counter; |
|
65 |
_active = false; |
|
66 |
} |
|
67 |
} |
|
68 |
||
69 |
double elapsedTimer::seconds() const { |
|
18025 | 70 |
return TimeHelper::counter_to_seconds(_counter); |
1 | 71 |
} |
72 |
||
73 |
jlong elapsedTimer::milliseconds() const { |
|
74 |
jlong ticks_per_ms = os::elapsed_frequency() / 1000; |
|
75 |
return _counter / ticks_per_ms; |
|
76 |
} |
|
77 |
||
78 |
jlong elapsedTimer::active_ticks() const { |
|
79 |
if (!_active) { |
|
80 |
return ticks(); |
|
81 |
} |
|
82 |
jlong counter = _counter + os::elapsed_counter() - _start_counter; |
|
83 |
return counter; |
|
84 |
} |
|
85 |
||
86 |
void TimeStamp::update_to(jlong ticks) { |
|
87 |
_counter = ticks; |
|
88 |
if (_counter == 0) _counter = 1; |
|
89 |
assert(is_updated(), "must not look clear"); |
|
90 |
} |
|
91 |
||
92 |
void TimeStamp::update() { |
|
93 |
update_to(os::elapsed_counter()); |
|
94 |
} |
|
95 |
||
96 |
double TimeStamp::seconds() const { |
|
97 |
assert(is_updated(), "must not be clear"); |
|
98 |
jlong new_count = os::elapsed_counter(); |
|
18025 | 99 |
return TimeHelper::counter_to_seconds(new_count - _counter); |
1 | 100 |
} |
101 |
||
102 |
jlong TimeStamp::milliseconds() const { |
|
103 |
assert(is_updated(), "must not be clear"); |
|
104 |
||
105 |
jlong new_count = os::elapsed_counter(); |
|
106 |
jlong count = new_count - _counter; |
|
107 |
jlong ticks_per_ms = os::elapsed_frequency() / 1000; |
|
108 |
return count / ticks_per_ms; |
|
109 |
} |
|
110 |
||
111 |
jlong TimeStamp::ticks_since_update() const { |
|
112 |
assert(is_updated(), "must not be clear"); |
|
113 |
return os::elapsed_counter() - _counter; |
|
114 |
} |
|
115 |
||
116 |
TraceTime::TraceTime(const char* title, |
|
18025 | 117 |
bool doit) { |
1 | 118 |
_active = doit; |
119 |
_verbose = true; |
|
120 |
||
121 |
if (_active) { |
|
122 |
_accum = NULL; |
|
18025 | 123 |
tty->stamp(PrintGCTimeStamps); |
124 |
tty->print("[%s", title); |
|
125 |
tty->flush(); |
|
1 | 126 |
_t.start(); |
127 |
} |
|
128 |
} |
|
129 |
||
130 |
TraceTime::TraceTime(const char* title, |
|
131 |
elapsedTimer* accumulator, |
|
132 |
bool doit, |
|
18025 | 133 |
bool verbose) { |
1 | 134 |
_active = doit; |
135 |
_verbose = verbose; |
|
136 |
if (_active) { |
|
137 |
if (_verbose) { |
|
18025 | 138 |
tty->stamp(PrintGCTimeStamps); |
139 |
tty->print("[%s", title); |
|
140 |
tty->flush(); |
|
1 | 141 |
} |
142 |
_accum = accumulator; |
|
143 |
_t.start(); |
|
144 |
} |
|
145 |
} |
|
146 |
||
147 |
TraceTime::~TraceTime() { |
|
148 |
if (_active) { |
|
149 |
_t.stop(); |
|
150 |
if (_accum!=NULL) _accum->add(_t); |
|
151 |
if (_verbose) { |
|
18025 | 152 |
tty->print_cr(", %3.7f secs]", _t.seconds()); |
153 |
tty->flush(); |
|
1 | 154 |
} |
155 |
} |
|
156 |
} |
|
157 |
||
158 |
TraceCPUTime::TraceCPUTime(bool doit, |
|
159 |
bool print_cr, |
|
160 |
outputStream *logfile) : |
|
161 |
_active(doit), |
|
162 |
_print_cr(print_cr), |
|
163 |
_starting_user_time(0.0), |
|
164 |
_starting_system_time(0.0), |
|
165 |
_starting_real_time(0.0), |
|
166 |
_logfile(logfile), |
|
167 |
_error(false) { |
|
168 |
if (_active) { |
|
169 |
if (logfile != NULL) { |
|
170 |
_logfile = logfile; |
|
171 |
} else { |
|
172 |
_logfile = tty; |
|
173 |
} |
|
174 |
||
175 |
_error = !os::getTimesSecs(&_starting_real_time, |
|
176 |
&_starting_user_time, |
|
177 |
&_starting_system_time); |
|
178 |
} |
|
179 |
} |
|
180 |
||
181 |
TraceCPUTime::~TraceCPUTime() { |
|
182 |
if (_active) { |
|
183 |
bool valid = false; |
|
184 |
if (!_error) { |
|
185 |
double real_secs; // walk clock time |
|
186 |
double system_secs; // system time |
|
187 |
double user_secs; // user time for all threads |
|
188 |
||
189 |
double real_time, user_time, system_time; |
|
190 |
valid = os::getTimesSecs(&real_time, &user_time, &system_time); |
|
191 |
if (valid) { |
|
192 |
||
193 |
user_secs = user_time - _starting_user_time; |
|
194 |
system_secs = system_time - _starting_system_time; |
|
195 |
real_secs = real_time - _starting_real_time; |
|
196 |
||
23223 | 197 |
_logfile->print(" [Times: user=%3.2f sys=%3.2f real=%3.2f secs] ", |
1 | 198 |
user_secs, system_secs, real_secs); |
199 |
||
200 |
} else { |
|
201 |
_logfile->print("[Invalid result in TraceCPUTime]"); |
|
202 |
} |
|
203 |
} else { |
|
204 |
_logfile->print("[Error in TraceCPUTime]"); |
|
205 |
} |
|
14634
fdd9909928ae
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
13963
diff
changeset
|
206 |
if (_print_cr) { |
1 | 207 |
_logfile->print_cr(""); |
208 |
} |
|
14634
fdd9909928ae
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
13963
diff
changeset
|
209 |
_logfile->flush(); |
1 | 210 |
} |
211 |
} |