Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1078)

Unified Diff: runtime/platform/thread_macos.cc

Issue 25909002: Sampling profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: runtime/platform/thread_macos.cc
diff --git a/runtime/platform/thread_macos.cc b/runtime/platform/thread_macos.cc
index e9c6dfc38e85987b61ce4a52414bbafc26e88bda..3c885b57b59c556323640e6a7980d6551154de89 100644
--- a/runtime/platform/thread_macos.cc
+++ b/runtime/platform/thread_macos.cc
@@ -8,6 +8,15 @@
#include "platform/thread.h"
#include <sys/errno.h> // NOLINT
+#include <sys/types.h> // NOLINT
+#include <sys/sysctl.h> // NOLINT
+#include <mach/mach_init.h> // NOLINT
+#include <mach/mach_host.h> // NOLINT
+#include <mach/mach_port.h> // NOLINT
+#include <mach/mach_traps.h> // NOLINT
+#include <mach/task_info.h> // NOLINT
+#include <mach/thread_info.h> // NOLINT
+#include <mach/thread_act.h> // NOLINT
#include "platform/assert.h"
@@ -128,6 +137,29 @@ intptr_t Thread::GetMaxStackSize() {
}
+ThreadId Thread::GetCurrentThreadId() {
+ return pthread_self();
+}
+
+
+void Thread::GetThreadCPUUsage(int64_t* cpu_usage) {
+ ASSERT(cpu_usage != NULL);
+ mach_msg_type_number_t count = THREAD_BASIC_INFO_COUNT;
+ thread_basic_info_data_t info_data;
+ thread_basic_info_t info = &info_data;
+ mach_port_t thread_port = mach_thread_self();
+ kern_return_t r = thread_info(thread_port, THREAD_BASIC_INFO,
+ (thread_info_t)info, &count);
+ mach_port_deallocate(mach_task_self(), thread_port);
+ if (r == KERN_SUCCESS) {
+ *cpu_usage = (info->user_time.seconds * kMicrosecondsPerSecond) +
+ info->user_time.microseconds;
+ return;
+ }
+ *cpu_usage = 0;
+}
+
+
Mutex::Mutex() {
pthread_mutexattr_t attr;
int result = pthread_mutexattr_init(&attr);
@@ -254,6 +286,32 @@ Monitor::WaitResult Monitor::Wait(int64_t millis) {
}
+Monitor::WaitResult Monitor::WaitMicros(int64_t micros) {
+ // TODO(iposva): Do we need to track lock owners?
+ Monitor::WaitResult retval = kNotified;
+ if (micros == 0) {
siva 2013/10/28 05:19:21 ditto comment about using the named constant.
Cutch 2013/11/04 20:36:05 Done.
+ // Wait forever.
+ int result = pthread_cond_wait(data_.cond(), data_.mutex());
+ VALIDATE_PTHREAD_RESULT(result);
+ } else {
+ struct timespec ts;
+ int64_t secs = micros / kMicrosecondsPerSecond;
+ int64_t nanos =
+ (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond;
+ ts.tv_sec = secs;
+ ts.tv_nsec = nanos;
+ int result = pthread_cond_timedwait_relative_np(data_.cond(),
+ data_.mutex(),
+ &ts);
+ ASSERT((result == 0) || (result == ETIMEDOUT));
+ if (result == ETIMEDOUT) {
+ retval = kTimedOut;
+ }
siva 2013/10/28 05:19:21 else { VALIDATE_PTHREAD_RESULT(result); }
Cutch 2013/11/04 20:36:05 Above assert handles this.
+ }
+ return retval;
+}
+
+
void Monitor::Notify() {
// TODO(iposva): Do we need to track lock owners?
int result = pthread_cond_signal(data_.cond());

Powered by Google App Engine
This is Rietveld 408576698