diff options
| author | Raghavendra Talur <rtalur@redhat.com> | 2017-07-18 11:36:19 +0530 | 
|---|---|---|
| committer | Jeff Darcy <jeff@pl.atyp.us> | 2017-07-19 14:16:19 +0000 | 
| commit | 33db9aff1deaa028f30516e49fdb1e8d6e31bb73 (patch) | |
| tree | 36d88c93e1e83e4253b154199b0b12531d0edb39 /libglusterfs/src/common-utils.c | |
| parent | 5ccf0922208c368873120e235be0fd2975a589c1 (diff) | |
libglusterfs: Name threads on creation
Set names to threads on creation for easier
debugging.
Output of top -H -p <PID-OF-GLUSTERFSD>
Before:
19773 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19774 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19775 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19776 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19777 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19778 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19779 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19780 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19781 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19782 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19783 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19784 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19785 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.01 glusterfsd
19786 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.01 glusterfsd
19787 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.01 glusterfsd
19789 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19790 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
25178 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
 5398 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
 7881 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
After:
19773 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19774 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glustertimer
19775 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterfsd
19776 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glustermemsweep
19777 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glustersproc0
19778 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glustersproc1
19779 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterepoll0
19780 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusteridxwrker
19781 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusteriotwr0
19782 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterbrssign
19783 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterbrswrker
19784 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterclogecon
19785 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.01 glusterclogd0
19786 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.01 glusterclogd1
19787 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.01 glusterclogd2
19789 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterposixjan
19790 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterposixfsy
25178 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterepoll1
 5398 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterepoll2
 7881 root      20   0 1301.3m  12.6m   8.4m S  0.0  0.1   0:00.00 glusterposixhc
Change-Id: Id5f333755c1ba168a2ffaa4fce6e71c375e10703
BUG: 1254002
Updates: #271
Signed-off-by: Raghavendra Talur <rtalur@redhat.com>
Reviewed-on: https://review.gluster.org/11926
Reviewed-by: Prashanth Pai <ppai@redhat.com>
Smoke: Gluster Build System <jenkins@build.gluster.org>
Reviewed-by: Niels de Vos <ndevos@redhat.com>
CentOS-regression: Gluster Build System <jenkins@build.gluster.org>
Diffstat (limited to 'libglusterfs/src/common-utils.c')
| -rw-r--r-- | libglusterfs/src/common-utils.c | 27 | 
1 files changed, 24 insertions, 3 deletions
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c index 1adb0bd5a81..ec1d5c4823c 100644 --- a/libglusterfs/src/common-utils.c +++ b/libglusterfs/src/common-utils.c @@ -3725,10 +3725,15 @@ gf_thread_cleanup_xint (pthread_t thread)  int  gf_thread_create (pthread_t *thread, const pthread_attr_t *attr, -                  void *(*start_routine)(void *), void *arg) +                  void *(*start_routine)(void *), void *arg, const char *name)  {          sigset_t set, old;          int ret; +        char thread_name[GF_THREAD_NAMEMAX+GF_THREAD_NAME_PREFIX_LEN] = {0,}; +        /* Max name on Linux is 16 and on NetBSD is 32 +         * All Gluster threads have a set prefix of gluster and hence the limit +         * of 9 on GF_THREAD_NAMEMAX including the null character. +         */          sigemptyset (&old);          sigfillset (&set); @@ -3742,6 +3747,21 @@ gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,          pthread_sigmask (SIG_BLOCK, &set, &old);          ret = pthread_create (thread, attr, start_routine, arg); +        snprintf (thread_name, sizeof(thread_name), "%s%s", +                  GF_THREAD_NAME_PREFIX, name); + +        if (0 == ret && name) { +                #ifdef GF_LINUX_HOST_OS +                        pthread_setname_np(*thread, thread_name); +                #elif defined(__NetBSD__) +                        pthread_setname_np(*thread, thread_name, NULL); +                #else +                        gf_msg (THIS->name, GF_LOG_WARNING, 0, +                                LG_MSG_PTHREAD_NAMING_FAILED, +                                "Thread names not implemented on this ", +                                "platform"); +                #endif +        }          pthread_sigmask (SIG_SETMASK, &old, NULL); @@ -3750,7 +3770,8 @@ gf_thread_create (pthread_t *thread, const pthread_attr_t *attr,  int  gf_thread_create_detached (pthread_t *thread, -                         void *(*start_routine)(void *), void *arg) +                         void *(*start_routine)(void *), void *arg, +                         const char *name)  {          pthread_attr_t attr;          int ret = -1; @@ -3765,7 +3786,7 @@ gf_thread_create_detached (pthread_t *thread,          pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED); -        ret = gf_thread_create (thread, &attr, start_routine, arg); +        ret = gf_thread_create (thread, &attr, start_routine, arg, name);          if (ret) {                  gf_msg (THIS->name, GF_LOG_ERROR, ret,                          LG_MSG_PTHREAD_FAILED,  | 
