< prev index next > src/hotspot/share/runtime/timer.cpp
Print this page
#include "precompiled.hpp"
#include "logging/log.hpp"
#include "oops/oop.inline.hpp"
#include "runtime/os.hpp"
+ #include "runtime/thread.hpp"
#include "runtime/timer.hpp"
#include "utilities/ostream.hpp"
double TimeHelper::counter_to_seconds(jlong counter) {
double freq = (double) os::elapsed_frequency();
jlong TimeHelper::micros_to_counter(jlong micros) {
jlong freq = os::elapsed_frequency() / MICROUNITS;
return micros * freq;
}
! void elapsedTimer::add(elapsedTimer t) {
! _counter += t._counter;
}
! void elapsedTimer::add_nanoseconds(jlong ns) {
jlong freq = os::elapsed_frequency() / NANOUNITS;
_counter += ns * freq;
}
! void elapsedTimer::start() {
if (!_active) {
_active = true;
! _start_counter = os::elapsed_counter();
}
}
! void elapsedTimer::stop() {
if (_active) {
! _counter += os::elapsed_counter() - _start_counter;
_active = false;
}
}
! double elapsedTimer::seconds() const {
return TimeHelper::counter_to_seconds(_counter);
}
! jlong elapsedTimer::milliseconds() const {
return (jlong)TimeHelper::counter_to_millis(_counter);
}
! jlong elapsedTimer::active_ticks() const {
if (!_active) {
return ticks();
}
! jlong counter = _counter + os::elapsed_counter() - _start_counter;
return counter;
}
void TimeStamp::update_to(jlong ticks) {
_counter = ticks;
if (_counter == 0) _counter = 1;
assert(is_updated(), "must not look clear");
}
jlong TimeHelper::micros_to_counter(jlong micros) {
jlong freq = os::elapsed_frequency() / MICROUNITS;
return micros * freq;
}
! void BaseTimer::add(BaseTimer* t) {
! _counter += t->_counter;
}
! void BaseTimer::add_nanoseconds(jlong ns) {
jlong freq = os::elapsed_frequency() / NANOUNITS;
_counter += ns * freq;
}
! void BaseTimer::start() {
if (!_active) {
_active = true;
! _start_counter = read_counter();
}
}
! void BaseTimer::stop() {
if (_active) {
! _counter += read_counter() - _start_counter;
_active = false;
}
}
! double BaseTimer::seconds() const {
return TimeHelper::counter_to_seconds(_counter);
}
! jlong BaseTimer::milliseconds() const {
return (jlong)TimeHelper::counter_to_millis(_counter);
}
! jlong BaseTimer::active_ticks() const {
if (!_active) {
return ticks();
}
! jlong counter = _counter + read_counter() - _start_counter;
return counter;
}
+ jlong elapsedTimer::read_counter() const {
+ return os::elapsed_counter();
+ }
+
+ ThreadTimer::ThreadTimer() {
+ _owner = Thread::current();
+ }
+
+ void ThreadTimer::start() {
+ assert(_owner != nullptr, "timer must be bound to a thread");
+ Thread* current = Thread::current();
+ assert(current == _owner, "timer can only be started by the thread that owns it");
+ BaseTimer::start();
+ }
+
+ void ThreadTimer::stop() {
+ assert(_owner != nullptr, "sanity check");
+ Thread* current = Thread::current();
+ assert(current == _owner, "timer can only be stopped by the thread that owns it");
+ if (_start_counter != -1) {
+ BaseTimer::stop();
+ }
+ }
+
+ jlong ThreadTimer::read_counter() const {
+ assert(_owner != nullptr, "sanity check");
+ return os::thread_cpu_time(_owner);
+ }
+
void TimeStamp::update_to(jlong ticks) {
_counter = ticks;
if (_counter == 0) _counter = 1;
assert(is_updated(), "must not look clear");
}
< prev index next >