Mercurial > hg > truffle
annotate src/share/vm/runtime/timer.cpp @ 21282:93215cb4a2f9
include duringCall and rethrowException for BytecodeFrames in disassembly comments
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Mon, 11 May 2015 12:22:49 +0200 |
parents | 52b4284cb496 |
children |
rev | line source |
---|---|
0 | 1 /* |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14411
diff
changeset
|
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
0
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 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 | |
14411 | 38 #ifdef TARGET_OS_FAMILY_aix |
39 # include "os_aix.inline.hpp" | |
40 #endif | |
3960 | 41 #ifdef TARGET_OS_FAMILY_bsd |
42 # include "os_bsd.inline.hpp" | |
43 #endif | |
0 | 44 |
10405 | 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 } | |
0 | 50 |
13103
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
51 elapsedTimer::elapsedTimer(jlong time, jlong timeUnitsPerSecond) { |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
52 _active = false; |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
53 jlong osTimeUnitsPerSecond = os::elapsed_frequency(); |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
54 assert(osTimeUnitsPerSecond % 1000 == 0, "must be"); |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
55 assert(timeUnitsPerSecond % 1000 == 0, "must be"); |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
56 while (osTimeUnitsPerSecond < timeUnitsPerSecond) { |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
57 timeUnitsPerSecond /= 1000; |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
58 time *= 1000; |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
59 } |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
60 while (osTimeUnitsPerSecond > timeUnitsPerSecond) { |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
61 timeUnitsPerSecond *= 1000; |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
62 time /= 1000; |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
63 } |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
64 _counter = time; |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
65 } |
c0b0974dd509
moved notification of Graal compilation statistics from VMToCompiler to CompilerToVM
Doug Simon <doug.simon@oracle.com>
parents:
10405
diff
changeset
|
66 |
0 | 67 void elapsedTimer::add(elapsedTimer t) { |
68 _counter += t._counter; | |
69 } | |
70 | |
71 void elapsedTimer::start() { | |
72 if (!_active) { | |
73 _active = true; | |
74 _start_counter = os::elapsed_counter(); | |
75 } | |
76 } | |
77 | |
78 void elapsedTimer::stop() { | |
79 if (_active) { | |
80 _counter += os::elapsed_counter() - _start_counter; | |
81 _active = false; | |
82 } | |
83 } | |
84 | |
85 double elapsedTimer::seconds() const { | |
10405 | 86 return TimeHelper::counter_to_seconds(_counter); |
0 | 87 } |
88 | |
89 jlong elapsedTimer::milliseconds() const { | |
90 jlong ticks_per_ms = os::elapsed_frequency() / 1000; | |
91 return _counter / ticks_per_ms; | |
92 } | |
93 | |
94 jlong elapsedTimer::active_ticks() const { | |
95 if (!_active) { | |
96 return ticks(); | |
97 } | |
98 jlong counter = _counter + os::elapsed_counter() - _start_counter; | |
99 return counter; | |
100 } | |
101 | |
102 void TimeStamp::update_to(jlong ticks) { | |
103 _counter = ticks; | |
104 if (_counter == 0) _counter = 1; | |
105 assert(is_updated(), "must not look clear"); | |
106 } | |
107 | |
108 void TimeStamp::update() { | |
109 update_to(os::elapsed_counter()); | |
110 } | |
111 | |
112 double TimeStamp::seconds() const { | |
113 assert(is_updated(), "must not be clear"); | |
114 jlong new_count = os::elapsed_counter(); | |
10405 | 115 return TimeHelper::counter_to_seconds(new_count - _counter); |
0 | 116 } |
117 | |
118 jlong TimeStamp::milliseconds() const { | |
119 assert(is_updated(), "must not be clear"); | |
120 | |
121 jlong new_count = os::elapsed_counter(); | |
122 jlong count = new_count - _counter; | |
123 jlong ticks_per_ms = os::elapsed_frequency() / 1000; | |
124 return count / ticks_per_ms; | |
125 } | |
126 | |
127 jlong TimeStamp::ticks_since_update() const { | |
128 assert(is_updated(), "must not be clear"); | |
129 return os::elapsed_counter() - _counter; | |
130 } | |
131 | |
132 TraceTime::TraceTime(const char* title, | |
10405 | 133 bool doit) { |
0 | 134 _active = doit; |
135 _verbose = true; | |
136 | |
137 if (_active) { | |
138 _accum = NULL; | |
10405 | 139 tty->stamp(PrintGCTimeStamps); |
140 tty->print("[%s", title); | |
141 tty->flush(); | |
0 | 142 _t.start(); |
143 } | |
144 } | |
145 | |
146 TraceTime::TraceTime(const char* title, | |
147 elapsedTimer* accumulator, | |
148 bool doit, | |
10405 | 149 bool verbose) { |
0 | 150 _active = doit; |
151 _verbose = verbose; | |
152 if (_active) { | |
153 if (_verbose) { | |
10405 | 154 tty->stamp(PrintGCTimeStamps); |
155 tty->print("[%s", title); | |
156 tty->flush(); | |
0 | 157 } |
158 _accum = accumulator; | |
159 _t.start(); | |
160 } | |
161 } | |
162 | |
163 TraceTime::~TraceTime() { | |
164 if (_active) { | |
165 _t.stop(); | |
166 if (_accum!=NULL) _accum->add(_t); | |
167 if (_verbose) { | |
10405 | 168 tty->print_cr(", %3.7f secs]", _t.seconds()); |
169 tty->flush(); | |
0 | 170 } |
171 } | |
172 } | |
173 | |
174 TraceCPUTime::TraceCPUTime(bool doit, | |
175 bool print_cr, | |
176 outputStream *logfile) : | |
177 _active(doit), | |
178 _print_cr(print_cr), | |
179 _starting_user_time(0.0), | |
180 _starting_system_time(0.0), | |
181 _starting_real_time(0.0), | |
182 _logfile(logfile), | |
183 _error(false) { | |
184 if (_active) { | |
185 if (logfile != NULL) { | |
186 _logfile = logfile; | |
187 } else { | |
188 _logfile = tty; | |
189 } | |
190 | |
191 _error = !os::getTimesSecs(&_starting_real_time, | |
192 &_starting_user_time, | |
193 &_starting_system_time); | |
194 } | |
195 } | |
196 | |
197 TraceCPUTime::~TraceCPUTime() { | |
198 if (_active) { | |
199 bool valid = false; | |
200 if (!_error) { | |
201 double real_secs; // walk clock time | |
202 double system_secs; // system time | |
203 double user_secs; // user time for all threads | |
204 | |
205 double real_time, user_time, system_time; | |
206 valid = os::getTimesSecs(&real_time, &user_time, &system_time); | |
207 if (valid) { | |
208 | |
209 user_secs = user_time - _starting_user_time; | |
210 system_secs = system_time - _starting_system_time; | |
211 real_secs = real_time - _starting_real_time; | |
212 | |
213 _logfile->print(" [Times: user=%3.2f sys=%3.2f, real=%3.2f secs] ", | |
214 user_secs, system_secs, real_secs); | |
215 | |
216 } else { | |
217 _logfile->print("[Invalid result in TraceCPUTime]"); | |
218 } | |
219 } else { | |
220 _logfile->print("[Error in TraceCPUTime]"); | |
221 } | |
7207
0f80645e9c26
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
6842
diff
changeset
|
222 if (_print_cr) { |
17937
78bbf4d43a14
8037816: Fix for 8036122 breaks build with Xcode5/clang
drchase
parents:
14411
diff
changeset
|
223 _logfile->cr(); |
0 | 224 } |
7207
0f80645e9c26
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
6842
diff
changeset
|
225 _logfile->flush(); |
0 | 226 } |
227 } |