ThreadID printed when Thread terminating in the same format as posix_logger

Summary: 220132b65e 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
main
sdong 11 years ago
parent ab3e566699
commit 9899b12780
  1. 22
      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)); 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 #ifdef NDEBUG
// empty in release build // empty in release build
#define TEST_KILL_RANDOM(rocksdb_kill_odds) #define TEST_KILL_RANDOM(rocksdb_kill_odds)
@ -1293,13 +1282,17 @@ class PosixEnv : public Env {
return Status::OK(); return Status::OK();
} }
static uint64_t gettid() { static uint64_t gettid(pthread_t tid) {
pthread_t tid = pthread_self();
uint64_t thread_id = 0; uint64_t thread_id = 0;
memcpy(&thread_id, &tid, std::min(sizeof(thread_id), sizeof(tid))); memcpy(&thread_id, &tid, std::min(sizeof(thread_id), sizeof(tid)));
return thread_id; return thread_id;
} }
static uint64_t gettid() {
pthread_t tid = pthread_self();
return gettid(tid);
}
virtual Status NewLogger(const std::string& fname, virtual Status NewLogger(const std::string& fname,
shared_ptr<Logger>* result) { shared_ptr<Logger>* result) {
FILE* f = fopen(fname.c_str(), "w"); FILE* f = fopen(fname.c_str(), "w");
@ -1525,7 +1518,8 @@ class PosixEnv : public Env {
PthreadCall("unlock", pthread_mutex_unlock(&mu_)); PthreadCall("unlock", pthread_mutex_unlock(&mu_));
// TODO(sdong): temp logging. Need to help debugging. Remove it when // TODO(sdong): temp logging. Need to help debugging. Remove it when
// the feature is proved to be stable. // the feature is proved to be stable.
PrintThreadInfo(thread_id, terminating_thread); fprintf(stdout, "Bg thread %zu terminates %llx\n", thread_id,
static_cast<long long unsigned int>(gettid()));
break; break;
} }
void (*function)(void*) = queue_.front().function; void (*function)(void*) = queue_.front().function;

Loading…
Cancel
Save