Fix sampling profiler to use thread's cpu clock.
The sampling profiler was using the sampling thread's cpu clock to
measure cpu time, instead of the sampled thread's cpu clock.
Change-Id: Ief1f82e07e0353192c61521f67dec7a761905f64
diff --git a/runtime/thread.cc b/runtime/thread.cc
index 48e595f..c4077de 100644
--- a/runtime/thread.cc
+++ b/runtime/thread.cc
@@ -496,6 +496,19 @@
name.assign(*name_);
}
+uint64_t Thread::GetCpuMicroTime() const {
+#if defined(HAVE_POSIX_CLOCKS)
+ clockid_t cpu_clock_id;
+ pthread_getcpuclockid(pthread_self_, &cpu_clock_id);
+ timespec now;
+ clock_gettime(cpu_clock_id, &now);
+ return static_cast<uint64_t>(now.tv_sec) * 1000000LL + now.tv_nsec / 1000LL;
+#else
+ UNIMPLEMENTED(WARNING);
+ return -1;
+#endif
+}
+
void Thread::AtomicSetFlag(ThreadFlag flag) {
android_atomic_or(flag, &state_and_flags_.as_int);
}