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

Unified Diff: runtime/platform/thread_android.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_android.h ('k') | runtime/platform/thread_linux.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/platform/thread_android.cc
diff --git a/runtime/platform/thread_android.cc b/runtime/platform/thread_android.cc
index 20e0e9ec5a4b564e626115aca041dd20cbd2a8ed..f29ffdb8e1fc06e8af9fb3207d9fbae0030526e5 100644
--- a/runtime/platform/thread_android.cc
+++ b/runtime/platform/thread_android.cc
@@ -39,10 +39,10 @@ namespace dart {
#endif
-static void ComputeTimeSpec(struct timespec* ts, int64_t millis) {
- int64_t secs = millis / kMillisecondsPerSecond;
+static void ComputeTimeSpecMicros(struct timespec* ts, int64_t micros) {
+ int64_t secs = micros / kMicrosecondsPerSecond;
int64_t nanos =
- (millis - (secs * kMillisecondsPerSecond)) * kNanosecondsPerMillisecond;
+ (micros - (secs * kMicrosecondsPerSecond)) * kNanosecondsPerMicrosecond;
int result = clock_gettime(CLOCK_MONOTONIC, ts);
ASSERT(result == 0);
ts->tv_sec += secs;
@@ -144,6 +144,22 @@ 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);
+ struct timespec ts;
+ int r = clock_gettime(CLOCK_THREAD_CPUTIME_ID, &ts);
+ ASSERT(r == 0);
+ *cpu_usage = (ts.tv_sec * kNanosecondsPerSecond + ts.tv_nsec) /
+ kNanosecondsPerMicrosecond;
+}
+
+
Mutex::Mutex() {
pthread_mutexattr_t attr;
int result = pthread_mutexattr_init(&attr);
@@ -252,17 +268,21 @@ 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;
- ComputeTimeSpec(&ts, millis);
- int result = pthread_cond_timedwait_monotonic(
- data_.cond(), data_.mutex(), &ts);
+ ComputeTimeSpecMicros(&ts, micros);
+ int result = pthread_cond_timedwait(data_.cond(), data_.mutex(), &ts);
ASSERT((result == 0) || (result == ETIMEDOUT));
if (result == ETIMEDOUT) {
retval = kTimedOut;
« no previous file with comments | « runtime/platform/thread_android.h ('k') | runtime/platform/thread_linux.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698