[vm] More efficiently access thread CPU time on Mac.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/47850
Change-Id: I5719c42b4e2aa0d1a1b02c5e274cdb9b93177ca1
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240148
Reviewed-by: Ben Konyi <bkonyi@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/os_macos.cc b/runtime/vm/os_macos.cc
index eed635d..05f9ee4 100644
--- a/runtime/vm/os_macos.cc
+++ b/runtime/vm/os_macos.cc
@@ -106,6 +106,12 @@
 }
 
 int64_t OS::GetCurrentThreadCPUMicros() {
+  if (__builtin_available(macOS 10.12, iOS 10.0, *)) {
+    // This is more efficient when available.
+    return clock_gettime_nsec_np(CLOCK_THREAD_CPUTIME_ID) /
+           kNanosecondsPerMicrosecond;
+  }
+
   mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
   thread_basic_info_data_t info_data;
   thread_basic_info_t info = &info_data;