diff --git a/runtime/vm/os.h b/runtime/vm/os.h index a5fb7391994..aab5c4da7fc 100644 --- a/runtime/vm/os.h +++ b/runtime/vm/os.h @@ -63,6 +63,11 @@ class OS { // NOTE: This function will return -1 on OSs that are not supported. static int64_t GetCurrentThreadCPUMicros(); + // If the tracing/timeline configuration on the current OS supports thread + // timestamps, returns the same value as |GetCurrentThreadCPUMicros|. + // Otherwise, returns -1. + static int64_t GetCurrentThreadCPUMicrosForTimeline(); + // Returns the activation frame alignment constraint or one if // the platform doesn't care. Guaranteed to be a power of two. static intptr_t ActivationFrameAlignment(); diff --git a/runtime/vm/os_android.cc b/runtime/vm/os_android.cc index 7ac97ec4278..10ad9cf62ba 100644 --- a/runtime/vm/os_android.cc +++ b/runtime/vm/os_android.cc @@ -177,6 +177,10 @@ int64_t OS::GetCurrentThreadCPUMicros() { return result; } +int64_t OS::GetCurrentThreadCPUMicrosForTimeline() { + return OS::GetCurrentThreadCPUMicros(); +} + // TODO(5411554): May need to hoist these architecture dependent code // into a architecture specific file e.g: os_ia32_linux.cc intptr_t OS::ActivationFrameAlignment() { diff --git a/runtime/vm/os_fuchsia.cc b/runtime/vm/os_fuchsia.cc index 76f1433100b..9e2dd9b0a27 100644 --- a/runtime/vm/os_fuchsia.cc +++ b/runtime/vm/os_fuchsia.cc @@ -287,6 +287,13 @@ int64_t OS::GetCurrentThreadCPUMicros() { return now / kNanosecondsPerMicrosecond; } +// On Fuchsia, thread timestamp values are not used in the tracing/timeline +// integration. Because of this, we try to avoid querying them, since doing so +// has both a runtime and trace buffer storage cost. +int64_t OS::GetCurrentThreadCPUMicrosForTimeline() { + return -1; +} + // TODO(5411554): May need to hoist these architecture dependent code // into a architecture specific file e.g: os_ia32_fuchsia.cc intptr_t OS::ActivationFrameAlignment() { diff --git a/runtime/vm/os_linux.cc b/runtime/vm/os_linux.cc index 70341061229..fcca4f71bb8 100644 --- a/runtime/vm/os_linux.cc +++ b/runtime/vm/os_linux.cc @@ -492,6 +492,10 @@ int64_t OS::GetCurrentThreadCPUMicros() { return result; } +int64_t OS::GetCurrentThreadCPUMicrosForTimeline() { + return OS::GetCurrentThreadCPUMicros(); +} + // TODO(5411554): May need to hoist these architecture dependent code // into a architecture specific file e.g: os_ia32_linux.cc intptr_t OS::ActivationFrameAlignment() { diff --git a/runtime/vm/os_macos.cc b/runtime/vm/os_macos.cc index c18ca45874f..4ff4a9b873e 100644 --- a/runtime/vm/os_macos.cc +++ b/runtime/vm/os_macos.cc @@ -127,6 +127,10 @@ int64_t OS::GetCurrentThreadCPUMicros() { #endif } +int64_t OS::GetCurrentThreadCPUMicrosForTimeline() { + return OS::GetCurrentThreadCPUMicros(); +} + intptr_t OS::ActivationFrameAlignment() { #if HOST_OS_IOS #if TARGET_ARCH_ARM diff --git a/runtime/vm/os_win.cc b/runtime/vm/os_win.cc index 2ed4d87e04e..da2d6f7d5a7 100644 --- a/runtime/vm/os_win.cc +++ b/runtime/vm/os_win.cc @@ -174,6 +174,10 @@ int64_t OS::GetCurrentThreadCPUMicros() { return -1; } +int64_t OS::GetCurrentThreadCPUMicrosForTimeline() { + return OS::GetCurrentThreadCPUMicros(); +} + intptr_t OS::ActivationFrameAlignment() { #if defined(TARGET_ARCH_ARM64) return 16; diff --git a/runtime/vm/timeline.cc b/runtime/vm/timeline.cc index 2fe569c0f62..94b0cf35c8c 100644 --- a/runtime/vm/timeline.cc +++ b/runtime/vm/timeline.cc @@ -1581,7 +1581,7 @@ void DartTimelineEventHelpers::ReportTaskEvent(Thread* thread, (phase[0] == 'B') || (phase[0] == 'E')); ASSERT(phase[1] == '\0'); const int64_t start = OS::GetCurrentMonotonicMicros(); - const int64_t start_cpu = OS::GetCurrentThreadCPUMicros(); + const int64_t start_cpu = OS::GetCurrentThreadCPUMicrosForTimeline(); switch (phase[0]) { case 'n': event->AsyncInstant(name, id, start); diff --git a/runtime/vm/timeline.h b/runtime/vm/timeline.h index 57f0dc75614..2824fd08473 100644 --- a/runtime/vm/timeline.h +++ b/runtime/vm/timeline.h @@ -248,11 +248,13 @@ class TimelineEvent { int64_t async_id, int64_t micros = OS::GetCurrentMonotonicMicros()); - void DurationBegin(const char* label, - int64_t micros = OS::GetCurrentMonotonicMicros(), - int64_t thread_micros = OS::GetCurrentThreadCPUMicros()); - void DurationEnd(int64_t micros = OS::GetCurrentMonotonicMicros(), - int64_t thread_micros = OS::GetCurrentThreadCPUMicros()); + void DurationBegin( + const char* label, + int64_t micros = OS::GetCurrentMonotonicMicros(), + int64_t thread_micros = OS::GetCurrentThreadCPUMicrosForTimeline()); + void DurationEnd( + int64_t micros = OS::GetCurrentMonotonicMicros(), + int64_t thread_micros = OS::GetCurrentThreadCPUMicrosForTimeline()); void Instant(const char* label, int64_t micros = OS::GetCurrentMonotonicMicros()); @@ -263,13 +265,14 @@ class TimelineEvent { int64_t thread_start_micros = -1, int64_t thread_end_micros = -1); - void Begin(const char* label, - int64_t micros = OS::GetCurrentMonotonicMicros(), - int64_t thread_micros = OS::GetCurrentThreadCPUMicros()); + void Begin( + const char* label, + int64_t micros = OS::GetCurrentMonotonicMicros(), + int64_t thread_micros = OS::GetCurrentThreadCPUMicrosForTimeline()); void End(const char* label, int64_t micros = OS::GetCurrentMonotonicMicros(), - int64_t thread_micros = OS::GetCurrentThreadCPUMicros()); + int64_t thread_micros = OS::GetCurrentThreadCPUMicrosForTimeline()); void Counter(const char* label, int64_t micros = OS::GetCurrentMonotonicMicros());