mirror of
https://github.com/facebook/rocksdb.git
synced 2024-11-29 18:33:58 +00:00
248c063ba1
Summary: Report elapsed time of a thread operation in micros in ThreadStatus instead of start time of a thread operation in seconds since the Epoch, 1970-01-01 00:00:00 (UTC). Test Plan: ./db_bench --benchmarks=fillrandom --num=100000 --threads=40 \ --max_background_compactions=10 --max_background_flushes=3 \ --thread_status_per_interval=1000 --key_size=16 --value_size=1000 \ --num_column_families=10 Sample Output: ThreadID ThreadType cfName Operation ElapsedTime Stage State 140667724562496 High Pri column_family_name_000002 Flush 772.419 ms FlushJob::WriteLevel0Table 140667728756800 High Pri default Flush 617.845 ms FlushJob::WriteLevel0Table 140667732951104 High Pri column_family_name_000005 Flush 772.078 ms FlushJob::WriteLevel0Table 140667875557440 Low Pri column_family_name_000008 Compaction 1409.216 ms CompactionJob::Install 140667737145408 Low Pri 140667749728320 Low Pri 140667816837184 Low Pri column_family_name_000007 Compaction 1071.815 ms CompactionJob::ProcessKeyValueCompaction 140667787477056 Low Pri column_family_name_000009 Compaction 772.516 ms CompactionJob::ProcessKeyValueCompaction 140667741339712 Low Pri 140667758116928 Low Pri column_family_name_000004 Compaction 620.739 ms CompactionJob::ProcessKeyValueCompaction 140667753922624 Low Pri 140667842003008 Low Pri column_family_name_000006 Compaction 1260.079 ms CompactionJob::ProcessKeyValueCompaction 140667745534016 Low Pri Reviewers: sdong, igor, rven Subscribers: dhruba, leveldb Differential Revision: https://reviews.facebook.net/D35769
182 lines
5.4 KiB
C++
182 lines
5.4 KiB
C++
// Copyright (c) 2013, Facebook, Inc. All rights reserved.
|
|
// This source code is licensed under the BSD-style license found in the
|
|
// LICENSE file in the root directory of this source tree. An additional grant
|
|
// of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
#include "rocksdb/env.h"
|
|
#include "util/thread_status_updater.h"
|
|
#include "util/thread_status_util.h"
|
|
|
|
namespace rocksdb {
|
|
|
|
|
|
#if ROCKSDB_USING_THREAD_STATUS
|
|
__thread ThreadStatusUpdater*
|
|
ThreadStatusUtil::thread_updater_local_cache_ = nullptr;
|
|
__thread bool ThreadStatusUtil::thread_updater_initialized_ = false;
|
|
|
|
void ThreadStatusUtil::SetThreadType(
|
|
const Env* env, ThreadStatus::ThreadType thread_type) {
|
|
if (!MaybeInitThreadLocalUpdater(env)) {
|
|
return;
|
|
}
|
|
assert(thread_updater_local_cache_);
|
|
thread_updater_local_cache_->SetThreadType(thread_type);
|
|
}
|
|
|
|
void ThreadStatusUtil::UnregisterThread() {
|
|
thread_updater_initialized_ = false;
|
|
if (thread_updater_local_cache_ != nullptr) {
|
|
thread_updater_local_cache_->UnregisterThread();
|
|
thread_updater_local_cache_ = nullptr;
|
|
}
|
|
}
|
|
|
|
void ThreadStatusUtil::SetColumnFamily(const ColumnFamilyData* cfd) {
|
|
if (!MaybeInitThreadLocalUpdater(cfd->ioptions()->env)) {
|
|
return;
|
|
}
|
|
assert(thread_updater_local_cache_);
|
|
if (cfd != nullptr && cfd->options()->enable_thread_tracking) {
|
|
thread_updater_local_cache_->SetColumnFamilyInfoKey(cfd);
|
|
} else {
|
|
// When cfd == nullptr or enable_thread_tracking == false, we set
|
|
// ColumnFamilyInfoKey to nullptr, which makes SetThreadOperation
|
|
// and SetThreadState become no-op.
|
|
thread_updater_local_cache_->SetColumnFamilyInfoKey(nullptr);
|
|
}
|
|
}
|
|
|
|
void ThreadStatusUtil::SetThreadOperation(ThreadStatus::OperationType op) {
|
|
if (thread_updater_local_cache_ == nullptr) {
|
|
// thread_updater_local_cache_ must be set in SetColumnFamily
|
|
// or other ThreadStatusUtil functions.
|
|
return;
|
|
}
|
|
|
|
if (op != ThreadStatus::OP_UNKNOWN) {
|
|
uint64_t current_time = Env::Default()->NowMicros();
|
|
thread_updater_local_cache_->SetOperationStartTime(current_time);
|
|
} else {
|
|
// TDOO(yhchiang): we could report the time when we set operation to
|
|
// OP_UNKNOWN once the whole instrumentation has been done.
|
|
thread_updater_local_cache_->SetOperationStartTime(0);
|
|
}
|
|
thread_updater_local_cache_->SetThreadOperation(op);
|
|
}
|
|
|
|
ThreadStatus::OperationStage ThreadStatusUtil::SetThreadOperationStage(
|
|
ThreadStatus::OperationStage stage) {
|
|
if (thread_updater_local_cache_ == nullptr) {
|
|
// thread_updater_local_cache_ must be set in SetColumnFamily
|
|
// or other ThreadStatusUtil functions.
|
|
return ThreadStatus::STAGE_UNKNOWN;
|
|
}
|
|
|
|
return thread_updater_local_cache_->SetThreadOperationStage(stage);
|
|
}
|
|
|
|
void ThreadStatusUtil::SetThreadState(ThreadStatus::StateType state) {
|
|
if (thread_updater_local_cache_ == nullptr) {
|
|
// thread_updater_local_cache_ must be set in SetColumnFamily
|
|
// or other ThreadStatusUtil functions.
|
|
return;
|
|
}
|
|
|
|
thread_updater_local_cache_->SetThreadState(state);
|
|
}
|
|
|
|
void ThreadStatusUtil::ResetThreadStatus() {
|
|
if (thread_updater_local_cache_ == nullptr) {
|
|
return;
|
|
}
|
|
thread_updater_local_cache_->ResetThreadStatus();
|
|
}
|
|
|
|
void ThreadStatusUtil::NewColumnFamilyInfo(
|
|
const DB* db, const ColumnFamilyData* cfd) {
|
|
if (!MaybeInitThreadLocalUpdater(cfd->ioptions()->env)) {
|
|
return;
|
|
}
|
|
assert(thread_updater_local_cache_);
|
|
if (thread_updater_local_cache_) {
|
|
thread_updater_local_cache_->NewColumnFamilyInfo(
|
|
db, db->GetName(), cfd, cfd->GetName());
|
|
}
|
|
}
|
|
|
|
void ThreadStatusUtil::EraseColumnFamilyInfo(
|
|
const ColumnFamilyData* cfd) {
|
|
if (thread_updater_local_cache_ == nullptr) {
|
|
return;
|
|
}
|
|
thread_updater_local_cache_->EraseColumnFamilyInfo(cfd);
|
|
}
|
|
|
|
void ThreadStatusUtil::EraseDatabaseInfo(const DB* db) {
|
|
if (thread_updater_local_cache_ == nullptr) {
|
|
return;
|
|
}
|
|
thread_updater_local_cache_->EraseDatabaseInfo(db);
|
|
}
|
|
|
|
bool ThreadStatusUtil::MaybeInitThreadLocalUpdater(const Env* env) {
|
|
if (!thread_updater_initialized_ && env != nullptr) {
|
|
thread_updater_initialized_ = true;
|
|
thread_updater_local_cache_ = env->GetThreadStatusUpdater();
|
|
}
|
|
return (thread_updater_local_cache_ != nullptr);
|
|
}
|
|
|
|
AutoThreadOperationStageUpdater::AutoThreadOperationStageUpdater(
|
|
ThreadStatus::OperationStage stage) {
|
|
prev_stage_ = ThreadStatusUtil::SetThreadOperationStage(stage);
|
|
}
|
|
|
|
AutoThreadOperationStageUpdater::~AutoThreadOperationStageUpdater() {
|
|
ThreadStatusUtil::SetThreadOperationStage(prev_stage_);
|
|
}
|
|
|
|
#else
|
|
|
|
ThreadStatusUpdater* ThreadStatusUtil::thread_updater_local_cache_ = nullptr;
|
|
bool ThreadStatusUtil::thread_updater_initialized_ = false;
|
|
|
|
bool ThreadStatusUtil::MaybeInitThreadLocalUpdater(const Env* env) {
|
|
return false;
|
|
}
|
|
|
|
void ThreadStatusUtil::SetColumnFamily(const ColumnFamilyData* cfd) {
|
|
}
|
|
|
|
void ThreadStatusUtil::SetThreadOperation(ThreadStatus::OperationType op) {
|
|
}
|
|
|
|
void ThreadStatusUtil::SetThreadState(ThreadStatus::StateType state) {
|
|
}
|
|
|
|
void ThreadStatusUtil::NewColumnFamilyInfo(
|
|
const DB* db, const ColumnFamilyData* cfd) {
|
|
}
|
|
|
|
void ThreadStatusUtil::EraseColumnFamilyInfo(
|
|
const ColumnFamilyData* cfd) {
|
|
}
|
|
|
|
void ThreadStatusUtil::EraseDatabaseInfo(const DB* db) {
|
|
}
|
|
|
|
void ThreadStatusUtil::ResetThreadStatus() {
|
|
}
|
|
|
|
AutoThreadOperationStageUpdater::AutoThreadOperationStageUpdater(
|
|
ThreadStatus::OperationStage stage) {
|
|
}
|
|
|
|
AutoThreadOperationStageUpdater::~AutoThreadOperationStageUpdater() {
|
|
}
|
|
|
|
#endif // ROCKSDB_USING_THREAD_STATUS
|
|
|
|
} // namespace rocksdb
|