From 4c81383628db46d35b674000a3668b5a9a2498a6 Mon Sep 17 00:00:00 2001 From: lovro Date: Tue, 26 Nov 2013 18:00:43 -0800 Subject: [PATCH] Set background thread name with pthread_setname_np() Summary: Makes it easier to monitor performance with top Test Plan: ./manual_compaction_test with `top -H` running. Previously was two `manual_compacti`, now one shows `rocksdb:bg0`. Reviewers: igor, dhruba Reviewed By: igor CC: leveldb Differential Revision: https://reviews.facebook.net/D14367 --- util/env_posix.cc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/util/env_posix.cc b/util/env_posix.cc index 356008225..16c3d1c61 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -1396,6 +1396,15 @@ class PosixEnv : public Env { fprintf(stdout, "Created bg thread 0x%lx\n", (unsigned long)t); + + // Set the thread name to aid debugging +#if defined(_GNU_SOURCE) && defined(__GLIBC_PREREQ) && (__GLIBC_PREREQ(2, 12)) + char name_buf[16]; + snprintf(name_buf, sizeof name_buf, "rocksdb:bg%zu", bgthreads_.size()); + name_buf[sizeof name_buf - 1] = '\0'; + pthread_setname_np(t, name_buf); +#endif + bgthreads_.push_back(t); }