clang format files under monitoring/ (#10857)

Summary:
Ran find . -iname '*.h' -o -iname '*.cc' | xargs clang-format -i under monitoring/.

Pull Request resolved: https://github.com/facebook/rocksdb/pull/10857

Test Plan: existing CI.

Reviewed By: siying

Differential Revision: D40652600

Pulled By: cbi42

fbshipit-source-id: 2af2467c33995b093e07b7512b8c32ed4144968e
main
changyubi 2 years ago committed by Facebook GitHub Bot
parent aca00006bf
commit de34e7196f
  1. 48
      monitoring/histogram.cc
  2. 25
      monitoring/histogram.h
  3. 24
      monitoring/histogram_test.cc
  4. 46
      monitoring/histogram_windowing.cc
  5. 10
      monitoring/histogram_windowing.h
  6. 1
      monitoring/in_memory_stats_history.cc
  7. 16
      monitoring/instrumented_mutex.h
  8. 5
      monitoring/iostats_context.cc
  9. 1
      monitoring/iostats_context_test.cc
  10. 12
      monitoring/perf_context.cc
  11. 5
      monitoring/perf_level.cc
  12. 2
      monitoring/perf_level_imp.h
  13. 4
      monitoring/perf_step_timer.h
  14. 1
      monitoring/persistent_stats_history.cc
  15. 14
      monitoring/statistics.h
  16. 32
      monitoring/thread_status_updater.h
  17. 17
      monitoring/thread_status_util.h
  18. 4
      monitoring/thread_status_util_debug.cc

@ -52,11 +52,10 @@ size_t HistogramBucketMapper::IndexForValue(const uint64_t value) const {
} }
namespace { namespace {
const HistogramBucketMapper bucketMapper; const HistogramBucketMapper bucketMapper;
} }
HistogramStat::HistogramStat() HistogramStat::HistogramStat() : num_buckets_(bucketMapper.BucketCount()) {
: num_buckets_(bucketMapper.BucketCount()) {
assert(num_buckets_ == sizeof(buckets_) / sizeof(*buckets_)); assert(num_buckets_ == sizeof(buckets_) / sizeof(*buckets_));
Clear(); Clear();
} }
@ -109,12 +108,14 @@ void HistogramStat::Merge(const HistogramStat& other) {
uint64_t old_min = min(); uint64_t old_min = min();
uint64_t other_min = other.min(); uint64_t other_min = other.min();
while (other_min < old_min && while (other_min < old_min &&
!min_.compare_exchange_weak(old_min, other_min)) {} !min_.compare_exchange_weak(old_min, other_min)) {
}
uint64_t old_max = max(); uint64_t old_max = max();
uint64_t other_max = other.max(); uint64_t other_max = other.max();
while (other_max > old_max && while (other_max > old_max &&
!max_.compare_exchange_weak(old_max, other_max)) {} !max_.compare_exchange_weak(old_max, other_max)) {
}
num_.fetch_add(other.num(), std::memory_order_relaxed); num_.fetch_add(other.num(), std::memory_order_relaxed);
sum_.fetch_add(other.sum(), std::memory_order_relaxed); sum_.fetch_add(other.sum(), std::memory_order_relaxed);
@ -124,9 +125,7 @@ void HistogramStat::Merge(const HistogramStat& other) {
} }
} }
double HistogramStat::Median() const { double HistogramStat::Median() const { return Percentile(50.0); }
return Percentile(50.0);
}
double HistogramStat::Percentile(double p) const { double HistogramStat::Percentile(double p) const {
double threshold = num() * (p / 100.0); double threshold = num() * (p / 100.0);
@ -136,7 +135,7 @@ double HistogramStat::Percentile(double p) const {
cumulative_sum += bucket_value; cumulative_sum += bucket_value;
if (cumulative_sum >= threshold) { if (cumulative_sum >= threshold) {
// Scale linearly within this bucket // Scale linearly within this bucket
uint64_t left_point = (b == 0) ? 0 : bucketMapper.BucketLimit(b-1); uint64_t left_point = (b == 0) ? 0 : bucketMapper.BucketLimit(b - 1);
uint64_t right_point = bucketMapper.BucketLimit(b); uint64_t right_point = bucketMapper.BucketLimit(b);
uint64_t left_sum = cumulative_sum - bucket_value; uint64_t left_sum = cumulative_sum - bucket_value;
uint64_t right_sum = cumulative_sum; uint64_t right_sum = cumulative_sum;
@ -180,8 +179,7 @@ std::string HistogramStat::ToString() const {
uint64_t cur_num = num(); uint64_t cur_num = num();
std::string r; std::string r;
char buf[1650]; char buf[1650];
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf), "Count: %" PRIu64 " Average: %.4f StdDev: %.2f\n",
"Count: %" PRIu64 " Average: %.4f StdDev: %.2f\n",
cur_num, Average(), StandardDeviation()); cur_num, Average(), StandardDeviation());
r.append(buf); r.append(buf);
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
@ -205,7 +203,7 @@ std::string HistogramStat::ToString() const {
snprintf(buf, sizeof(buf), snprintf(buf, sizeof(buf),
"%c %7" PRIu64 ", %7" PRIu64 " ] %8" PRIu64 " %7.3f%% %7.3f%% ", "%c %7" PRIu64 ", %7" PRIu64 " ] %8" PRIu64 " %7.3f%% %7.3f%% ",
(b == 0) ? '[' : '(', (b == 0) ? '[' : '(',
(b == 0) ? 0 : bucketMapper.BucketLimit(b-1), // left (b == 0) ? 0 : bucketMapper.BucketLimit(b - 1), // left
bucketMapper.BucketLimit(b), // right bucketMapper.BucketLimit(b), // right
bucket_value, // count bucket_value, // count
(mult * bucket_value), // percentage (mult * bucket_value), // percentage
@ -220,7 +218,7 @@ std::string HistogramStat::ToString() const {
return r; return r;
} }
void HistogramStat::Data(HistogramData * const data) const { void HistogramStat::Data(HistogramData* const data) const {
assert(data); assert(data);
data->median = Median(); data->median = Median();
data->percentile95 = Percentile(95); data->percentile95 = Percentile(95);
@ -238,13 +236,9 @@ void HistogramImpl::Clear() {
stats_.Clear(); stats_.Clear();
} }
bool HistogramImpl::Empty() const { bool HistogramImpl::Empty() const { return stats_.Empty(); }
return stats_.Empty();
}
void HistogramImpl::Add(uint64_t value) { void HistogramImpl::Add(uint64_t value) { stats_.Add(value); }
stats_.Add(value);
}
void HistogramImpl::Merge(const Histogram& other) { void HistogramImpl::Merge(const Histogram& other) {
if (strcmp(Name(), other.Name()) == 0) { if (strcmp(Name(), other.Name()) == 0) {
@ -257,28 +251,20 @@ void HistogramImpl::Merge(const HistogramImpl& other) {
stats_.Merge(other.stats_); stats_.Merge(other.stats_);
} }
double HistogramImpl::Median() const { double HistogramImpl::Median() const { return stats_.Median(); }
return stats_.Median();
}
double HistogramImpl::Percentile(double p) const { double HistogramImpl::Percentile(double p) const {
return stats_.Percentile(p); return stats_.Percentile(p);
} }
double HistogramImpl::Average() const { double HistogramImpl::Average() const { return stats_.Average(); }
return stats_.Average();
}
double HistogramImpl::StandardDeviation() const { double HistogramImpl::StandardDeviation() const {
return stats_.StandardDeviation(); return stats_.StandardDeviation();
} }
std::string HistogramImpl::ToString() const { std::string HistogramImpl::ToString() const { return stats_.ToString(); }
return stats_.ToString();
}
void HistogramImpl::Data(HistogramData * const data) const { void HistogramImpl::Data(HistogramData* const data) const { stats_.Data(data); }
stats_.Data(data);
}
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -8,36 +8,29 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors. // found in the LICENSE file. See the AUTHORS file for names of contributors.
#pragma once #pragma once
#include "rocksdb/statistics.h"
#include <cassert> #include <cassert>
#include <string>
#include <vector>
#include <map> #include <map>
#include <mutex> #include <mutex>
#include <string>
#include <vector>
#include "rocksdb/statistics.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
class HistogramBucketMapper { class HistogramBucketMapper {
public: public:
HistogramBucketMapper(); HistogramBucketMapper();
// converts a value to the bucket index. // converts a value to the bucket index.
size_t IndexForValue(uint64_t value) const; size_t IndexForValue(uint64_t value) const;
// number of buckets required. // number of buckets required.
size_t BucketCount() const { size_t BucketCount() const { return bucketValues_.size(); }
return bucketValues_.size();
}
uint64_t LastValue() const { uint64_t LastValue() const { return maxBucketValue_; }
return maxBucketValue_;
}
uint64_t FirstValue() const { uint64_t FirstValue() const { return minBucketValue_; }
return minBucketValue_;
}
uint64_t BucketLimit(const size_t bucketNumber) const { uint64_t BucketLimit(const size_t bucketNumber) const {
assert(bucketNumber < BucketCount()); assert(bucketNumber < BucketCount());
@ -93,9 +86,9 @@ struct HistogramStat {
}; };
class Histogram { class Histogram {
public: public:
Histogram() {} Histogram() {}
virtual ~Histogram() {}; virtual ~Histogram(){};
virtual void Clear() = 0; virtual void Clear() = 0;
virtual bool Empty() const = 0; virtual bool Empty() const = 0;

@ -18,14 +18,14 @@ namespace ROCKSDB_NAMESPACE {
class HistogramTest : public testing::Test {}; class HistogramTest : public testing::Test {};
namespace { namespace {
const double kIota = 0.1; const double kIota = 0.1;
const HistogramBucketMapper bucketMapper; const HistogramBucketMapper bucketMapper;
std::shared_ptr<MockSystemClock> clock = std::shared_ptr<MockSystemClock> clock =
std::make_shared<MockSystemClock>(SystemClock::Default()); std::make_shared<MockSystemClock>(SystemClock::Default());
} } // namespace
void PopulateHistogram(Histogram& histogram, void PopulateHistogram(Histogram& histogram, uint64_t low, uint64_t high,
uint64_t low, uint64_t high, uint64_t loop = 1) { uint64_t loop = 1) {
Random rnd(test::RandomSeed()); Random rnd(test::RandomSeed());
for (; loop > 0; loop--) { for (; loop > 0; loop--) {
for (uint64_t i = low; i <= high; i++) { for (uint64_t i = low; i <= high; i++) {
@ -139,8 +139,8 @@ TEST_F(HistogramTest, HistogramWindowingExpire) {
int micros_per_window = 1000000; int micros_per_window = 1000000;
uint64_t min_num_per_window = 0; uint64_t min_num_per_window = 0;
HistogramWindowingImpl HistogramWindowingImpl histogramWindowing(num_windows, micros_per_window,
histogramWindowing(num_windows, micros_per_window, min_num_per_window); min_num_per_window);
histogramWindowing.TEST_UpdateClock(clock); histogramWindowing.TEST_UpdateClock(clock);
PopulateHistogram(histogramWindowing, 1, 1, 100); PopulateHistogram(histogramWindowing, 1, 1, 100);
clock->SleepForMicroseconds(micros_per_window); clock->SleepForMicroseconds(micros_per_window);
@ -190,10 +190,10 @@ TEST_F(HistogramTest, HistogramWindowingMerge) {
int micros_per_window = 1000000; int micros_per_window = 1000000;
uint64_t min_num_per_window = 0; uint64_t min_num_per_window = 0;
HistogramWindowingImpl HistogramWindowingImpl histogramWindowing(num_windows, micros_per_window,
histogramWindowing(num_windows, micros_per_window, min_num_per_window); min_num_per_window);
HistogramWindowingImpl HistogramWindowingImpl otherWindowing(num_windows, micros_per_window,
otherWindowing(num_windows, micros_per_window, min_num_per_window); min_num_per_window);
histogramWindowing.TEST_UpdateClock(clock); histogramWindowing.TEST_UpdateClock(clock);
otherWindowing.TEST_UpdateClock(clock); otherWindowing.TEST_UpdateClock(clock);

@ -23,11 +23,10 @@ HistogramWindowingImpl::HistogramWindowingImpl() {
Clear(); Clear();
} }
HistogramWindowingImpl::HistogramWindowingImpl( HistogramWindowingImpl::HistogramWindowingImpl(uint64_t num_windows,
uint64_t num_windows,
uint64_t micros_per_window, uint64_t micros_per_window,
uint64_t min_num_per_window) : uint64_t min_num_per_window)
num_windows_(num_windows), : num_windows_(num_windows),
micros_per_window_(micros_per_window), micros_per_window_(micros_per_window),
min_num_per_window_(min_num_per_window) { min_num_per_window_(min_num_per_window) {
clock_ = SystemClock::Default(); clock_ = SystemClock::Default();
@ -35,8 +34,7 @@ HistogramWindowingImpl::HistogramWindowingImpl(
Clear(); Clear();
} }
HistogramWindowingImpl::~HistogramWindowingImpl() { HistogramWindowingImpl::~HistogramWindowingImpl() {}
}
void HistogramWindowingImpl::Clear() { void HistogramWindowingImpl::Clear() {
std::lock_guard<std::mutex> lock(mutex_); std::lock_guard<std::mutex> lock(mutex_);
@ -55,7 +53,7 @@ bool HistogramWindowingImpl::Empty() const { return stats_.Empty(); }
// of any operation. // of any operation.
// Each individual value is atomic, it is just that some samples can go // Each individual value is atomic, it is just that some samples can go
// in the older bucket which is tolerable. // in the older bucket which is tolerable.
void HistogramWindowingImpl::Add(uint64_t value){ void HistogramWindowingImpl::Add(uint64_t value) {
TimerTick(); TimerTick();
// Parent (global) member update // Parent (global) member update
@ -83,17 +81,15 @@ void HistogramWindowingImpl::Merge(const HistogramWindowingImpl& other) {
uint64_t cur_window = current_window(); uint64_t cur_window = current_window();
uint64_t other_cur_window = other.current_window(); uint64_t other_cur_window = other.current_window();
// going backwards for alignment // going backwards for alignment
for (unsigned int i = 0; for (unsigned int i = 0; i < std::min(num_windows_, other.num_windows_);
i < std::min(num_windows_, other.num_windows_); i++) { i++) {
uint64_t window_index = uint64_t window_index = (cur_window + num_windows_ - i) % num_windows_;
(cur_window + num_windows_ - i) % num_windows_;
uint64_t other_window_index = uint64_t other_window_index =
(other_cur_window + other.num_windows_ - i) % other.num_windows_; (other_cur_window + other.num_windows_ - i) % other.num_windows_;
size_t windex = static_cast<size_t>(window_index); size_t windex = static_cast<size_t>(window_index);
size_t other_windex = static_cast<size_t>(other_window_index); size_t other_windex = static_cast<size_t>(other_window_index);
window_stats_[windex].Merge( window_stats_[windex].Merge(other.window_stats_[other_windex]);
other.window_stats_[other_windex]);
} }
} }
@ -101,9 +97,7 @@ std::string HistogramWindowingImpl::ToString() const {
return stats_.ToString(); return stats_.ToString();
} }
double HistogramWindowingImpl::Median() const { double HistogramWindowingImpl::Median() const { return Percentile(50.0); }
return Percentile(50.0);
}
double HistogramWindowingImpl::Percentile(double p) const { double HistogramWindowingImpl::Percentile(double p) const {
// Retry 3 times in total // Retry 3 times in total
@ -118,15 +112,13 @@ double HistogramWindowingImpl::Percentile(double p) const {
return 0.0; return 0.0;
} }
double HistogramWindowingImpl::Average() const { double HistogramWindowingImpl::Average() const { return stats_.Average(); }
return stats_.Average();
}
double HistogramWindowingImpl::StandardDeviation() const { double HistogramWindowingImpl::StandardDeviation() const {
return stats_.StandardDeviation(); return stats_.StandardDeviation();
} }
void HistogramWindowingImpl::Data(HistogramData * const data) const { void HistogramWindowingImpl::Data(HistogramData* const data) const {
stats_.Data(data); stats_.Data(data);
} }
@ -149,17 +141,17 @@ void HistogramWindowingImpl::SwapHistoryBucket() {
last_swap_time_.store(clock_->NowMicros(), std::memory_order_relaxed); last_swap_time_.store(clock_->NowMicros(), std::memory_order_relaxed);
uint64_t curr_window = current_window(); uint64_t curr_window = current_window();
uint64_t next_window = (curr_window == num_windows_ - 1) ? uint64_t next_window =
0 : curr_window + 1; (curr_window == num_windows_ - 1) ? 0 : curr_window + 1;
// subtract next buckets from totals and swap to next buckets // subtract next buckets from totals and swap to next buckets
HistogramStat& stats_to_drop = HistogramStat& stats_to_drop =
window_stats_[static_cast<size_t>(next_window)]; window_stats_[static_cast<size_t>(next_window)];
if (!stats_to_drop.Empty()) { if (!stats_to_drop.Empty()) {
for (size_t b = 0; b < stats_.num_buckets_; b++){ for (size_t b = 0; b < stats_.num_buckets_; b++) {
stats_.buckets_[b].fetch_sub( stats_.buckets_[b].fetch_sub(stats_to_drop.bucket_at(b),
stats_to_drop.bucket_at(b), std::memory_order_relaxed); std::memory_order_relaxed);
} }
if (stats_.min() == stats_to_drop.min()) { if (stats_.min() == stats_to_drop.min()) {
@ -186,8 +178,8 @@ void HistogramWindowingImpl::SwapHistoryBucket() {
stats_.num_.fetch_sub(stats_to_drop.num(), std::memory_order_relaxed); stats_.num_.fetch_sub(stats_to_drop.num(), std::memory_order_relaxed);
stats_.sum_.fetch_sub(stats_to_drop.sum(), std::memory_order_relaxed); stats_.sum_.fetch_sub(stats_to_drop.sum(), std::memory_order_relaxed);
stats_.sum_squares_.fetch_sub( stats_.sum_squares_.fetch_sub(stats_to_drop.sum_squares(),
stats_to_drop.sum_squares(), std::memory_order_relaxed); std::memory_order_relaxed);
stats_to_drop.Clear(); stats_to_drop.Clear();
} }

@ -14,12 +14,10 @@
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
class SystemClock; class SystemClock;
class HistogramWindowingImpl : public Histogram class HistogramWindowingImpl : public Histogram {
{ public:
public:
HistogramWindowingImpl(); HistogramWindowingImpl();
HistogramWindowingImpl(uint64_t num_windows, HistogramWindowingImpl(uint64_t num_windows, uint64_t micros_per_window,
uint64_t micros_per_window,
uint64_t min_num_per_window); uint64_t min_num_per_window);
HistogramWindowingImpl(const HistogramWindowingImpl&) = delete; HistogramWindowingImpl(const HistogramWindowingImpl&) = delete;
@ -56,7 +54,7 @@ public:
inline uint64_t current_window() const { inline uint64_t current_window() const {
return current_window_.load(std::memory_order_relaxed); return current_window_.load(std::memory_order_relaxed);
} }
inline uint64_t last_swap_time() const{ inline uint64_t last_swap_time() const {
return last_swap_time_.load(std::memory_order_relaxed); return last_swap_time_.load(std::memory_order_relaxed);
} }

@ -7,6 +7,7 @@
// found in the LICENSE file. See the AUTHORS file for names of contributors. // found in the LICENSE file. See the AUTHORS file for names of contributors.
#include "monitoring/in_memory_stats_history.h" #include "monitoring/in_memory_stats_history.h"
#include "db/db_impl/db_impl.h" #include "db/db_impl/db_impl.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

@ -46,9 +46,7 @@ class InstrumentedMutex {
void Unlock() { mutex_.Unlock(); } void Unlock() { mutex_.Unlock(); }
void AssertHeld() { void AssertHeld() { mutex_.AssertHeld(); }
mutex_.AssertHeld();
}
private: private:
void LockInternal(); void LockInternal();
@ -76,9 +74,7 @@ class InstrumentedMutexLock {
mutex_->Lock(); mutex_->Lock();
} }
~InstrumentedMutexLock() { ~InstrumentedMutexLock() { mutex_->Unlock(); }
mutex_->Unlock();
}
private: private:
InstrumentedMutex* const mutex_; InstrumentedMutex* const mutex_;
@ -114,13 +110,9 @@ class InstrumentedCondVar {
bool TimedWait(uint64_t abs_time_us); bool TimedWait(uint64_t abs_time_us);
void Signal() { void Signal() { cond_.Signal(); }
cond_.Signal();
}
void SignalAll() { void SignalAll() { cond_.SignalAll(); }
cond_.SignalAll();
}
private: private:
void WaitInternal(); void WaitInternal();

@ -4,6 +4,7 @@
// (found in the LICENSE.Apache file in the root directory). // (found in the LICENSE.Apache file in the root directory).
#include <sstream> #include <sstream>
#include "monitoring/iostats_context_imp.h" #include "monitoring/iostats_context_imp.h"
#include "rocksdb/env.h" #include "rocksdb/env.h"
@ -17,9 +18,7 @@ static IOStatsContext iostats_context;
thread_local IOStatsContext iostats_context; thread_local IOStatsContext iostats_context;
#endif #endif
IOStatsContext* get_iostats_context() { IOStatsContext* get_iostats_context() { return &iostats_context; }
return &iostats_context;
}
void IOStatsContext::Reset() { void IOStatsContext::Reset() {
#ifndef NIOSTATS_CONTEXT #ifndef NIOSTATS_CONTEXT

@ -4,6 +4,7 @@
// (found in the LICENSE.Apache file in the root directory). // (found in the LICENSE.Apache file in the root directory).
#include "rocksdb/iostats_context.h" #include "rocksdb/iostats_context.h"
#include "test_util/testharness.h" #include "test_util/testharness.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

@ -5,6 +5,7 @@
// //
#include <sstream> #include <sstream>
#include "monitoring/perf_context_imp.h" #include "monitoring/perf_context_imp.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
@ -17,9 +18,7 @@ PerfContext perf_context;
thread_local PerfContext perf_context; thread_local PerfContext perf_context;
#endif #endif
PerfContext* get_perf_context() { PerfContext* get_perf_context() { return &perf_context; }
return &perf_context;
}
PerfContext::~PerfContext() { PerfContext::~PerfContext() {
#if !defined(NPERF_CONTEXT) && !defined(OS_SOLARIS) #if !defined(NPERF_CONTEXT) && !defined(OS_SOLARIS)
@ -500,8 +499,7 @@ void PerfContext::Reset() {
} }
#define PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(counter) \ #define PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(counter) \
if (per_level_perf_context_enabled && \ if (per_level_perf_context_enabled && level_to_perf_context) { \
level_to_perf_context) { \
ss << #counter << " = "; \ ss << #counter << " = "; \
for (auto& kv : *level_to_perf_context) { \ for (auto& kv : *level_to_perf_context) { \
if (!exclude_zero_counters || (kv.second.counter > 0)) { \ if (!exclude_zero_counters || (kv.second.counter > 0)) { \
@ -638,11 +636,11 @@ void PerfContext::EnablePerLevelPerfContext() {
per_level_perf_context_enabled = true; per_level_perf_context_enabled = true;
} }
void PerfContext::DisablePerLevelPerfContext(){ void PerfContext::DisablePerLevelPerfContext() {
per_level_perf_context_enabled = false; per_level_perf_context_enabled = false;
} }
void PerfContext::ClearPerLevelPerfContext(){ void PerfContext::ClearPerLevelPerfContext() {
if (level_to_perf_context != nullptr) { if (level_to_perf_context != nullptr) {
level_to_perf_context->clear(); level_to_perf_context->clear();
delete level_to_perf_context; delete level_to_perf_context;

@ -5,6 +5,7 @@
// //
#include <assert.h> #include <assert.h>
#include "monitoring/perf_level_imp.h" #include "monitoring/perf_level_imp.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
@ -17,8 +18,6 @@ void SetPerfLevel(PerfLevel level) {
perf_level = level; perf_level = level;
} }
PerfLevel GetPerfLevel() { PerfLevel GetPerfLevel() { return perf_level; }
return perf_level;
}
} // namespace ROCKSDB_NAMESPACE } // namespace ROCKSDB_NAMESPACE

@ -4,8 +4,8 @@
// (found in the LICENSE.Apache file in the root directory). // (found in the LICENSE.Apache file in the root directory).
// //
#pragma once #pragma once
#include "rocksdb/perf_level.h"
#include "port/port.h" #include "port/port.h"
#include "rocksdb/perf_level.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {

@ -26,9 +26,7 @@ class PerfStepTimer {
metric_(metric), metric_(metric),
statistics_(statistics) {} statistics_(statistics) {}
~PerfStepTimer() { ~PerfStepTimer() { Stop(); }
Stop();
}
void Start() { void Start() {
if (perf_counter_enabled_ || statistics_ != nullptr) { if (perf_counter_enabled_ || statistics_ != nullptr) {

@ -11,6 +11,7 @@
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <utility> #include <utility>
#include "db/db_impl/db_impl.h" #include "db/db_impl/db_impl.h"
#include "util/string_util.h" #include "util/string_util.h"

@ -4,8 +4,6 @@
// (found in the LICENSE.Apache file in the root directory). // (found in the LICENSE.Apache file in the root directory).
// //
#pragma once #pragma once
#include "rocksdb/statistics.h"
#include <atomic> #include <atomic>
#include <map> #include <map>
#include <string> #include <string>
@ -14,6 +12,7 @@
#include "monitoring/histogram.h" #include "monitoring/histogram.h"
#include "port/likely.h" #include "port/likely.h"
#include "port/port.h" #include "port/port.h"
#include "rocksdb/statistics.h"
#include "util/core_local.h" #include "util/core_local.h"
#include "util/mutexlock.h" #include "util/mutexlock.h"
@ -94,14 +93,15 @@ class StatisticsImpl : public Statistics {
INTERNAL_HISTOGRAM_ENUM_MAX * sizeof(HistogramImpl)) % INTERNAL_HISTOGRAM_ENUM_MAX * sizeof(HistogramImpl)) %
CACHE_LINE_SIZE)] ROCKSDB_FIELD_UNUSED; CACHE_LINE_SIZE)] ROCKSDB_FIELD_UNUSED;
#endif #endif
void *operator new(size_t s) { return port::cacheline_aligned_alloc(s); } void* operator new(size_t s) { return port::cacheline_aligned_alloc(s); }
void *operator new[](size_t s) { return port::cacheline_aligned_alloc(s); } void* operator new[](size_t s) { return port::cacheline_aligned_alloc(s); }
void operator delete(void *p) { port::cacheline_aligned_free(p); } void operator delete(void* p) { port::cacheline_aligned_free(p); }
void operator delete[](void *p) { port::cacheline_aligned_free(p); } void operator delete[](void* p) { port::cacheline_aligned_free(p); }
}; };
#ifndef TEST_CACHE_LINE_SIZE #ifndef TEST_CACHE_LINE_SIZE
static_assert(sizeof(StatisticsData) % CACHE_LINE_SIZE == 0, "Expected " TOSTRING(CACHE_LINE_SIZE) "-byte aligned"); static_assert(sizeof(StatisticsData) % CACHE_LINE_SIZE == 0,
"Expected " TOSTRING(CACHE_LINE_SIZE) "-byte aligned");
#endif #endif
CoreLocalArray<StatisticsData> per_core_stats_; CoreLocalArray<StatisticsData> per_core_stats_;

@ -36,9 +36,9 @@
#include <unordered_set> #include <unordered_set>
#include <vector> #include <vector>
#include "port/port.h"
#include "rocksdb/status.h" #include "rocksdb/status.h"
#include "rocksdb/thread_status.h" #include "rocksdb/thread_status.h"
#include "port/port.h"
#include "util/thread_operation.h" #include "util/thread_operation.h"
namespace ROCKSDB_NAMESPACE { namespace ROCKSDB_NAMESPACE {
@ -49,11 +49,9 @@ class ColumnFamilyHandle;
struct ConstantColumnFamilyInfo { struct ConstantColumnFamilyInfo {
#ifdef ROCKSDB_USING_THREAD_STATUS #ifdef ROCKSDB_USING_THREAD_STATUS
public: public:
ConstantColumnFamilyInfo( ConstantColumnFamilyInfo(const void* _db_key, const std::string& _db_name,
const void* _db_key, const std::string& _cf_name)
const std::string& _db_name, : db_key(_db_key), db_name(_db_name), cf_name(_cf_name) {}
const std::string& _cf_name) :
db_key(_db_key), db_name(_db_name), cf_name(_cf_name) {}
const void* db_key; const void* db_key;
const std::string db_name; const std::string db_name;
const std::string cf_name; const std::string cf_name;
@ -142,13 +140,11 @@ class ThreadStatusUpdater {
// will be set in std::memory_order_release. This is to ensure // will be set in std::memory_order_release. This is to ensure
// whenever a thread operation is not OP_UNKNOWN, we will always // whenever a thread operation is not OP_UNKNOWN, we will always
// have a consistent information on its properties. // have a consistent information on its properties.
void SetThreadOperationProperty( void SetThreadOperationProperty(int i, uint64_t value);
int i, uint64_t value);
// Increase the "i"th property of the current operation with // Increase the "i"th property of the current operation with
// the specified delta. // the specified delta.
void IncreaseThreadOperationProperty( void IncreaseThreadOperationProperty(int i, uint64_t delta);
int i, uint64_t delta);
// Update the thread operation stage of the current thread. // Update the thread operation stage of the current thread.
ThreadStatus::OperationStage SetThreadOperationStage( ThreadStatus::OperationStage SetThreadOperationStage(
@ -167,14 +163,12 @@ class ThreadStatusUpdater {
void ClearThreadState(); void ClearThreadState();
// Obtain the status of all active registered threads. // Obtain the status of all active registered threads.
Status GetThreadList( Status GetThreadList(std::vector<ThreadStatus>* thread_list);
std::vector<ThreadStatus>* thread_list);
// Create an entry in the global ColumnFamilyInfo table for the // Create an entry in the global ColumnFamilyInfo table for the
// specified column family. This function should be called only // specified column family. This function should be called only
// when the current thread does not hold db_mutex. // when the current thread does not hold db_mutex.
void NewColumnFamilyInfo( void NewColumnFamilyInfo(const void* db_key, const std::string& db_name,
const void* db_key, const std::string& db_name,
const void* cf_key, const std::string& cf_name); const void* cf_key, const std::string& cf_name);
// Erase all ConstantColumnFamilyInfo that is associated with the // Erase all ConstantColumnFamilyInfo that is associated with the
@ -190,8 +184,7 @@ class ThreadStatusUpdater {
// Verifies whether the input ColumnFamilyHandles matches // Verifies whether the input ColumnFamilyHandles matches
// the information stored in the current cf_info_map. // the information stored in the current cf_info_map.
void TEST_VerifyColumnFamilyInfoMap( void TEST_VerifyColumnFamilyInfoMap(
const std::vector<ColumnFamilyHandle*>& handles, const std::vector<ColumnFamilyHandle*>& handles, bool check_exist);
bool check_exist);
protected: protected:
#ifdef ROCKSDB_USING_THREAD_STATUS #ifdef ROCKSDB_USING_THREAD_STATUS
@ -204,9 +197,7 @@ class ThreadStatusUpdater {
// Directly returns the pointer to thread_status_data_ without // Directly returns the pointer to thread_status_data_ without
// checking whether enabling_tracking is true of not. // checking whether enabling_tracking is true of not.
ThreadStatusData* Get() { ThreadStatusData* Get() { return thread_status_data_; }
return thread_status_data_;
}
// The mutex that protects cf_info_map and db_key_map. // The mutex that protects cf_info_map and db_key_map.
std::mutex thread_list_mutex_; std::mutex thread_list_mutex_;
@ -222,8 +213,7 @@ class ThreadStatusUpdater {
// A db_key to cf_key map that allows erasing elements in cf_info_map // A db_key to cf_key map that allows erasing elements in cf_info_map
// associated to the same db_key faster. // associated to the same db_key faster.
std::unordered_map< std::unordered_map<const void*, std::unordered_set<const void*>> db_key_map_;
const void*, std::unordered_set<const void*>> db_key_map_;
#else #else
static ThreadStatusData* thread_status_data_; static ThreadStatusData* thread_status_data_;

@ -30,8 +30,8 @@ class ColumnFamilyData;
class ThreadStatusUtil { class ThreadStatusUtil {
public: public:
// Register the current thread for tracking. // Register the current thread for tracking.
static void RegisterThread( static void RegisterThread(const Env* env,
const Env* env, ThreadStatus::ThreadType thread_type); ThreadStatus::ThreadType thread_type);
// Unregister the current thread. // Unregister the current thread.
static void UnregisterThread(); static void UnregisterThread();
@ -62,19 +62,17 @@ class ThreadStatusUtil {
static ThreadStatus::OperationStage SetThreadOperationStage( static ThreadStatus::OperationStage SetThreadOperationStage(
ThreadStatus::OperationStage stage); ThreadStatus::OperationStage stage);
static void SetThreadOperationProperty( static void SetThreadOperationProperty(int code, uint64_t value);
int code, uint64_t value);
static void IncreaseThreadOperationProperty( static void IncreaseThreadOperationProperty(int code, uint64_t delta);
int code, uint64_t delta);
static void SetThreadState(ThreadStatus::StateType type); static void SetThreadState(ThreadStatus::StateType type);
static void ResetThreadStatus(); static void ResetThreadStatus();
#ifndef NDEBUG #ifndef NDEBUG
static void TEST_SetStateDelay( static void TEST_SetStateDelay(const ThreadStatus::StateType state,
const ThreadStatus::StateType state, int micro); int micro);
static void TEST_StateDelay(const ThreadStatus::StateType state); static void TEST_StateDelay(const ThreadStatus::StateType state);
#endif #endif
@ -121,8 +119,7 @@ class ThreadStatusUtil {
// and set the thread state to the previous state in its destructor. // and set the thread state to the previous state in its destructor.
class AutoThreadOperationStageUpdater { class AutoThreadOperationStageUpdater {
public: public:
explicit AutoThreadOperationStageUpdater( explicit AutoThreadOperationStageUpdater(ThreadStatus::OperationStage stage);
ThreadStatus::OperationStage stage);
~AutoThreadOperationStageUpdater(); ~AutoThreadOperationStageUpdater();
#ifdef ROCKSDB_USING_THREAD_STATUS #ifdef ROCKSDB_USING_THREAD_STATUS

@ -15,8 +15,8 @@ namespace ROCKSDB_NAMESPACE {
// the delay for debugging purpose. // the delay for debugging purpose.
static std::atomic<int> states_delay[ThreadStatus::NUM_STATE_TYPES]; static std::atomic<int> states_delay[ThreadStatus::NUM_STATE_TYPES];
void ThreadStatusUtil::TEST_SetStateDelay( void ThreadStatusUtil::TEST_SetStateDelay(const ThreadStatus::StateType state,
const ThreadStatus::StateType state, int micro) { int micro) {
states_delay[state].store(micro, std::memory_order_relaxed); states_delay[state].store(micro, std::memory_order_relaxed);
} }

Loading…
Cancel
Save