summaryrefslogtreecommitdiffstats
path: root/runtime/base
diff options
context:
space:
mode:
authorHiroshi Yamauchi <yamauchi@google.com>2013-08-12 17:28:49 -0700
committerHiroshi Yamauchi <yamauchi@google.com>2013-08-13 13:53:12 -0700
commitb3733086ab415088b97fac20b3eea24433a7d2c5 (patch)
treead853d385e5c113e5d6248d0f7d198d7d9136865 /runtime/base
parent4baa8083ae0820f71cf0f03b94fd7f8d3b9bfa46 (diff)
downloadart-b3733086ab415088b97fac20b3eea24433a7d2c5.zip
art-b3733086ab415088b97fac20b3eea24433a7d2c5.tar.gz
art-b3733086ab415088b97fac20b3eea24433a7d2c5.tar.bz2
Add a systrace support for lock contention logging.
- Now several ART executables like oatdump need to link with libcutils as the mutex code is shared among them. - The blocking thread ID and lock owner thread ID are passed to ScopedContentionRecorder in the correct order. Bug: 9986464 Change-Id: Id766de23fbc4af1d8ba2de051595e365b04f5ae7
Diffstat (limited to 'runtime/base')
-rw-r--r--runtime/base/mutex-inl.h9
-rw-r--r--runtime/base/mutex.cc6
2 files changed, 12 insertions, 3 deletions
diff --git a/runtime/base/mutex-inl.h b/runtime/base/mutex-inl.h
index 7f3b459..a559d63 100644
--- a/runtime/base/mutex-inl.h
+++ b/runtime/base/mutex-inl.h
@@ -19,7 +19,10 @@
#include "mutex.h"
+#define ATRACE_TAG ATRACE_TAG_DALVIK
+
#include "cutils/atomic-inline.h"
+#include "cutils/trace.h"
#include "runtime.h"
#include "thread.h"
@@ -45,10 +48,16 @@ class ScopedContentionRecorder {
blocked_tid_(kLogLockContentions ? blocked_tid : 0),
owner_tid_(kLogLockContentions ? owner_tid : 0),
start_nano_time_(kLogLockContentions ? NanoTime() : 0) {
+ if (kLogLockContentions) {
+ std::string msg = StringPrintf("Lock contention on %s (owner tid: %llu)",
+ mutex->GetName(), owner_tid);
+ ATRACE_BEGIN(msg.c_str());
+ }
}
~ScopedContentionRecorder() {
if (kLogLockContentions) {
+ ATRACE_END();
uint64_t end_nano_time = NanoTime();
mutex_->RecordContention(blocked_tid_, owner_tid_, end_nano_time - start_nano_time_);
}
diff --git a/runtime/base/mutex.cc b/runtime/base/mutex.cc
index 3007978..b99e7c9 100644
--- a/runtime/base/mutex.cc
+++ b/runtime/base/mutex.cc
@@ -351,7 +351,7 @@ void Mutex::ExclusiveLock(Thread* self) {
done = android_atomic_acquire_cas(0, 1, &state_) == 0;
} else {
// Failed to acquire, hang up.
- ScopedContentionRecorder scr(this, GetExclusiveOwnerTid(), SafeGetTid(self));
+ ScopedContentionRecorder scr(this, SafeGetTid(self), GetExclusiveOwnerTid());
android_atomic_inc(&num_contenders_);
if (futex(&state_, FUTEX_WAIT, 1, NULL, NULL, 0) != 0) {
// EAGAIN and EINTR both indicate a spurious failure, try again from the beginning.
@@ -554,7 +554,7 @@ void ReaderWriterMutex::ExclusiveLock(Thread* self) {
done = android_atomic_acquire_cas(0, -1, &state_) == 0;
} else {
// Failed to acquire, hang up.
- ScopedContentionRecorder scr(this, GetExclusiveOwnerTid(), SafeGetTid(self));
+ ScopedContentionRecorder scr(this, SafeGetTid(self), GetExclusiveOwnerTid());
android_atomic_inc(&num_pending_writers_);
if (futex(&state_, FUTEX_WAIT, cur_state, NULL, NULL, 0) != 0) {
// EAGAIN and EINTR both indicate a spurious failure, try again from the beginning.
@@ -623,7 +623,7 @@ bool ReaderWriterMutex::ExclusiveLockWithTimeout(Thread* self, int64_t ms, int32
if (ComputeRelativeTimeSpec(&rel_ts, end_abs_ts, now_abs_ts)) {
return false; // Timed out.
}
- ScopedContentionRecorder scr(this, GetExclusiveOwnerTid(), SafeGetTid(self));
+ ScopedContentionRecorder scr(this, SafeGetTid(self), GetExclusiveOwnerTid());
android_atomic_inc(&num_pending_writers_);
if (futex(&state_, FUTEX_WAIT, cur_state, &rel_ts, NULL, 0) != 0) {
if (errno == ETIMEDOUT) {