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

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, 1 month 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
« no previous file with comments | « runtime/platform/thread_macos.h ('k') | runtime/platform/thread_win.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/thread_macos.cc
diff --git a/runtime/platform/thread_macos.cc b/runtime/platform/thread_macos.cc
index e9c6dfc38e85987b61ce4a52414bbafc26e88bda..8d4445d15c5e4baee3347e7d1a33fa60b6b1f3df 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,30 @@ intptr_t Thread::GetMaxStackSize() {
}
+ThreadId Thread::GetCurrentThreadId() {
+ return pthread_self();
+}
+
+
+void Thread::GetThreadCpuUsage(ThreadId thread_id, int64_t* cpu_usage) {
+ ASSERT(thread_id == GetCurrentThreadId());
+ 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);
@@ -229,17 +262,22 @@ void Monitor::Exit() {
Monitor::WaitResult Monitor::Wait(int64_t millis) {
+ return WaitMicros(millis * kMicrosecondsPerMillisecond);
+}
+
+
+Monitor::WaitResult Monitor::WaitMicros(int64_t micros) {
// TODO(iposva): Do we need to track lock owners?
Monitor::WaitResult retval = kNotified;
- if (millis == 0) {
+ if (micros == kNoTimeout) {
// Wait forever.
int result = pthread_cond_wait(data_.cond(), data_.mutex());
VALIDATE_PTHREAD_RESULT(result);
} else {
struct timespec ts;
- int64_t secs = millis / kMillisecondsPerSecond;
- int64_t nanos = (millis - (secs * kMillisecondsPerSecond)) *
- kNanosecondsPerMillisecond;
+ 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(),
« no previous file with comments | « runtime/platform/thread_macos.h ('k') | runtime/platform/thread_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698