Skip to content

Commit

Permalink
Use a monotonic clock in the implementation of Stopwatch.
Browse files Browse the repository at this point in the history
Rename OS::GetCurrentTraceMicros() to OS::GetCurrentMonotonicMicros().

BUG=http://dartbug.com/477
BUG=http://dartbug.com/12383
R=iposva@google.com

Review URL: https://codereview.chromium.org/1504523002 .
  • Loading branch information
rmacnak-google committed Dec 8, 2015
1 parent 5c9a554 commit c99df05
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 21 deletions.
2 changes: 1 addition & 1 deletion runtime/lib/stopwatch.cc
Expand Up @@ -11,7 +11,7 @@ namespace dart {

DEFINE_NATIVE_ENTRY(Stopwatch_now, 0) {
// TODO(iposva): investigate other hi-res time sources such as cycle count.
return Integer::New(OS::GetCurrentTimeMicros());
return Integer::New(OS::GetCurrentMonotonicMicros());
}


Expand Down
2 changes: 1 addition & 1 deletion runtime/lib/timeline.cc
Expand Up @@ -32,7 +32,7 @@ DEFINE_NATIVE_ENTRY(Timeline_getNextAsyncId, 0) {


DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) {
return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true);
return Integer::New(OS::GetCurrentMonotonicMicros(), Heap::kNew, true);
}


Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/dart_api_impl.cc
Expand Up @@ -5560,7 +5560,7 @@ DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id,


