Bug 758837: Use a smarter way to reduce the thread names passed to
authorwtc%google.com
Tue, 19 Jun 2012 21:22:53 +0000
changeset 4401 245bb09ea7f5cf4eb74e5b29250157479aa960e9
parent 4400 cf97502a1e9345b419156a3e13ee6cc0d4da5dd0
child 4402 5c3a2654393f89f81312d8e78bbb93d4bc3aa477
push idunknown
push userunknown
push dateunknown
bugs758837
Bug 758837: Use a smarter way to reduce the thread names passed to PR_SetCurrentThreadName to 16 characters long. Elide the middle part of a long name with "..". The patch is contributed by Honza Bambas <honzab.moz@firemni.cz>. r=wtc.
pr/src/pthreads/ptthread.c
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -1652,19 +1652,27 @@ PR_IMPLEMENT(PRStatus) PR_SetCurrentThre
 #endif
 
     *(void**)(&dynamic_pthread_setname_np) =
         dlsym(RTLD_DEFAULT, "pthread_setname_np");
     if (!dynamic_pthread_setname_np)
         return PR_SUCCESS;
 
 #define SETNAME_LENGTH_CONSTRAINT 15
+#define SETNAME_FRAGMENT1_LENGTH (SETNAME_LENGTH_CONSTRAINT >> 1)
+#define SETNAME_FRAGMENT2_LENGTH \
+    (SETNAME_LENGTH_CONSTRAINT - SETNAME_FRAGMENT1_LENGTH - 2)
     char name_dup[SETNAME_LENGTH_CONSTRAINT + 1];
     if (nameLen > SETNAME_LENGTH_CONSTRAINT + 1) {
-        memcpy(name_dup, name, SETNAME_LENGTH_CONSTRAINT);
+        memcpy(name_dup, name, SETNAME_FRAGMENT1_LENGTH);
+        name_dup[SETNAME_FRAGMENT1_LENGTH] = '.';
+        name_dup[SETNAME_FRAGMENT1_LENGTH + 1] = '.';
+        memcpy(name_dup + SETNAME_FRAGMENT1_LENGTH + 2,
+               name + nameLen - SETNAME_FRAGMENT2_LENGTH,
+               SETNAME_FRAGMENT2_LENGTH);
         name_dup[SETNAME_LENGTH_CONSTRAINT] = '\0';
         name = name_dup;
     }
 
 #if defined(DARWIN)
     result = dynamic_pthread_setname_np(name);
 #else
     result = dynamic_pthread_setname_np(thread->id, name);