[ovs-dev] [PATCH] util: Set thread name via pthreads in set_subprogram_name().
Andy Zhou
azhou at nicira.com
Wed Jul 24 18:20:00 UTC 2013
Acked-by: Andy Zhou <azhou at nicira.com>
BTW, I tested the pthread_setname_np() function on Ubuntu 12.04. It works
as advertised.
On Fri, Jul 12, 2013 at 2:28 PM, Ben Pfaff <blp at nicira.com> wrote:
> This makes "top" and "ps" output more readable on FreeBSD at least, and
> the names are also visible in debuggers.
>
> Suggested-by: Ed Maste <emaste at freebsd.org>
> Signed-off-by: Ben Pfaff <blp at nicira.com>
> ---
> One reason that I didn't know about these functions was that my main
> dev box runs a distro so old that its glibc doesn't even have this
> function. That means that this patch is effectively untested.
>
> configure.ac | 3 ++-
> lib/util.c | 8 +++++++-
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index e4f9991..078ff4f 100644
> --- a/configure.ac
> +++ b/configure.ac
> @@ -64,7 +64,8 @@ AC_CHECK_DECLS([sys_siglist], [], [], [[#include
> <signal.h>]])
> AC_CHECK_MEMBERS([struct stat.st_mtim.tv_nsec, struct stat.st_mtimensec],
> [], [], [[#include <sys/stat.h>]])
> AC_CHECK_MEMBERS([struct ifreq.ifr_flagshigh], [], [], [[#include
> <net/if.h>]])
> -AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r])
> +AC_CHECK_FUNCS([mlockall strnlen getloadavg statvfs getmntent_r \
> + pthread_setname_np pthread_set_name_np])
> AC_CHECK_HEADERS([mntent.h sys/statvfs.h linux/types.h linux/if_ether.h
> stdatomic.h])
> AC_CHECK_HEADERS([net/if_mib.h], [], [], [[#include <sys/types.h>
> #include <net/if.h>]])
> diff --git a/lib/util.c b/lib/util.c
> index c69d7d1..6a72107 100644
> --- a/lib/util.c
> +++ b/lib/util.c
> @@ -395,11 +395,17 @@ get_subprogram_name(void)
> }
>
> /* Sets 'name' as the name of the currently running thread or process.
> (This
> - * appears in log messages.) */
> + * appears in log messages and may also be visible in system process
> listings
> + * and debuggers.) */
> void
> set_subprogram_name(const char *name)
> {
> free(subprogram_name_set(xstrdup(name)));
> +#if HAVE_PTHREAD_SETNAME_NP
> + pthread_setname_np(pthread_self(), name);
> +#elif HAVE_PTHREAD_SET_NAME_NP
> + pthread_set_name_np(pthread_self(), name);
> +#endif
> }
>
> /* Returns a pointer to a string describing the program version. The
> --
> 1.7.2.5
>
> _______________________________________________
> dev mailing list
> dev at openvswitch.org
> http://openvswitch.org/mailman/listinfo/dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.openvswitch.org/pipermail/ovs-dev/attachments/20130724/509e80b7/attachment-0003.html>
More information about the dev
mailing list