Skip to content

Commit c99df05

Browse files
Use a monotonic clock in the implementation of Stopwatch.
Rename OS::GetCurrentTraceMicros() to OS::GetCurrentMonotonicMicros(). BUG=http://dartbug.com/477 BUG=http://dartbug.com/12383 [email protected] Review URL: https://codereview.chromium.org/1504523002 .
1 parent 5c9a554 commit c99df05

12 files changed

+21
-21
lines changed

runtime/lib/stopwatch.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace dart {
1111

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

1717

runtime/lib/timeline.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ DEFINE_NATIVE_ENTRY(Timeline_getNextAsyncId, 0) {
3232

3333

3434
DEFINE_NATIVE_ENTRY(Timeline_getTraceClock, 0) {
35-
return Integer::New(OS::GetCurrentTraceMicros(), Heap::kNew, true);
35+
return Integer::New(OS::GetCurrentMonotonicMicros(), Heap::kNew, true);
3636
}
3737

3838

runtime/vm/dart_api_impl.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5560,7 +5560,7 @@ DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id,
55605560

55615561

55625562
DART_EXPORT int64_t Dart_TimelineGetMicros() {
5563-
return OS::GetCurrentTraceMicros();
5563+
return OS::GetCurrentMonotonicMicros();
55645564
}
55655565

55665566

runtime/vm/object.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13379,7 +13379,7 @@ RawCode* Code::FinalizeCode(const char* name,
1337913379
VerifiedMemory::Accept(region.start(), region.size());
1338013380
CPU::FlushICache(instrs.EntryPoint(), instrs.size());
1338113381

13382-
code.set_compile_timestamp(OS::GetCurrentTraceMicros());
13382+
code.set_compile_timestamp(OS::GetCurrentMonotonicMicros());
1338313383
CodeObservers::NotifyAll(name,
1338413384
instrs.EntryPoint(),
1338513385
assembler->prologue_offset(),

runtime/vm/os.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class OS {
4848
static int64_t GetCurrentTimeMicros();
4949

5050
// Returns the current time used by the tracing infrastructure.
51-
static int64_t GetCurrentTraceMicros();
51+
static int64_t GetCurrentMonotonicMicros();
5252

5353
// Returns a cleared aligned array of type T with n entries.
5454
// Alignment must be >= 16 and a power of two.

runtime/vm/os_android.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ int64_t OS::GetCurrentTimeMicros() {
179179
}
180180

181181

182-
int64_t OS::GetCurrentTraceMicros() {
182+
int64_t OS::GetCurrentMonotonicMicros() {
183183
struct timespec ts;
184184
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
185185
UNREACHABLE();

runtime/vm/os_linux.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ int64_t OS::GetCurrentTimeMicros() {
396396
}
397397

398398

399-
int64_t OS::GetCurrentTraceMicros() {
399+
int64_t OS::GetCurrentMonotonicMicros() {
400400
struct timespec ts;
401401
if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
402402
UNREACHABLE();

runtime/vm/os_macos.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ int64_t OS::GetCurrentTimeMicros() {
9090
}
9191

9292

93-
int64_t OS::GetCurrentTraceMicros() {
93+
int64_t OS::GetCurrentMonotonicMicros() {
9494
#if TARGET_OS_IOS
9595
// On iOS mach_absolute_time stops while the device is sleeping. Instead use
9696
// now - KERN_BOOTTIME to get a time difference that is not impacted by clock

runtime/vm/os_win.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ int64_t OS::GetCurrentTimeMicros() {
123123

124124
static int64_t qpc_ticks_per_second = 0;
125125

126-
int64_t OS::GetCurrentTraceMicros() {
126+
int64_t OS::GetCurrentMonotonicMicros() {
127127
if (qpc_ticks_per_second == 0) {
128128
// QueryPerformanceCounter not supported, fallback.
129129
return GetCurrentTimeMicros();

runtime/vm/profiler.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,7 @@ static Sample* SetupSample(Thread* thread,
820820
Isolate* isolate = thread->isolate();
821821
ASSERT(sample_buffer != NULL);
822822
Sample* sample = sample_buffer->ReserveSample();
823-
sample->Init(isolate, OS::GetCurrentTraceMicros(), tid);
823+
sample->Init(isolate, OS::GetCurrentMonotonicMicros(), tid);
824824
uword vm_tag = thread->vm_tag();
825825
#if defined(USING_SIMULATOR)
826826
// When running in the simulator, the runtime entry function address

runtime/vm/timeline.cc

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ void TimelineEvent::Reset() {
189189

190190
void TimelineEvent::AsyncBegin(const char* label, int64_t async_id) {
191191
Init(kAsyncBegin, label);
192-
timestamp0_ = OS::GetCurrentTraceMicros();
192+
timestamp0_ = OS::GetCurrentMonotonicMicros();
193193
// Overload timestamp1_ with the async_id.
194194
timestamp1_ = async_id;
195195
}
@@ -198,7 +198,7 @@ void TimelineEvent::AsyncBegin(const char* label, int64_t async_id) {
198198
void TimelineEvent::AsyncInstant(const char* label,
199199
int64_t async_id) {
200200
Init(kAsyncInstant, label);
201-
timestamp0_ = OS::GetCurrentTraceMicros();
201+
timestamp0_ = OS::GetCurrentMonotonicMicros();
202202
// Overload timestamp1_ with the async_id.
203203
timestamp1_ = async_id;
204204
}
@@ -207,26 +207,26 @@ void TimelineEvent::AsyncInstant(const char* label,
207207
void TimelineEvent::AsyncEnd(const char* label,
208208
int64_t async_id) {
209209
Init(kAsyncEnd, label);
210-
timestamp0_ = OS::GetCurrentTraceMicros();
210+
timestamp0_ = OS::GetCurrentMonotonicMicros();
211211
// Overload timestamp1_ with the async_id.
212212
timestamp1_ = async_id;
213213
}
214214

215215

216216
void TimelineEvent::DurationBegin(const char* label) {
217217
Init(kDuration, label);
218-
timestamp0_ = OS::GetCurrentTraceMicros();
218+
timestamp0_ = OS::GetCurrentMonotonicMicros();
219219
}
220220

221221

222222
void TimelineEvent::DurationEnd() {
223-
timestamp1_ = OS::GetCurrentTraceMicros();
223+
timestamp1_ = OS::GetCurrentMonotonicMicros();
224224
}
225225

226226

227227
void TimelineEvent::Instant(const char* label) {
228228
Init(kInstant, label);
229-
timestamp0_ = OS::GetCurrentTraceMicros();
229+
timestamp0_ = OS::GetCurrentMonotonicMicros();
230230
}
231231

232232

@@ -453,7 +453,7 @@ int64_t TimelineEvent::AsyncId() const {
453453
int64_t TimelineEvent::TimeDuration() const {
454454
if (timestamp1_ == 0) {
455455
// This duration is still open, use current time as end.
456-
return OS::GetCurrentTraceMicros() - timestamp0_;
456+
return OS::GetCurrentMonotonicMicros() - timestamp0_;
457457
}
458458
return timestamp1_ - timestamp0_;
459459
}
@@ -529,7 +529,7 @@ TimelineDurationScope::~TimelineDurationScope() {
529529
return;
530530
}
531531
ASSERT(event != NULL);
532-
event->Duration(label_, timestamp_, OS::GetCurrentTraceMicros());
532+
event->Duration(label_, timestamp_, OS::GetCurrentMonotonicMicros());
533533
event->StealArguments(arguments_length_, arguments_);
534534
event->Complete();
535535
arguments_length_ = 0;
@@ -545,7 +545,7 @@ void TimelineDurationScope::Init() {
545545
// Stream is not enabled, do nothing.
546546
return;
547547
}
548-
timestamp_ = OS::GetCurrentTraceMicros();
548+
timestamp_ = OS::GetCurrentMonotonicMicros();
549549
enabled_ = true;
550550
}
551551

runtime/vm/timeline.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,10 @@ class TimelineEvent {
129129
int64_t end_micros);
130130

131131
void Begin(const char* label,
132-
int64_t micros = OS::GetCurrentTraceMicros());
132+
int64_t micros = OS::GetCurrentMonotonicMicros());
133133

134134
void End(const char* label,
135-
int64_t micros = OS::GetCurrentTraceMicros());
135+
int64_t micros = OS::GetCurrentMonotonicMicros());
136136

137137
void SerializedJSON(const char* json);
138138

0 commit comments

Comments
 (0)