Mercurial > hg > truffle
annotate src/share/vm/runtime/timer.cpp @ 12888:4a2acfb16e97
8025657: compiler/intrinsics/mathexact/ConstantTest.java fails on assert in lcm.cpp on solaris x64
Reviewed-by: kvn, twisti
author | rbackman |
---|---|
date | Fri, 11 Oct 2013 12:06:14 +0200 |
parents | f2110083203d |
children | c0b0974dd509 bdd155477289 |
rev | line source |
---|---|
0 | 1 /* |
10405 | 2 * Copyright (c) 1997, 2013, 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 | |
3960 | 38 #ifdef TARGET_OS_FAMILY_bsd |
39 # include "os_bsd.inline.hpp" | |
40 #endif | |
0 | 41 |
10405 | 42 double TimeHelper::counter_to_seconds(jlong counter) { |
43 double count = (double) counter; | |
44 double freq = (double) os::elapsed_frequency(); | |
45 return counter/freq; | |
46 } | |
0 | 47 |
48 void elapsedTimer::add(elapsedTimer t) { | |
49 _counter += t._counter; | |
50 } | |
51 | |
52 void elapsedTimer::start() { | |
53 if (!_active) { | |
54 _active = true; | |
55 _start_counter = os::elapsed_counter(); | |
56 } | |
57 } | |
58 | |
59 void elapsedTimer::stop() { | |
60 if (_active) { | |
61 _counter += os::elapsed_counter() - _start_counter; | |
62 _active = false; | |
63 } | |
64 } | |
65 | |
66 double elapsedTimer::seconds() const { | |
10405 | 67 return TimeHelper::counter_to_seconds(_counter); |
0 | 68 } |
69 | |
70 jlong elapsedTimer::milliseconds() const { | |
71 jlong ticks_per_ms = os::elapsed_frequency() / 1000; | |
72 return _counter / ticks_per_ms; | |
73 } | |
74 | |
75 jlong elapsedTimer::active_ticks() const { | |
76 if (!_active) { | |
77 return ticks(); | |
78 } | |
79 jlong counter = _counter + os::elapsed_counter() - _start_counter; | |
80 return counter; | |
81 } | |
82 | |
83 void TimeStamp::update_to(jlong ticks) { | |
84 _counter = ticks; | |
85 if (_counter == 0) _counter = 1; | |
86 assert(is_updated(), "must not look clear"); | |
87 } | |
88 | |
89 void TimeStamp::update() { | |
90 update_to(os::elapsed_counter()); | |
91 } | |
92 | |
93 double TimeStamp::seconds() const { | |
94 assert(is_updated(), "must not be clear"); | |
95 jlong new_count = os::elapsed_counter(); | |
10405 | 96 return TimeHelper::counter_to_seconds(new_count - _counter); |
0 | 97 } |
98 | |
99 jlong TimeStamp::milliseconds() const { | |
100 assert(is_updated(), "must not be clear"); | |
101 | |
102 jlong new_count = os::elapsed_counter(); | |
103 jlong count = new_count - _counter; | |
104 jlong ticks_per_ms = os::elapsed_frequency() / 1000; | |
105 return count / ticks_per_ms; | |
106 } | |
107 | |
108 jlong TimeStamp::ticks_since_update() const { | |
109 assert(is_updated(), "must not be clear"); | |
110 return os::elapsed_counter() - _counter; | |
111 } | |
112 | |
113 TraceTime::TraceTime(const char* title, | |
10405 | 114 bool doit) { |
0 | 115 _active = doit; |
116 _verbose = true; | |
117 | |
118 if (_active) { | |
119 _accum = NULL; | |
10405 | 120 tty->stamp(PrintGCTimeStamps); |
121 tty->print("[%s", title); | |
122 tty->flush(); | |
0 | 123 _t.start(); |
124 } | |
125 } | |
126 | |
127 TraceTime::TraceTime(const char* title, | |
128 elapsedTimer* accumulator, | |
129 bool doit, | |
10405 | 130 bool verbose) { |
0 | 131 _active = doit; |
132 _verbose = verbose; | |
133 if (_active) { | |
134 if (_verbose) { | |
10405 | 135 tty->stamp(PrintGCTimeStamps); |
136 tty->print("[%s", title); | |
137 tty->flush(); | |
0 | 138 } |
139 _accum = accumulator; | |
140 _t.start(); | |
141 } | |
142 } | |
143 | |
144 TraceTime::~TraceTime() { | |
145 if (_active) { | |
146 _t.stop(); | |
147 if (_accum!=NULL) _accum->add(_t); | |
148 if (_verbose) { | |
10405 | 149 tty->print_cr(", %3.7f secs]", _t.seconds()); |
150 tty->flush(); | |
0 | 151 } |
152 } | |
153 } | |
154 | |
155 TraceCPUTime::TraceCPUTime(bool doit, | |
156 bool print_cr, | |
157 outputStream *logfile) : | |
158 _active(doit), | |
159 _print_cr(print_cr), | |
160 _starting_user_time(0.0), | |
161 _starting_system_time(0.0), | |
162 _starting_real_time(0.0), | |
163 _logfile(logfile), | |
164 _error(false) { | |
165 if (_active) { | |
166 if (logfile != NULL) { | |
167 _logfile = logfile; | |
168 } else { | |
169 _logfile = tty; | |
170 } | |
171 | |
172 _error = !os::getTimesSecs(&_starting_real_time, | |
173 &_starting_user_time, | |
174 &_starting_system_time); | |
175 } | |
176 } | |
177 | |
178 TraceCPUTime::~TraceCPUTime() { | |
179 if (_active) { | |
180 bool valid = false; | |
181 if (!_error) { | |
182 double real_secs; // walk clock time | |
183 double system_secs; // system time | |
184 double user_secs; // user time for all threads | |
185 | |
186 double real_time, user_time, system_time; | |
187 valid = os::getTimesSecs(&real_time, &user_time, &system_time); | |
188 if (valid) { | |
189 | |
190 user_secs = user_time - _starting_user_time; | |
191 system_secs = system_time - _starting_system_time; | |
192 real_secs = real_time - _starting_real_time; | |
193 | |
194 _logfile->print(" [Times: user=%3.2f sys=%3.2f, real=%3.2f secs] ", | |
195 user_secs, system_secs, real_secs); | |
196 | |
197 } else { | |
198 _logfile->print("[Invalid result in TraceCPUTime]"); | |
199 } | |
200 } else { | |
201 _logfile->print("[Error in TraceCPUTime]"); | |
202 } | |
7207
0f80645e9c26
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
6842
diff
changeset
|
203 if (_print_cr) { |
0 | 204 _logfile->print_cr(""); |
205 } | |
7207
0f80645e9c26
8004170: G1: Verbose GC output is not getting flushed to log file using JDK 8
johnc
parents:
6842
diff
changeset
|
206 _logfile->flush(); |
0 | 207 } |
208 } |