author | jcoomes |
Fri, 05 Sep 2014 12:36:37 -0700 | |
changeset 26838 | 344fb68e970a |
parent 25468 | 5331df506290 |
child 30608 | d79880a5cf2f |
permissions | -rw-r--r-- |
1 | 1 |
/* |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23223
diff
changeset
|
2 |
* Copyright (c) 1997, 2014, 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" |
|
1 | 29 |
|
18025 | 30 |
double TimeHelper::counter_to_seconds(jlong counter) { |
31 |
double count = (double) counter; |
|
32 |
double freq = (double) os::elapsed_frequency(); |
|
33 |
return counter/freq; |
|
34 |
} |
|
1 | 35 |
|
36 |
void elapsedTimer::add(elapsedTimer t) { |
|
37 |
_counter += t._counter; |
|
38 |
} |
|
39 |
||
40 |
void elapsedTimer::start() { |
|
41 |
if (!_active) { |
|
42 |
_active = true; |
|
43 |
_start_counter = os::elapsed_counter(); |
|
44 |
} |
|
45 |
} |
|
46 |
||
47 |
void elapsedTimer::stop() { |
|
48 |
if (_active) { |
|
49 |
_counter += os::elapsed_counter() - _start_counter; |
|
50 |
_active = false; |
|
51 |
} |
|
52 |
} |
|
53 |
||
54 |
double elapsedTimer::seconds() const { |
|
18025 | 55 |
return TimeHelper::counter_to_seconds(_counter); |
1 | 56 |
} |
57 |
||
58 |
jlong elapsedTimer::milliseconds() const { |
|
59 |
jlong ticks_per_ms = os::elapsed_frequency() / 1000; |
|
60 |
return _counter / ticks_per_ms; |
|
61 |
} |
|
62 |
||
63 |
jlong elapsedTimer::active_ticks() const { |
|
64 |
if (!_active) { |
|
65 |
return ticks(); |
|
66 |
} |
|
67 |
jlong counter = _counter + os::elapsed_counter() - _start_counter; |
|
68 |
return counter; |
|
69 |
} |
|
70 |
||
71 |
void TimeStamp::update_to(jlong ticks) { |
|
72 |
_counter = ticks; |
|
73 |
if (_counter == 0) _counter = 1; |
|
74 |
assert(is_updated(), "must not look clear"); |
|
75 |
} |
|
76 |
||
77 |
void TimeStamp::update() { |
|
78 |
update_to(os::elapsed_counter()); |
|
79 |
} |
|
80 |
||
81 |
double TimeStamp::seconds() const { |
|
82 |
assert(is_updated(), "must not be clear"); |
|
83 |
jlong new_count = os::elapsed_counter(); |
|
18025 | 84 |
return TimeHelper::counter_to_seconds(new_count - _counter); |
1 | 85 |
} |
86 |
||
87 |
jlong TimeStamp::milliseconds() const { |
|
88 |
assert(is_updated(), "must not be clear"); |
|
89 |
||
90 |
jlong new_count = os::elapsed_counter(); |
|
91 |
jlong count = new_count - _counter; |
|
92 |
jlong ticks_per_ms = os::elapsed_frequency() / 1000; |
|
93 |
return count / ticks_per_ms; |
|
94 |
} |
|
95 |
||
96 |
jlong TimeStamp::ticks_since_update() const { |
|
97 |
assert(is_updated(), "must not be clear"); |
|
98 |
return os::elapsed_counter() - _counter; |
|
99 |
} |
|
100 |
||
101 |
TraceTime::TraceTime(const char* title, |
|
18025 | 102 |
bool doit) { |
1 | 103 |
_active = doit; |
104 |
_verbose = true; |
|
105 |
||
106 |
if (_active) { |
|
107 |
_accum = NULL; |
|
18025 | 108 |
tty->stamp(PrintGCTimeStamps); |
109 |
tty->print("[%s", title); |
|
110 |
tty->flush(); |
|
1 | 111 |
_t.start(); |
112 |
} |
|
113 |
} |
|
114 |
||
115 |
TraceTime::TraceTime(const char* title, |
|
116 |
elapsedTimer* accumulator, |
|
117 |
bool doit, |
|
18025 | 118 |
bool verbose) { |
1 | 119 |
_active = doit; |
120 |
_verbose = verbose; |
|
121 |
if (_active) { |
|
122 |
if (_verbose) { |
|
18025 | 123 |
tty->stamp(PrintGCTimeStamps); |
124 |
tty->print("[%s", title); |
|
125 |
tty->flush(); |
|
1 | 126 |
} |
127 |
_accum = accumulator; |
|
128 |
_t.start(); |
|
129 |
} |
|
130 |
} |
|
131 |
||
132 |
TraceTime::~TraceTime() { |
|
133 |
if (_active) { |
|
134 |
_t.stop(); |
|
135 |
if (_accum!=NULL) _accum->add(_t); |
|
136 |
if (_verbose) { |
|
18025 | 137 |
tty->print_cr(", %3.7f secs]", _t.seconds()); |
138 |
tty->flush(); |
|
1 | 139 |
} |
140 |
} |
|
141 |
} |
|
142 |
||
143 |
TraceCPUTime::TraceCPUTime(bool doit, |
|
144 |
bool print_cr, |
|
145 |
outputStream *logfile) : |
|
146 |
_active(doit), |
|
147 |
_print_cr(print_cr), |
|
148 |
_starting_user_time(0.0), |
|
149 |
_starting_system_time(0.0), |
|
150 |
_starting_real_time(0.0), |
|
151 |
_logfile(logfile), |
|
152 |
_error(false) { |
|
153 |
if (_active) { |
|
154 |
if (logfile != NULL) { |
|
155 |
_logfile = logfile; |
|
156 |
} else { |
|
157 |
_logfile = tty; |
|
158 |
} |
|
159 |
||
160 |
_error = !os::getTimesSecs(&_starting_real_time, |
|
161 |
&_starting_user_time, |
|
162 |
&_starting_system_time); |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
TraceCPUTime::~TraceCPUTime() { |
|
167 |
if (_active) { |
|
168 |
bool valid = false; |
|
169 |
if (!_error) { |
|
170 |
double real_secs; // walk clock time |
|
171 |
double system_secs; // system time |
|
172 |
double user_secs; // user time for all threads |
|
173 |
||
174 |
double real_time, user_time, system_time; |
|
175 |
valid = os::getTimesSecs(&real_time, &user_time, &system_time); |
|
176 |
if (valid) { |
|
177 |
||
178 |
user_secs = user_time - _starting_user_time; |
|
179 |
system_secs = system_time - _starting_system_time; |
|
180 |
real_secs = real_time - _starting_real_time; |
|
181 |
||
23223 | 182 |
_logfile->print(" [Times: user=%3.2f sys=%3.2f real=%3.2f secs] ", |
1 | 183 |
user_secs, system_secs, real_secs); |
184 |
||
185 |
} else { |
|
186 |
_logfile->print("[Invalid result in TraceCPUTime]"); |
|
187 |
} |
|
188 |
} else { |
|
189 |
_logfile->print("[Error in TraceCPUTime]"); |
|
190 |
} |
|
14634
fdd9909928ae
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
13963
diff
changeset
|
191 |
if (_print_cr) { |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23223
diff
changeset
|
192 |
_logfile->cr(); |
1 | 193 |
} |
14634
fdd9909928ae
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
13963
diff
changeset
|
194 |
_logfile->flush(); |
1 | 195 |
} |
196 |
} |