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
main
lovro 11 years ago
parent 4ee6e6c9d6
commit 4c81383628
  1. 9
      util/env_posix.cc

@ -1396,6 +1396,15 @@ class PosixEnv : public Env {
fprintf(stdout, fprintf(stdout,
"Created bg thread 0x%lx\n", "Created bg thread 0x%lx\n",
(unsigned long)t); (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); bgthreads_.push_back(t);
} }

Loading…
Cancel
Save