DART_EXPORT int64_t Dart_TimelineGetMicros() {
return OS::GetCurrentTraceMicros();
return OS::GetCurrentMonotonicMicros();
}


Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/object.cc
Expand Up @@ -13379,7 +13379,7 @@ RawCode* Code::FinalizeCode(const char* name,
VerifiedMemory::Accept(region.start(), region.size());
CPU::FlushICache(instrs.EntryPoint(), instrs.size());

code.set_compile_timestamp(OS::GetCurrentTraceMicros());
code.set_compile_timestamp(OS::GetCurrentMonotonicMicros());
CodeObservers::NotifyAll(name,
instrs.EntryPoint(),
assembler->prologue_offset(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/os.h
Expand Up @@ -48,7 +48,7 @@ class OS {
static int64_t GetCurrentTimeMicros();

// Returns the current time used by the tracing infrastructure.
static int64_t GetCurrentTraceMicros();
static int64_t GetCurrentMonotonicMicros();

// Returns a cleared aligned array of type T with n entries.
// Alignment must be >= 16 and a power of two.
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/os_android.cc
Expand Up @@ -179,7 +179,7 @@ int64_t OS::GetCurrentTimeMicros() {
}


int64_t OS::GetCurrentTraceMicros() {
int64_t OS::GetCurrentMonotonicMicros() {
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
UNREACHABLE();
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/os_linux.cc
Expand Up @@ -396,7 +396,7 @@ int64_t OS::GetCurrentTimeMicros() {
}


int64_t OS::GetCurrentTraceMicros() {
int64_t OS::GetCurrentMonotonicMicros() {
struct timespec ts;
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
UNREACHABLE();
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/os_macos.cc
Expand Up @@ -90,7 +90,7 @@ int64_t OS::GetCurrentTimeMicros() {
}


int64_t OS::GetCurrentTraceMicros() {
int64_t OS::GetCurrentMonotonicMicros() {
#if TARGET_OS_IOS
// On iOS mach_absolute_time stops while the device is sleeping. Instead use
// now - KERN_BOOTTIME to get a time difference that is not impacted by clock
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/os_win.cc
Expand Up @@ -123,7 +123,7 @@ int64_t OS::GetCurrentTimeMicros() {

static int64_t qpc_ticks_per_second = 0;

int64_t OS::GetCurrentTraceMicros() {
int64_t OS::GetCurrentMonotonicMicros() {
if (qpc_ticks_per_second == 0) {
// QueryPerformanceCounter not supported, fallback.
return GetCurrentTimeMicros();
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/profiler.cc
Expand Up @@ -820,7 +820,7 @@ static Sample* SetupSample(Thread* thread,
Isolate* isolate = thread->isolate();
ASSERT(sample_buffer != NULL);
Sample* sample = sample_buffer->ReserveSample();
sample->Init(isolate, OS::GetCurrentTraceMicros(), tid);
sample->Init(isolate, OS::GetCurrentMonotonicMicros(), tid);
uword vm_tag = thread->vm_tag();
#if defined(USING_SIMULATOR)
// When running in the simulator, the runtime entry function address
Expand Down
18 changes: 9 additions & 9 deletions runtime/vm/timeline.cc
Expand Up @@ -189,7 +189,7 @@ void TimelineEvent::Reset() {

void TimelineEvent::AsyncBegin(const char* label, int64_t async_id) {
Init(kAsyncBegin, label);
timestamp0_ = OS::GetCurrentTraceMicros();
timestamp0_ = OS::GetCurrentMonotonicMicros();
// Overload timestamp1_ with the async_id.
timestamp1_ = async_id;
}
Expand All @@ -198,7 +198,7 @@ void TimelineEvent::AsyncBegin(const char* label, int64_t async_id) {
void TimelineEvent::AsyncInstant(const char* label,
int64_t async_id) {
Init(kAsyncInstant, label);
timestamp0_ = OS::GetCurrentTraceMicros();
timestamp0_ = OS::GetCurrentMonotonicMicros();
// Overload timestamp1_ with the async_id.
timestamp1_ = async_id;
}
Expand All @@ -207,26 +207,26 @@ void TimelineEvent::AsyncInstant(const char* label,
void TimelineEvent::AsyncEnd(const char* label,
int64_t async_id) {
Init(kAsyncEnd, label);
timestamp0_ = OS::GetCurrentTraceMicros();
timestamp0_ = OS::GetCurrentMonotonicMicros();
// Overload timestamp1_ with the async_id.
timestamp1_ = async_id;
}


void TimelineEvent::DurationBegin(const char* label) {
Init(kDuration, label);
timestamp0_ = OS::GetCurrentTraceMicros();
timestamp0_ = OS::GetCurrentMonotonicMicros();
}


void TimelineEvent::DurationEnd() {
timestamp1_ = OS::GetCurrentTraceMicros();
timestamp1_ = OS::GetCurrentMonotonicMicros();
}


void TimelineEvent::Instant(const char* label) {
Init(kInstant, label);
timestamp0_ = OS::GetCurrentTraceMicros();
timestamp0_ = OS::GetCurrentMonotonicMicros();
}


Expand Down Expand Up @@ -453,7 +453,7 @@ int64_t TimelineEvent::AsyncId() const {
int64_t TimelineEvent::TimeDuration() const {
if (timestamp1_ == 0) {
// This duration is still open, use current time as end.
return OS::GetCurrentTraceMicros() - timestamp0_;
return OS::GetCurrentMonotonicMicros() - timestamp0_;
}
return timestamp1_ - timestamp0_;
}
Expand Down Expand Up @@ -529,7 +529,7 @@ TimelineDurationScope::~TimelineDurationScope() {
return;
}
ASSERT(event != NULL);
event->Duration(label_, timestamp_, OS::GetCurrentTraceMicros());
event->Duration(label_, timestamp_, OS::GetCurrentMonotonicMicros());
event->StealArguments(arguments_length_, arguments_);
event->Complete();
arguments_length_ = 0;
Expand All @@ -545,7 +545,7 @@ void TimelineDurationScope::Init() {
// Stream is not enabled, do nothing.
return;
}
timestamp_ = OS::GetCurrentTraceMicros();
timestamp_ = OS::GetCurrentMonotonicMicros();
enabled_ = true;
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/timeline.h
Expand Up @@ -129,10 +129,10 @@ class TimelineEvent {
int64_t end_micros);

void Begin(const char* label,
int64_t micros = OS::GetCurrentTraceMicros());
int64_t micros = OS::GetCurrentMonotonicMicros());

void End(const char* label,
int64_t micros = OS::GetCurrentTraceMicros());
int64_t micros = OS::GetCurrentMonotonicMicros());

void SerializedJSON(const char* json);

Expand Down

0 comments on commit c99df05

Please sign in to comment.