When a binder service's main thread joins the thread pool
it retains its name (whatever the exec name was), which is
very confusing in systrace.
we now rename that thread just like its friends in the
thread pool.
Change-Id: Ibb3b6ff07304b247cfc6fb1694e72350c579513e
public:
static status_t publish(bool allowIsolated = false) {
sp<IServiceManager> sm(defaultServiceManager());
public:
static status_t publish(bool allowIsolated = false) {
sp<IServiceManager> sm(defaultServiceManager());
- return sm->addService(String16(SERVICE::getServiceName()), new SERVICE(), allowIsolated);
+ return sm->addService(
+ String16(SERVICE::getServiceName()),
+ new SERVICE(), allowIsolated);
}
static void publishAndJoinThreadPool(bool allowIsolated = false) {
sp<IServiceManager> sm(defaultServiceManager());
}
static void publishAndJoinThreadPool(bool allowIsolated = false) {
sp<IServiceManager> sm(defaultServiceManager());
- sm->addService(String16(SERVICE::getServiceName()), new SERVICE(), allowIsolated);
+ sm->addService(
+ String16(SERVICE::getServiceName()),
+ new SERVICE(), allowIsolated);
ProcessState::self()->startThreadPool();
ProcessState::self()->startThreadPool();
+ ProcessState::self()->giveThreadPoolName();
IPCThreadState::self()->joinThreadPool();
}
IPCThreadState::self()->joinThreadPool();
}
void spawnPooledThread(bool isMain);
status_t setThreadPoolMaxThreadCount(size_t maxThreads);
void spawnPooledThread(bool isMain);
status_t setThreadPoolMaxThreadCount(size_t maxThreads);
+ void giveThreadPoolName();
private:
friend class IPCThreadState;
private:
friend class IPCThreadState;
ProcessState(const ProcessState& o);
ProcessState& operator=(const ProcessState& o);
ProcessState(const ProcessState& o);
ProcessState& operator=(const ProcessState& o);
+ String8 makeBinderThreadName();
struct handle_entry {
IBinder* binder;
struct handle_entry {
IBinder* binder;
size_t threadStackSize,
android_thread_id_t *threadId);
size_t threadStackSize,
android_thread_id_t *threadId);
+// set the same of the running thread
+extern void androidSetThreadName(const char* name);
+
// Used by the Java Runtime to control how threads are created, so that
// they can be proper and lovely Java threads.
typedef int (*android_create_thread_fn)(android_thread_func_t entryFunction,
// Used by the Java Runtime to control how threads are created, so that
// they can be proper and lovely Java threads.
typedef int (*android_create_thread_fn)(android_thread_func_t entryFunction,
+String8 ProcessState::makeBinderThreadName() {
+ int32_t s = android_atomic_add(1, &mThreadPoolSeq);
+ String8 name;
+ name.appendFormat("Binder_%X", s);
+ return name;
+}
+
void ProcessState::spawnPooledThread(bool isMain)
{
if (mThreadPoolStarted) {
void ProcessState::spawnPooledThread(bool isMain)
{
if (mThreadPoolStarted) {
- int32_t s = android_atomic_add(1, &mThreadPoolSeq);
- char buf[16];
- snprintf(buf, sizeof(buf), "Binder_%X", s);
- ALOGV("Spawning new pooled thread, name=%s\n", buf);
+ String8 name = makeBinderThreadName();
+ ALOGV("Spawning new pooled thread, name=%s\n", name.string());
sp<Thread> t = new PoolThread(isMain);
sp<Thread> t = new PoolThread(isMain);
+void ProcessState::giveThreadPoolName() {
+ androidSetThreadName( makeBinderThreadName().string() );
+}
+
static int open_driver()
{
int fd = open("/dev/binder", O_RDWR);
static int open_driver()
{
int fd = open("/dev/binder", O_RDWR);
-#if defined(HAVE_PRCTL)
- // Mac OS doesn't have this, and we build libutil for the host too
- int hasAt = 0;
- int hasDot = 0;
- char *s = name;
- while (*s) {
- if (*s == '.') hasDot = 1;
- else if (*s == '@') hasAt = 1;
- s++;
- }
- int len = s - name;
- if (len < 15 || hasAt || !hasDot) {
- s = name;
- } else {
- s = name + len - 15;
- }
- prctl(PR_SET_NAME, (unsigned long) s, 0, 0, 0);
-#endif
+ androidSetThreadName(name);
free(name);
}
return f(u);
}
};
free(name);
}
return f(u);
}
};
+void androidSetThreadName(const char* name) {
+#if defined(HAVE_PRCTL)
+ // Mac OS doesn't have this, and we build libutil for the host too
+ int hasAt = 0;
+ int hasDot = 0;
+ const char *s = name;
+ while (*s) {
+ if (*s == '.') hasDot = 1;
+ else if (*s == '@') hasAt = 1;
+ s++;
+ }
+ int len = s - name;
+ if (len < 15 || hasAt || !hasDot) {
+ s = name;
+ } else {
+ s = name + len - 15;
+ }
+ prctl(PR_SET_NAME, (unsigned long) s, 0, 0, 0);
+#endif
+}
+
int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
void *userData,
const char* threadName,
int androidCreateRawThreadEtc(android_thread_func_t entryFunction,
void *userData,
const char* threadName,