author | rehn |
Thu, 31 Aug 2017 10:00:28 +0200 | |
changeset 47881 | 0ce0ac68ace7 |
parent 47216 | 71c04702a3d5 |
child 53520 | 5178e4b58b17 |
permissions | -rw-r--r-- |
1 | 1 |
/* |
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 1997, 2017, 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" |
36178
9739f8c767da
8148630: Convert TraceStartupTime to Unified Logging
rprotacio
parents:
35061
diff
changeset
|
26 |
#include "logging/log.hpp" |
7397 | 27 |
#include "oops/oop.inline.hpp" |
28 |
#include "runtime/timer.hpp" |
|
29 |
#include "utilities/ostream.hpp" |
|
1 | 30 |
|
18025 | 31 |
double TimeHelper::counter_to_seconds(jlong counter) { |
32 |
double freq = (double) os::elapsed_frequency(); |
|
30608
d79880a5cf2f
8079561: Add a method to convert counters to milliseconds
brutisso
parents:
25468
diff
changeset
|
33 |
return counter / freq; |
d79880a5cf2f
8079561: Add a method to convert counters to milliseconds
brutisso
parents:
25468
diff
changeset
|
34 |
} |
d79880a5cf2f
8079561: Add a method to convert counters to milliseconds
brutisso
parents:
25468
diff
changeset
|
35 |
|
d79880a5cf2f
8079561: Add a method to convert counters to milliseconds
brutisso
parents:
25468
diff
changeset
|
36 |
double TimeHelper::counter_to_millis(jlong counter) { |
d79880a5cf2f
8079561: Add a method to convert counters to milliseconds
brutisso
parents:
25468
diff
changeset
|
37 |
return counter_to_seconds(counter) * 1000.0; |
18025 | 38 |
} |
1 | 39 |
|
47881
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
40 |
jlong TimeHelper::millis_to_counter(jlong millis) { |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
41 |
jlong freq = os::elapsed_frequency() / MILLIUNITS; |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
42 |
return millis * freq; |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
43 |
} |
0ce0ac68ace7
8189941: Implementation JEP 312: Thread-local handshake
rehn
parents:
47216
diff
changeset
|
44 |
|
33160
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
45 |
elapsedTimer::elapsedTimer(jlong time, jlong timeUnitsPerSecond) { |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
46 |
_active = false; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
47 |
jlong osTimeUnitsPerSecond = os::elapsed_frequency(); |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
48 |
assert(osTimeUnitsPerSecond % 1000 == 0, "must be"); |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
49 |
assert(timeUnitsPerSecond % 1000 == 0, "must be"); |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
50 |
while (osTimeUnitsPerSecond < timeUnitsPerSecond) { |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
51 |
timeUnitsPerSecond /= 1000; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
52 |
time *= 1000; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
53 |
} |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
54 |
while (osTimeUnitsPerSecond > timeUnitsPerSecond) { |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
55 |
timeUnitsPerSecond *= 1000; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
56 |
time /= 1000; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
57 |
} |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
58 |
_counter = time; |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
59 |
} |
c59f1676d27e
8136421: JEP 243: Java-Level JVM Compiler Interface
twisti
parents:
31334
diff
changeset
|
60 |
|
1 | 61 |
void elapsedTimer::add(elapsedTimer t) { |
62 |
_counter += t._counter; |
|
63 |
} |
|
64 |
||
65 |
void elapsedTimer::start() { |
|
66 |
if (!_active) { |
|
67 |
_active = true; |
|
68 |
_start_counter = os::elapsed_counter(); |
|
69 |
} |
|
70 |
} |
|
71 |
||
72 |
void elapsedTimer::stop() { |
|
73 |
if (_active) { |
|
74 |
_counter += os::elapsed_counter() - _start_counter; |
|
75 |
_active = false; |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
double elapsedTimer::seconds() const { |
|
18025 | 80 |
return TimeHelper::counter_to_seconds(_counter); |
1 | 81 |
} |
82 |
||
83 |
jlong elapsedTimer::milliseconds() const { |
|
31334
d55c96b36b5f
8085975: Fix warning "converting to jlong from double" of gcc 4.1.2 after 8079561
goetz
parents:
30608
diff
changeset
|
84 |
return (jlong)TimeHelper::counter_to_millis(_counter); |
1 | 85 |
} |
86 |
||
87 |
jlong elapsedTimer::active_ticks() const { |
|
88 |
if (!_active) { |
|
89 |
return ticks(); |
|
90 |
} |
|
91 |
jlong counter = _counter + os::elapsed_counter() - _start_counter; |
|
92 |
return counter; |
|
93 |
} |
|
94 |
||
95 |
void TimeStamp::update_to(jlong ticks) { |
|
96 |
_counter = ticks; |
|
97 |
if (_counter == 0) _counter = 1; |
|
98 |
assert(is_updated(), "must not look clear"); |
|
99 |
} |
|
100 |
||
101 |
void TimeStamp::update() { |
|
102 |
update_to(os::elapsed_counter()); |
|
103 |
} |
|
104 |
||
105 |
double TimeStamp::seconds() const { |
|
106 |
assert(is_updated(), "must not be clear"); |
|
107 |
jlong new_count = os::elapsed_counter(); |
|
18025 | 108 |
return TimeHelper::counter_to_seconds(new_count - _counter); |
1 | 109 |
} |
110 |
||
111 |
jlong TimeStamp::milliseconds() const { |
|
112 |
assert(is_updated(), "must not be clear"); |
|
113 |
jlong new_count = os::elapsed_counter(); |
|
31334
d55c96b36b5f
8085975: Fix warning "converting to jlong from double" of gcc 4.1.2 after 8079561
goetz
parents:
30608
diff
changeset
|
114 |
return (jlong)TimeHelper::counter_to_millis(new_count - _counter); |
1 | 115 |
} |
116 |
||
117 |
jlong TimeStamp::ticks_since_update() const { |
|
118 |
assert(is_updated(), "must not be clear"); |
|
119 |
return os::elapsed_counter() - _counter; |
|
120 |
} |
|
121 |
||
122 |
TraceCPUTime::TraceCPUTime(bool doit, |
|
123 |
bool print_cr, |
|
124 |
outputStream *logfile) : |
|
125 |
_active(doit), |
|
126 |
_print_cr(print_cr), |
|
127 |
_starting_user_time(0.0), |
|
128 |
_starting_system_time(0.0), |
|
129 |
_starting_real_time(0.0), |
|
130 |
_logfile(logfile), |
|
131 |
_error(false) { |
|
132 |
if (_active) { |
|
133 |
if (logfile != NULL) { |
|
134 |
_logfile = logfile; |
|
135 |
} else { |
|
136 |
_logfile = tty; |
|
137 |
} |
|
138 |
||
139 |
_error = !os::getTimesSecs(&_starting_real_time, |
|
140 |
&_starting_user_time, |
|
141 |
&_starting_system_time); |
|
142 |
} |
|
143 |
} |
|
144 |
||
145 |
TraceCPUTime::~TraceCPUTime() { |
|
146 |
if (_active) { |
|
147 |
bool valid = false; |
|
148 |
if (!_error) { |
|
149 |
double real_secs; // walk clock time |
|
150 |
double system_secs; // system time |
|
151 |
double user_secs; // user time for all threads |
|
152 |
||
153 |
double real_time, user_time, system_time; |
|
154 |
valid = os::getTimesSecs(&real_time, &user_time, &system_time); |
|
155 |
if (valid) { |
|
156 |
||
157 |
user_secs = user_time - _starting_user_time; |
|
158 |
system_secs = system_time - _starting_system_time; |
|
159 |
real_secs = real_time - _starting_real_time; |
|
160 |
||
23223 | 161 |
_logfile->print(" [Times: user=%3.2f sys=%3.2f real=%3.2f secs] ", |
1 | 162 |
user_secs, system_secs, real_secs); |
163 |
||
164 |
} else { |
|
165 |
_logfile->print("[Invalid result in TraceCPUTime]"); |
|
166 |
} |
|
167 |
} else { |
|
168 |
_logfile->print("[Error in TraceCPUTime]"); |
|
169 |
} |
|
14634
fdd9909928ae
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
13963
diff
changeset
|
170 |
if (_print_cr) { |
24424
2658d7834c6e
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
23223
diff
changeset
|
171 |
_logfile->cr(); |
1 | 172 |
} |
14634
fdd9909928ae
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
13963
diff
changeset
|
173 |
_logfile->flush(); |
1 | 174 |
} |
175 |
} |
|
37161
e881f320966e
8150015: Integrate TraceTime with Unified Logging more seamlessly
rehn
parents:
37043
diff
changeset
|
176 |