annotate src/share/vm/runtime/timer.cpp @ 1552:c18cbe5936b8

6941466: Oracle rebranding changes for Hotspot repositories Summary: Change all the Sun copyrights to Oracle copyright Reviewed-by: ohair
author trims
date Thu, 27 May 2010 19:08:38 -0700
parents a61af66fc99e
children f95d63e2154a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 0
diff changeset
2 * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
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
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
a61af66fc99e Initial load
duke
parents:
diff changeset
25 # include "incls/_precompiled.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
26 # include "incls/_timer.cpp.incl"
a61af66fc99e Initial load
duke
parents:
diff changeset
27
a61af66fc99e Initial load
duke
parents:
diff changeset
28
a61af66fc99e Initial load
duke
parents:
diff changeset
29 void elapsedTimer::add(elapsedTimer t) {
a61af66fc99e Initial load
duke
parents:
diff changeset
30 _counter += t._counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
31 }
a61af66fc99e Initial load
duke
parents:
diff changeset
32
a61af66fc99e Initial load
duke
parents:
diff changeset
33 void elapsedTimer::start() {
a61af66fc99e Initial load
duke
parents:
diff changeset
34 if (!_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
35 _active = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
36 _start_counter = os::elapsed_counter();
a61af66fc99e Initial load
duke
parents:
diff changeset
37 }
a61af66fc99e Initial load
duke
parents:
diff changeset
38 }
a61af66fc99e Initial load
duke
parents:
diff changeset
39
a61af66fc99e Initial load
duke
parents:
diff changeset
40 void elapsedTimer::stop() {
a61af66fc99e Initial load
duke
parents:
diff changeset
41 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
42 _counter += os::elapsed_counter() - _start_counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
43 _active = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
44 }
a61af66fc99e Initial load
duke
parents:
diff changeset
45 }
a61af66fc99e Initial load
duke
parents:
diff changeset
46
a61af66fc99e Initial load
duke
parents:
diff changeset
47 double elapsedTimer::seconds() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
48 double count = (double) _counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
49 double freq = (double) os::elapsed_frequency();
a61af66fc99e Initial load
duke
parents:
diff changeset
50 return count/freq;
a61af66fc99e Initial load
duke
parents:
diff changeset
51 }
a61af66fc99e Initial load
duke
parents:
diff changeset
52
a61af66fc99e Initial load
duke
parents:
diff changeset
53 jlong elapsedTimer::milliseconds() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
54 jlong ticks_per_ms = os::elapsed_frequency() / 1000;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 return _counter / ticks_per_ms;
a61af66fc99e Initial load
duke
parents:
diff changeset
56 }
a61af66fc99e Initial load
duke
parents:
diff changeset
57
a61af66fc99e Initial load
duke
parents:
diff changeset
58 jlong elapsedTimer::active_ticks() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
59 if (!_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
60 return ticks();
a61af66fc99e Initial load
duke
parents:
diff changeset
61 }
a61af66fc99e Initial load
duke
parents:
diff changeset
62 jlong counter = _counter + os::elapsed_counter() - _start_counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 return counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
64 }
a61af66fc99e Initial load
duke
parents:
diff changeset
65
a61af66fc99e Initial load
duke
parents:
diff changeset
66 void TimeStamp::update_to(jlong ticks) {
a61af66fc99e Initial load
duke
parents:
diff changeset
67 _counter = ticks;
a61af66fc99e Initial load
duke
parents:
diff changeset
68 if (_counter == 0) _counter = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
69 assert(is_updated(), "must not look clear");
a61af66fc99e Initial load
duke
parents:
diff changeset
70 }
a61af66fc99e Initial load
duke
parents:
diff changeset
71
a61af66fc99e Initial load
duke
parents:
diff changeset
72 void TimeStamp::update() {
a61af66fc99e Initial load
duke
parents:
diff changeset
73 update_to(os::elapsed_counter());
a61af66fc99e Initial load
duke
parents:
diff changeset
74 }
a61af66fc99e Initial load
duke
parents:
diff changeset
75
a61af66fc99e Initial load
duke
parents:
diff changeset
76 double TimeStamp::seconds() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
77 assert(is_updated(), "must not be clear");
a61af66fc99e Initial load
duke
parents:
diff changeset
78 jlong new_count = os::elapsed_counter();
a61af66fc99e Initial load
duke
parents:
diff changeset
79 double count = (double) new_count - _counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
80 double freq = (double) os::elapsed_frequency();
a61af66fc99e Initial load
duke
parents:
diff changeset
81 return count/freq;
a61af66fc99e Initial load
duke
parents:
diff changeset
82 }
a61af66fc99e Initial load
duke
parents:
diff changeset
83
a61af66fc99e Initial load
duke
parents:
diff changeset
84 jlong TimeStamp::milliseconds() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
85 assert(is_updated(), "must not be clear");
a61af66fc99e Initial load
duke
parents:
diff changeset
86
a61af66fc99e Initial load
duke
parents:
diff changeset
87 jlong new_count = os::elapsed_counter();
a61af66fc99e Initial load
duke
parents:
diff changeset
88 jlong count = new_count - _counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
89 jlong ticks_per_ms = os::elapsed_frequency() / 1000;
a61af66fc99e Initial load
duke
parents:
diff changeset
90 return count / ticks_per_ms;
a61af66fc99e Initial load
duke
parents:
diff changeset
91 }
a61af66fc99e Initial load
duke
parents:
diff changeset
92
a61af66fc99e Initial load
duke
parents:
diff changeset
93 jlong TimeStamp::ticks_since_update() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
94 assert(is_updated(), "must not be clear");
a61af66fc99e Initial load
duke
parents:
diff changeset
95 return os::elapsed_counter() - _counter;
a61af66fc99e Initial load
duke
parents:
diff changeset
96 }
a61af66fc99e Initial load
duke
parents:
diff changeset
97
a61af66fc99e Initial load
duke
parents:
diff changeset
98 TraceTime::TraceTime(const char* title,
a61af66fc99e Initial load
duke
parents:
diff changeset
99 bool doit,
a61af66fc99e Initial load
duke
parents:
diff changeset
100 bool print_cr,
a61af66fc99e Initial load
duke
parents:
diff changeset
101 outputStream* logfile) {
a61af66fc99e Initial load
duke
parents:
diff changeset
102 _active = doit;
a61af66fc99e Initial load
duke
parents:
diff changeset
103 _verbose = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 _print_cr = print_cr;
a61af66fc99e Initial load
duke
parents:
diff changeset
105 _logfile = (logfile != NULL) ? logfile : tty;
a61af66fc99e Initial load
duke
parents:
diff changeset
106
a61af66fc99e Initial load
duke
parents:
diff changeset
107 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
108 _accum = NULL;
a61af66fc99e Initial load
duke
parents:
diff changeset
109 if (PrintGCTimeStamps) {
a61af66fc99e Initial load
duke
parents:
diff changeset
110 _logfile->stamp();
a61af66fc99e Initial load
duke
parents:
diff changeset
111 _logfile->print(": ");
a61af66fc99e Initial load
duke
parents:
diff changeset
112 }
a61af66fc99e Initial load
duke
parents:
diff changeset
113 _logfile->print("[%s", title);
a61af66fc99e Initial load
duke
parents:
diff changeset
114 _logfile->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
115 _t.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
a61af66fc99e Initial load
duke
parents:
diff changeset
118
a61af66fc99e Initial load
duke
parents:
diff changeset
119 TraceTime::TraceTime(const char* title,
a61af66fc99e Initial load
duke
parents:
diff changeset
120 elapsedTimer* accumulator,
a61af66fc99e Initial load
duke
parents:
diff changeset
121 bool doit,
a61af66fc99e Initial load
duke
parents:
diff changeset
122 bool verbose,
a61af66fc99e Initial load
duke
parents:
diff changeset
123 outputStream* logfile) {
a61af66fc99e Initial load
duke
parents:
diff changeset
124 _active = doit;
a61af66fc99e Initial load
duke
parents:
diff changeset
125 _verbose = verbose;
a61af66fc99e Initial load
duke
parents:
diff changeset
126 _print_cr = true;
a61af66fc99e Initial load
duke
parents:
diff changeset
127 _logfile = (logfile != NULL) ? logfile : tty;
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
129 if (_verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (PrintGCTimeStamps) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 _logfile->stamp();
a61af66fc99e Initial load
duke
parents:
diff changeset
132 _logfile->print(": ");
a61af66fc99e Initial load
duke
parents:
diff changeset
133 }
a61af66fc99e Initial load
duke
parents:
diff changeset
134 _logfile->print("[%s", title);
a61af66fc99e Initial load
duke
parents:
diff changeset
135 _logfile->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 _accum = accumulator;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 _t.start();
a61af66fc99e Initial load
duke
parents:
diff changeset
139 }
a61af66fc99e Initial load
duke
parents:
diff changeset
140 }
a61af66fc99e Initial load
duke
parents:
diff changeset
141
a61af66fc99e Initial load
duke
parents:
diff changeset
142 TraceTime::~TraceTime() {
a61af66fc99e Initial load
duke
parents:
diff changeset
143 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 _t.stop();
a61af66fc99e Initial load
duke
parents:
diff changeset
145 if (_accum!=NULL) _accum->add(_t);
a61af66fc99e Initial load
duke
parents:
diff changeset
146 if (_verbose) {
a61af66fc99e Initial load
duke
parents:
diff changeset
147 if (_print_cr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
148 _logfile->print_cr(", %3.7f secs]", _t.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
149 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
150 _logfile->print(", %3.7f secs]", _t.seconds());
a61af66fc99e Initial load
duke
parents:
diff changeset
151 }
a61af66fc99e Initial load
duke
parents:
diff changeset
152 _logfile->flush();
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155 }
a61af66fc99e Initial load
duke
parents:
diff changeset
156
a61af66fc99e Initial load
duke
parents:
diff changeset
157 TraceCPUTime::TraceCPUTime(bool doit,
a61af66fc99e Initial load
duke
parents:
diff changeset
158 bool print_cr,
a61af66fc99e Initial load
duke
parents:
diff changeset
159 outputStream *logfile) :
a61af66fc99e Initial load
duke
parents:
diff changeset
160 _active(doit),
a61af66fc99e Initial load
duke
parents:
diff changeset
161 _print_cr(print_cr),
a61af66fc99e Initial load
duke
parents:
diff changeset
162 _starting_user_time(0.0),
a61af66fc99e Initial load
duke
parents:
diff changeset
163 _starting_system_time(0.0),
a61af66fc99e Initial load
duke
parents:
diff changeset
164 _starting_real_time(0.0),
a61af66fc99e Initial load
duke
parents:
diff changeset
165 _logfile(logfile),
a61af66fc99e Initial load
duke
parents:
diff changeset
166 _error(false) {
a61af66fc99e Initial load
duke
parents:
diff changeset
167 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (logfile != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 _logfile = logfile;
a61af66fc99e Initial load
duke
parents:
diff changeset
170 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
171 _logfile = tty;
a61af66fc99e Initial load
duke
parents:
diff changeset
172 }
a61af66fc99e Initial load
duke
parents:
diff changeset
173
a61af66fc99e Initial load
duke
parents:
diff changeset
174 _error = !os::getTimesSecs(&_starting_real_time,
a61af66fc99e Initial load
duke
parents:
diff changeset
175 &_starting_user_time,
a61af66fc99e Initial load
duke
parents:
diff changeset
176 &_starting_system_time);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 }
a61af66fc99e Initial load
duke
parents:
diff changeset
178 }
a61af66fc99e Initial load
duke
parents:
diff changeset
179
a61af66fc99e Initial load
duke
parents:
diff changeset
180 TraceCPUTime::~TraceCPUTime() {
a61af66fc99e Initial load
duke
parents:
diff changeset
181 if (_active) {
a61af66fc99e Initial load
duke
parents:
diff changeset
182 bool valid = false;
a61af66fc99e Initial load
duke
parents:
diff changeset
183 if (!_error) {
a61af66fc99e Initial load
duke
parents:
diff changeset
184 double real_secs; // walk clock time
a61af66fc99e Initial load
duke
parents:
diff changeset
185 double system_secs; // system time
a61af66fc99e Initial load
duke
parents:
diff changeset
186 double user_secs; // user time for all threads
a61af66fc99e Initial load
duke
parents:
diff changeset
187
a61af66fc99e Initial load
duke
parents:
diff changeset
188 double real_time, user_time, system_time;
a61af66fc99e Initial load
duke
parents:
diff changeset
189 valid = os::getTimesSecs(&real_time, &user_time, &system_time);
a61af66fc99e Initial load
duke
parents:
diff changeset
190 if (valid) {
a61af66fc99e Initial load
duke
parents:
diff changeset
191
a61af66fc99e Initial load
duke
parents:
diff changeset
192 user_secs = user_time - _starting_user_time;
a61af66fc99e Initial load
duke
parents:
diff changeset
193 system_secs = system_time - _starting_system_time;
a61af66fc99e Initial load
duke
parents:
diff changeset
194 real_secs = real_time - _starting_real_time;
a61af66fc99e Initial load
duke
parents:
diff changeset
195
a61af66fc99e Initial load
duke
parents:
diff changeset
196 _logfile->print(" [Times: user=%3.2f sys=%3.2f, real=%3.2f secs] ",
a61af66fc99e Initial load
duke
parents:
diff changeset
197 user_secs, system_secs, real_secs);
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
200 _logfile->print("[Invalid result in TraceCPUTime]");
a61af66fc99e Initial load
duke
parents:
diff changeset
201 }
a61af66fc99e Initial load
duke
parents:
diff changeset
202 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
203 _logfile->print("[Error in TraceCPUTime]");
a61af66fc99e Initial load
duke
parents:
diff changeset
204 }
a61af66fc99e Initial load
duke
parents:
diff changeset
205 if (_print_cr) {
a61af66fc99e Initial load
duke
parents:
diff changeset
206 _logfile->print_cr("");
a61af66fc99e Initial load
duke
parents:
diff changeset
207 }
a61af66fc99e Initial load
duke
parents:
diff changeset
208 }
a61af66fc99e Initial load
duke
parents:
diff changeset
209 }