1 /*
2 * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "oops/oop.inline.hpp"
27 #include "runtime/timer.hpp"
28 #include "utilities/ostream.hpp"
29
30 double TimeHelper::counter_to_seconds(jlong counter) {
31 double freq = (double) os::elapsed_frequency();
32 return counter / freq;
33 }
34
35 double TimeHelper::counter_to_millis(jlong counter) {
36 return counter_to_seconds(counter) * 1000.0;
37 }
38
39 elapsedTimer::elapsedTimer(jlong time, jlong timeUnitsPerSecond) {
40 _active = false;
41 jlong osTimeUnitsPerSecond = os::elapsed_frequency();
42 assert(osTimeUnitsPerSecond % 1000 == 0, "must be");
43 assert(timeUnitsPerSecond % 1000 == 0, "must be");
44 while (osTimeUnitsPerSecond < timeUnitsPerSecond) {
45 timeUnitsPerSecond /= 1000;
97 }
98
99 double TimeStamp::seconds() const {
100 assert(is_updated(), "must not be clear");
101 jlong new_count = os::elapsed_counter();
102 return TimeHelper::counter_to_seconds(new_count - _counter);
103 }
104
105 jlong TimeStamp::milliseconds() const {
106 assert(is_updated(), "must not be clear");
107 jlong new_count = os::elapsed_counter();
108 return (jlong)TimeHelper::counter_to_millis(new_count - _counter);
109 }
110
111 jlong TimeStamp::ticks_since_update() const {
112 assert(is_updated(), "must not be clear");
113 return os::elapsed_counter() - _counter;
114 }
115
116 TraceTime::TraceTime(const char* title,
117 bool doit) {
118 _active = doit;
119 _verbose = true;
120
121 if (_active) {
122 _accum = NULL;
123 tty->print("[%s", title);
124 tty->flush();
125 _t.start();
126 }
127 }
128
129 TraceTime::TraceTime(const char* title,
130 elapsedTimer* accumulator,
131 bool doit,
132 bool verbose) {
133 _active = doit;
134 _verbose = verbose;
135 if (_active) {
136 if (_verbose) {
137 tty->print("[%s", title);
138 tty->flush();
139 }
140 _accum = accumulator;
141 _t.start();
142 }
143 }
144
145 TraceTime::~TraceTime() {
146 if (_active) {
147 _t.stop();
148 if (_accum!=NULL) _accum->add(_t);
149 if (_verbose) {
150 tty->print_cr(", %3.7f secs]", _t.seconds());
151 tty->flush();
152 }
153 }
154 }
155
156 TraceCPUTime::TraceCPUTime(bool doit,
157 bool print_cr,
158 outputStream *logfile) :
159 _active(doit),
160 _print_cr(print_cr),
161 _starting_user_time(0.0),
162 _starting_system_time(0.0),
163 _starting_real_time(0.0),
164 _logfile(logfile),
165 _error(false) {
166 if (_active) {
167 if (logfile != NULL) {
168 _logfile = logfile;
169 } else {
170 _logfile = tty;
171 }
|
1 /*
2 * Copyright (c) 1997, 2016, Oracle and/or its affiliates. All rights reserved.
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 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
23 */
24
25 #include "precompiled.hpp"
26 #include "logging/log.hpp"
27 #include "oops/oop.inline.hpp"
28 #include "runtime/timer.hpp"
29 #include "utilities/ostream.hpp"
30
31 double TimeHelper::counter_to_seconds(jlong counter) {
32 double freq = (double) os::elapsed_frequency();
33 return counter / freq;
34 }
35
36 double TimeHelper::counter_to_millis(jlong counter) {
37 return counter_to_seconds(counter) * 1000.0;
38 }
39
40 elapsedTimer::elapsedTimer(jlong time, jlong timeUnitsPerSecond) {
41 _active = false;
42 jlong osTimeUnitsPerSecond = os::elapsed_frequency();
43 assert(osTimeUnitsPerSecond % 1000 == 0, "must be");
44 assert(timeUnitsPerSecond % 1000 == 0, "must be");
45 while (osTimeUnitsPerSecond < timeUnitsPerSecond) {
46 timeUnitsPerSecond /= 1000;
98 }
99
100 double TimeStamp::seconds() const {
101 assert(is_updated(), "must not be clear");
102 jlong new_count = os::elapsed_counter();
103 return TimeHelper::counter_to_seconds(new_count - _counter);
104 }
105
106 jlong TimeStamp::milliseconds() const {
107 assert(is_updated(), "must not be clear");
108 jlong new_count = os::elapsed_counter();
109 return (jlong)TimeHelper::counter_to_millis(new_count - _counter);
110 }
111
112 jlong TimeStamp::ticks_since_update() const {
113 assert(is_updated(), "must not be clear");
114 return os::elapsed_counter() - _counter;
115 }
116
117 TraceTime::TraceTime(const char* title,
118 bool doit,
119 LogTagType tag) {
120 _active = doit;
121 _verbose = true;
122 _tag = tag;
123 _title = title;
124
125 if (_active) {
126 _accum = NULL;
127 _t.start();
128 }
129 }
130
131 TraceTime::TraceTime(const char* title,
132 elapsedTimer* accumulator,
133 bool doit,
134 bool verbose,
135 LogTagType tag) {
136 _active = doit;
137 _verbose = verbose;
138 _tag = tag;
139 _title = title;
140
141 if (_active) {
142 _accum = accumulator;
143 _t.start();
144 }
145 }
146
147 TraceTime::~TraceTime() {
148 if (_active) {
149 _t.stop();
150 if (_accum!=NULL) _accum->add(_t);
151 if (_verbose) {
152 switch (_tag) {
153 case LogTag::_startuptime :
154 log_info(startuptime)("%s, %3.7f secs", _title, _t.seconds());
155 break;
156 case LogTag::__NO_TAG :
157 default :
158 tty->print_cr("[%s, %3.7f secs]", _title, _t.seconds());
159 tty->flush();
160 }
161 }
162 }
163 }
164
165 TraceCPUTime::TraceCPUTime(bool doit,
166 bool print_cr,
167 outputStream *logfile) :
168 _active(doit),
169 _print_cr(print_cr),
170 _starting_user_time(0.0),
171 _starting_system_time(0.0),
172 _starting_real_time(0.0),
173 _logfile(logfile),
174 _error(false) {
175 if (_active) {
176 if (logfile != NULL) {
177 _logfile = logfile;
178 } else {
179 _logfile = tty;
180 }
|