From 9899b12780f779dad707fdac0b042eff4bf70f1a Mon Sep 17 00:00:00 2001 From: sdong Date: Thu, 29 May 2014 10:57:22 -0700 Subject: [PATCH] ThreadID printed when Thread terminating in the same format as posix_logger Summary: https://github.com/facebook/rocksdb/commit/220132b65ec17abb037d3e79d5abf6ca8d797b96 correctly fixed the issue of thread ID printing when terminating a thread. Nothing wrong with it. This diff prints the ID in the same way as in PosixLogger::logv() so that users can be more easily to correlates them. Test Plan: run env_test and make sure it prints correctly. Reviewers: igor, haobo, ljin, yhchiang Reviewed By: yhchiang Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D18819 --- util/env_posix.cc | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/util/env_posix.cc b/util/env_posix.cc index 1f8c3bcf2..267958606 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -94,17 +94,6 @@ static Status IOError(const std::string& context, int err_number) { return Status::IOError(context, strerror(err_number)); } -// TODO(sdong): temp logging. Need to help debugging. Remove it when -// the feature is proved to be stable. -inline void PrintThreadInfo(size_t thread_id, pthread_t id) { - unsigned char* ptc = (unsigned char*)(void*)(&id); - fprintf(stdout, "Bg thread %zu terminates 0x", thread_id); - for (size_t i = 0; i < sizeof(id); i++) { - fprintf(stdout, "%02x", (unsigned)(ptc[i])); - } - fprintf(stdout, "\n"); -} - #ifdef NDEBUG // empty in release build #define TEST_KILL_RANDOM(rocksdb_kill_odds) @@ -1293,13 +1282,17 @@ class PosixEnv : public Env { return Status::OK(); } - static uint64_t gettid() { - pthread_t tid = pthread_self(); + static uint64_t gettid(pthread_t tid) { uint64_t thread_id = 0; memcpy(&thread_id, &tid, std::min(sizeof(thread_id), sizeof(tid))); return thread_id; } + static uint64_t gettid() { + pthread_t tid = pthread_self(); + return gettid(tid); + } + virtual Status NewLogger(const std::string& fname, shared_ptr* result) { FILE* f = fopen(fname.c_str(), "w"); @@ -1525,7 +1518,8 @@ class PosixEnv : public Env { PthreadCall("unlock", pthread_mutex_unlock(&mu_)); // TODO(sdong): temp logging. Need to help debugging. Remove it when // the feature is proved to be stable. - PrintThreadInfo(thread_id, terminating_thread); + fprintf(stdout, "Bg thread %zu terminates %llx\n", thread_id, + static_cast(gettid())); break; } void (*function)(void*) = queue_.front().function;