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

Unified Diff: base/threading/platform_thread_android.cc

Issue 144943004: Set thread names to be visible in debuggers (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 6 years, 10 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/threading/platform_thread_android.cc
diff --git a/base/threading/platform_thread_android.cc b/base/threading/platform_thread_android.cc
index 0dbb1913d0e08af10fb86330a66dc75b41edd40f..bd0b4b33db74a137fa1dd0508f39586362857d5a 100644
--- a/base/threading/platform_thread_android.cc
+++ b/base/threading/platform_thread_android.cc
@@ -5,6 +5,7 @@
#include "base/threading/platform_thread.h"
#include <errno.h>
+#include <sys/prctl.h>
#include <sys/resource.h>
#include "base/android/jni_android.h"
@@ -77,6 +78,18 @@ void PlatformThread::SetThreadPriority(PlatformThreadHandle handle,
void PlatformThread::SetName(const char* name) {
ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
tracked_objects::ThreadData::InitializeThreadContext(name);
+
+ // Like linux, on android we can get the thread names to show up in the
+ // debugger by setting the process name for the LWP.
+ // We don't want to do this for the main thread because that would rename
+ // the process, causing tools like killall to stop working.
+ if (PlatformThread::CurrentId() == getpid())
+ return;
+
+ // Set the name for the LWP (which gets truncated to 15 characters).
+ int err = prctl(PR_SET_NAME, name);
+ if (err < 0 && errno != EPERM)
+ DPLOG(ERROR) << "prctl(PR_SET_NAME)";
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698