|
|
@ -10,26 +10,22 @@ |
|
|
|
|
|
|
|
|
|
|
|
namespace rocksdb { |
|
|
|
namespace rocksdb { |
|
|
|
namespace { |
|
|
|
namespace { |
|
|
|
bool ShouldReportToStats(Env* env, Statistics* stats) { |
|
|
|
Statistics* stats_for_report(Env* env, Statistics* stats) { |
|
|
|
return env != nullptr && stats != nullptr && |
|
|
|
if (env != nullptr && stats != nullptr && |
|
|
|
stats->stats_level_ > kExceptTimeForMutex; |
|
|
|
stats->stats_level_ > kExceptTimeForMutex) { |
|
|
|
|
|
|
|
return stats; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return nullptr; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} // namespace
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
|
|
void InstrumentedMutex::Lock() { |
|
|
|
void InstrumentedMutex::Lock() { |
|
|
|
PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_mutex_lock_nanos, |
|
|
|
PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD( |
|
|
|
stats_code_ == DB_MUTEX_WAIT_MICROS); |
|
|
|
db_mutex_lock_nanos, stats_code_ == DB_MUTEX_WAIT_MICROS, |
|
|
|
uint64_t wait_time_micros = 0; |
|
|
|
stats_for_report(env_, stats_), stats_code_); |
|
|
|
if (ShouldReportToStats(env_, stats_)) { |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StopWatch sw(env_, nullptr, 0, &wait_time_micros); |
|
|
|
|
|
|
|
LockInternal(); |
|
|
|
LockInternal(); |
|
|
|
} |
|
|
|
} |
|
|
|
RecordTick(stats_, stats_code_, wait_time_micros); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
LockInternal(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InstrumentedMutex::LockInternal() { |
|
|
|
void InstrumentedMutex::LockInternal() { |
|
|
|
#ifndef NDEBUG |
|
|
|
#ifndef NDEBUG |
|
|
@ -39,19 +35,11 @@ void InstrumentedMutex::LockInternal() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void InstrumentedCondVar::Wait() { |
|
|
|
void InstrumentedCondVar::Wait() { |
|
|
|
PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_condition_wait_nanos, |
|
|
|
PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD( |
|
|
|
stats_code_ == DB_MUTEX_WAIT_MICROS); |
|
|
|
db_condition_wait_nanos, stats_code_ == DB_MUTEX_WAIT_MICROS, |
|
|
|
uint64_t wait_time_micros = 0; |
|
|
|
stats_for_report(env_, stats_), stats_code_); |
|
|
|
if (ShouldReportToStats(env_, stats_)) { |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StopWatch sw(env_, nullptr, 0, &wait_time_micros); |
|
|
|
|
|
|
|
WaitInternal(); |
|
|
|
WaitInternal(); |
|
|
|
} |
|
|
|
} |
|
|
|
RecordTick(stats_, stats_code_, wait_time_micros); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
WaitInternal(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void InstrumentedCondVar::WaitInternal() { |
|
|
|
void InstrumentedCondVar::WaitInternal() { |
|
|
|
#ifndef NDEBUG |
|
|
|
#ifndef NDEBUG |
|
|
@ -61,20 +49,10 @@ void InstrumentedCondVar::WaitInternal() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool InstrumentedCondVar::TimedWait(uint64_t abs_time_us) { |
|
|
|
bool InstrumentedCondVar::TimedWait(uint64_t abs_time_us) { |
|
|
|
PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD(db_condition_wait_nanos, |
|
|
|
PERF_CONDITIONAL_TIMER_FOR_MUTEX_GUARD( |
|
|
|
stats_code_ == DB_MUTEX_WAIT_MICROS); |
|
|
|
db_condition_wait_nanos, stats_code_ == DB_MUTEX_WAIT_MICROS, |
|
|
|
uint64_t wait_time_micros = 0; |
|
|
|
stats_for_report(env_, stats_), stats_code_); |
|
|
|
bool result = false; |
|
|
|
return TimedWaitInternal(abs_time_us); |
|
|
|
if (ShouldReportToStats(env_, stats_)) { |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
StopWatch sw(env_, nullptr, 0, &wait_time_micros); |
|
|
|
|
|
|
|
result = TimedWaitInternal(abs_time_us); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
RecordTick(stats_, stats_code_, wait_time_micros); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
result = TimedWaitInternal(abs_time_us); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return result; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool InstrumentedCondVar::TimedWaitInternal(uint64_t abs_time_us) { |
|
|
|
bool InstrumentedCondVar::TimedWaitInternal(uint64_t abs_time_us) { |
|
|
|