2
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
25
#include "precompiled.hpp"
26
#include "logging/log.hpp"
27
#include "oops/oop.inline.hpp"
28
#include "runtime/os.hpp"
29
#include "runtime/timer.hpp"
30
#include "utilities/ostream.hpp"
32
double TimeHelper::counter_to_seconds(jlong counter) {
33
double freq = (double) os::elapsed_frequency();
34
return (double)counter / freq;
37
double TimeHelper::counter_to_millis(jlong counter) {
38
return counter_to_seconds(counter) * 1000.0;
41
jlong TimeHelper::millis_to_counter(jlong millis) {
42
jlong freq = os::elapsed_frequency() / MILLIUNITS;
46
jlong TimeHelper::micros_to_counter(jlong micros) {
47
jlong freq = os::elapsed_frequency() / MICROUNITS;
51
void elapsedTimer::add(elapsedTimer t) {
52
_counter += t._counter;
55
void elapsedTimer::add_nanoseconds(jlong ns) {
56
jlong freq = os::elapsed_frequency() / NANOUNITS;
57
_counter += ns * freq;
60
void elapsedTimer::start() {
63
_start_counter = os::elapsed_counter();
67
void elapsedTimer::stop() {
69
_counter += os::elapsed_counter() - _start_counter;
74
double elapsedTimer::seconds() const {
75
return TimeHelper::counter_to_seconds(_counter);
78
jlong elapsedTimer::milliseconds() const {
79
return (jlong)TimeHelper::counter_to_millis(_counter);
82
jlong elapsedTimer::active_ticks() const {
86
jlong counter = _counter + os::elapsed_counter() - _start_counter;
90
void TimeStamp::update_to(jlong ticks) {
92
if (_counter == 0) _counter = 1;
93
assert(is_updated(), "must not look clear");
96
void TimeStamp::update() {
97
update_to(os::elapsed_counter());
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);
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);
112
jlong TimeStamp::ticks_since_update() const {
113
assert(is_updated(), "must not be clear");
114
return os::elapsed_counter() - _counter;