diff options
| author | 2014-12-17 19:13:39 +0000 | |
|---|---|---|
| committer | 2014-12-17 19:13:39 +0000 | |
| commit | d457b9cebceecc9d54fb569ea76509341153bf5c (patch) | |
| tree | a3ea3f9bf0871f5c135754f5088ee15352e33917 | |
| parent | 28d6b6c06fdb6c3dc30beb7883fa64f2b693d9ab (diff) | |
| parent | f0dc8b5519102b3d3e738aed846975ae4239421e (diff) | |
Merge "Add systrace events to monitors and thread suspension"
| -rw-r--r-- | runtime/monitor.cc | 11 | ||||
| -rw-r--r-- | runtime/thread_list.cc | 15 |
2 files changed, 25 insertions, 1 deletions
diff --git a/runtime/monitor.cc b/runtime/monitor.cc index 233267b53c..1ef5221627 100644 --- a/runtime/monitor.cc +++ b/runtime/monitor.cc @@ -16,6 +16,9 @@ #include "monitor.h" +#define ATRACE_TAG ATRACE_TAG_DALVIK + +#include <cutils/trace.h> #include <vector> #include "base/mutex.h" @@ -251,7 +254,12 @@ void Monitor::Lock(Thread* self) { { ScopedThreadStateChange tsc(self, kBlocked); // Change to blocked and give up mutator_lock_. MutexLock mu2(self, monitor_lock_); // Reacquire monitor_lock_ without mutator_lock_ for Wait. - if (owner_ != NULL) { // Did the owner_ give the lock up? + if (owner_ != nullptr) { // Did the owner_ give the lock up? + if (ATRACE_ENABLED()) { + std::string name; + owner_->GetThreadName(name); + ATRACE_BEGIN(("Contended on monitor with owner " + name).c_str()); + } monitor_contenders_.Wait(self); // Still contended so wait. // Woken from contention. if (log_contention) { @@ -275,6 +283,7 @@ void Monitor::Lock(Thread* self) { LogContentionEvent(self, wait_ms, sample_percent, owners_filename, owners_line_number); } } + ATRACE_END(); } } self->SetMonitorEnterObject(nullptr); diff --git a/runtime/thread_list.cc b/runtime/thread_list.cc index 6a9111fad5..65a8bd04ad 100644 --- a/runtime/thread_list.cc +++ b/runtime/thread_list.cc @@ -454,6 +454,9 @@ void ThreadList::ResumeAll() { } void ThreadList::Resume(Thread* thread, bool for_debugger) { + // This assumes there was an ATRACE_BEGIN when we suspended the thread. + ATRACE_END(); + Thread* self = Thread::Current(); DCHECK_NE(thread, self); VLOG(threads) << "Resume(" << reinterpret_cast<void*>(thread) << ") starting..." @@ -564,6 +567,12 @@ Thread* ThreadList::SuspendThreadByPeer(jobject peer, bool request_suspension, // done. if (thread->IsSuspended()) { VLOG(threads) << "SuspendThreadByPeer thread suspended: " << *thread; + if (ATRACE_ENABLED()) { + std::string name; + thread->GetThreadName(name); + ATRACE_BEGIN(StringPrintf("SuspendThreadByPeer suspended %s for peer=%p", name.c_str(), + peer).c_str()); + } return thread; } if (total_delay_us >= kTimeoutUs) { @@ -648,6 +657,12 @@ Thread* ThreadList::SuspendThreadByThreadId(uint32_t thread_id, bool debug_suspe // count, or else we've waited and it has self suspended) or is the current thread, we're // done. if (thread->IsSuspended()) { + if (ATRACE_ENABLED()) { + std::string name; + thread->GetThreadName(name); + ATRACE_BEGIN(StringPrintf("SuspendThreadByThreadId suspended %s id=%d", + name.c_str(), thread_id).c_str()); + } VLOG(threads) << "SuspendThreadByThreadId thread suspended: " << *thread; return thread; } |