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. 62
      monitoring/histogram.cc
  2. 27
      monitoring/histogram.h
  3. 38
      monitoring/histogram_test.cc
  4. 50
      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. 26
      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. 2
      monitoring/statistics.cc
  16. 14
      monitoring/statistics.h
  17. 34
      monitoring/thread_status_updater.h
  18. 17
      monitoring/thread_status_util.h
  19. 4
      monitoring/thread_status_util_debug.cc

@ -52,11 +52,10 @@ size_t HistogramBucketMapper::IndexForValue(const uint64_t value) const {
}
namespace {
const HistogramBucketMapper bucketMapper;
const HistogramBucketMapper bucketMapper;
}
HistogramStat::HistogramStat()
: num_buckets_(bucketMapper.BucketCount()) {
HistogramStat::HistogramStat() : num_buckets_(bucketMapper.BucketCount()) {
assert(num_buckets_ == sizeof(buckets_) / sizeof(*buckets_));
Clear();
}
@ -109,12 +108,14 @@ void HistogramStat::Merge(const HistogramStat& other) {
uint64_t old_min = min();
uint64_t other_min = other.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 other_max = other.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);
sum_.fetch_add(other.sum(), std::memory_order_relaxed);
@ -124,9 +125,7 @@ void HistogramStat::Merge(const HistogramStat& other) {
}
}
double HistogramStat::Median() const {
return Percentile(50.0);
}
double HistogramStat::Median() const { return Percentile(50.0); }
double HistogramStat::Percentile(double p) const {
double threshold = num() * (p / 100.0);
@ -136,14 +135,14 @@ double HistogramStat::Percentile(double p) const {
cumulative_sum += bucket_value;
if (cumulative_sum >= threshold) {
// 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 left_sum = cumulative_sum - bucket_value;
uint64_t right_sum = cumulative_sum;
double pos = 0;
uint64_t right_left_diff = right_sum - left_sum;
if (right_left_diff != 0) {
pos = (threshold - left_sum) / right_left_diff;
pos = (threshold - left_sum) / right_left_diff;
}
double r = left_point + (right_point - left_point) * pos;
uint64_t cur_min = min();
@ -180,8 +179,7 @@ std::string HistogramStat::ToString() const {
uint64_t cur_num = num();
std::string r;
char buf[1650];
snprintf(buf, sizeof(buf),
"Count: %" PRIu64 " Average: %.4f StdDev: %.2f\n",
snprintf(buf, sizeof(buf), "Count: %" PRIu64 " Average: %.4f StdDev: %.2f\n",
cur_num, Average(), StandardDeviation());
r.append(buf);
snprintf(buf, sizeof(buf),
@ -195,7 +193,7 @@ std::string HistogramStat::ToString() const {
Percentile(99.99));
r.append(buf);
r.append("------------------------------------------------------\n");
if (cur_num == 0) return r; // all buckets are empty
if (cur_num == 0) return r; // all buckets are empty
const double mult = 100.0 / cur_num;
uint64_t cumulative_sum = 0;
for (unsigned int b = 0; b < num_buckets_; b++) {
@ -205,11 +203,11 @@ std::string HistogramStat::ToString() const {
snprintf(buf, sizeof(buf),
"%c %7" PRIu64 ", %7" PRIu64 " ] %8" PRIu64 " %7.3f%% %7.3f%% ",
(b == 0) ? '[' : '(',
(b == 0) ? 0 : bucketMapper.BucketLimit(b-1), // left
bucketMapper.BucketLimit(b), // right
bucket_value, // count
(mult * bucket_value), // percentage
(mult * cumulative_sum)); // cumulative percentage
(b == 0) ? 0 : bucketMapper.BucketLimit(b - 1), // left
bucketMapper.BucketLimit(b), // right
bucket_value, // count
(mult * bucket_value), // percentage
(mult * cumulative_sum)); // cumulative percentage
r.append(buf);
// Add hash marks based on percentage; 20 marks for 100%.
@ -220,7 +218,7 @@ std::string HistogramStat::ToString() const {
return r;
}
void HistogramStat::Data(HistogramData * const data) const {
void HistogramStat::Data(HistogramData* const data) const {
assert(data);
data->median = Median();
data->percentile95 = Percentile(95);
@ -238,13 +236,9 @@ void HistogramImpl::Clear() {
stats_.Clear();
}
bool HistogramImpl::Empty() const {
return stats_.Empty();
}
bool HistogramImpl::Empty() const { return stats_.Empty(); }
void HistogramImpl::Add(uint64_t value) {
stats_.Add(value);
}
void HistogramImpl::Add(uint64_t value) { stats_.Add(value); }
void HistogramImpl::Merge(const Histogram& other) {
if (strcmp(Name(), other.Name()) == 0) {
@ -257,28 +251,20 @@ void HistogramImpl::Merge(const HistogramImpl& other) {
stats_.Merge(other.stats_);
}
double HistogramImpl::Median() const {
return stats_.Median();
}
double HistogramImpl::Median() const { return stats_.Median(); }
double HistogramImpl::Percentile(double p) const {
return stats_.Percentile(p);
}
double HistogramImpl::Average() const {
return stats_.Average();
}
double HistogramImpl::Average() const { return stats_.Average(); }
double HistogramImpl::StandardDeviation() const {
return stats_.StandardDeviation();
return stats_.StandardDeviation();
}
std::string HistogramImpl::ToString() const {
return stats_.ToString();
}
std::string HistogramImpl::ToString() const { return stats_.ToString(); }
void HistogramImpl::Data(HistogramData * const data) const {
stats_.Data(data);
}
void HistogramImpl::Data(HistogramData* const data) const { stats_.Data(data); }
} // namespace ROCKSDB_NAMESPACE

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

@ -18,14 +18,14 @@ namespace ROCKSDB_NAMESPACE {
class HistogramTest : public testing::Test {};
namespace {
const double kIota = 0.1;
const HistogramBucketMapper bucketMapper;
std::shared_ptr<MockSystemClock> clock =
std::make_shared<MockSystemClock>(SystemClock::Default());
}
void PopulateHistogram(Histogram& histogram,
uint64_t low, uint64_t high, uint64_t loop = 1) {
const double kIota = 0.1;
const HistogramBucketMapper bucketMapper;
std::shared_ptr<MockSystemClock> clock =
std::make_shared<MockSystemClock>(SystemClock::Default());
} // namespace
void PopulateHistogram(Histogram& histogram, uint64_t low, uint64_t high,
uint64_t loop = 1) {
Random rnd(test::RandomSeed());
for (; loop > 0; loop--) {
for (uint64_t i = low; i <= high; i++) {
@ -39,7 +39,7 @@ void PopulateHistogram(Histogram& histogram,
}
void BasicOperation(Histogram& histogram) {
PopulateHistogram(histogram, 1, 110, 10); // fill up to bucket [70, 110)
PopulateHistogram(histogram, 1, 110, 10); // fill up to bucket [70, 110)
HistogramData data;
histogram.Data(&data);
@ -47,8 +47,8 @@ void BasicOperation(Histogram& histogram) {
ASSERT_LE(fabs(histogram.Percentile(100.0) - 110.0), kIota);
ASSERT_LE(fabs(data.percentile99 - 108.9), kIota); // 99 * 110 / 100
ASSERT_LE(fabs(data.percentile95 - 104.5), kIota); // 95 * 110 / 100
ASSERT_LE(fabs(data.median - 55.0), kIota); // 50 * 110 / 100
ASSERT_EQ(data.average, 55.5); // (1 + 110) / 2
ASSERT_LE(fabs(data.median - 55.0), kIota); // 50 * 110 / 100
ASSERT_EQ(data.average, 55.5); // (1 + 110) / 2
}
void MergeHistogram(Histogram& histogram, Histogram& other) {
@ -62,8 +62,8 @@ void MergeHistogram(Histogram& histogram, Histogram& other) {
ASSERT_LE(fabs(histogram.Percentile(100.0) - 250.0), kIota);
ASSERT_LE(fabs(data.percentile99 - 247.5), kIota); // 99 * 250 / 100
ASSERT_LE(fabs(data.percentile95 - 237.5), kIota); // 95 * 250 / 100
ASSERT_LE(fabs(data.median - 125.0), kIota); // 50 * 250 / 100
ASSERT_EQ(data.average, 125.5); // (1 + 250) / 2
ASSERT_LE(fabs(data.median - 125.0), kIota); // 50 * 250 / 100
ASSERT_EQ(data.average, 125.5); // (1 + 250) / 2
}
void EmptyHistogram(Histogram& histogram) {
@ -139,8 +139,8 @@ TEST_F(HistogramTest, HistogramWindowingExpire) {
int micros_per_window = 1000000;
uint64_t min_num_per_window = 0;
HistogramWindowingImpl
histogramWindowing(num_windows, micros_per_window, min_num_per_window);
HistogramWindowingImpl histogramWindowing(num_windows, micros_per_window,
min_num_per_window);
histogramWindowing.TEST_UpdateClock(clock);
PopulateHistogram(histogramWindowing, 1, 1, 100);
clock->SleepForMicroseconds(micros_per_window);
@ -190,10 +190,10 @@ TEST_F(HistogramTest, HistogramWindowingMerge) {
int micros_per_window = 1000000;
uint64_t min_num_per_window = 0;
HistogramWindowingImpl
histogramWindowing(num_windows, micros_per_window, min_num_per_window);
HistogramWindowingImpl
otherWindowing(num_windows, micros_per_window, min_num_per_window);
HistogramWindowingImpl histogramWindowing(num_windows, micros_per_window,
min_num_per_window);
HistogramWindowingImpl otherWindowing(num_windows, micros_per_window,
min_num_per_window);
histogramWindowing.TEST_UpdateClock(clock);
otherWindowing.TEST_UpdateClock(clock);

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

@ -14,12 +14,10 @@
namespace ROCKSDB_NAMESPACE {
class SystemClock;
class HistogramWindowingImpl : public Histogram
{
public:
class HistogramWindowingImpl : public Histogram {
public:
HistogramWindowingImpl();
HistogramWindowingImpl(uint64_t num_windows,
uint64_t micros_per_window,
HistogramWindowingImpl(uint64_t num_windows, uint64_t micros_per_window,
uint64_t min_num_per_window);
HistogramWindowingImpl(const HistogramWindowingImpl&) = delete;
@ -56,7 +54,7 @@ public:
inline uint64_t current_window() const {
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);
}

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

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

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

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

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

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

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

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

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

@ -469,7 +469,7 @@ namespace {
// a buffer size used for temp string buffers
const int kTmpStrBufferSize = 200;
} // namespace
} // namespace
std::string StatisticsImpl::ToString() const {
MutexLock lock(&aggregate_lock_);

@ -4,8 +4,6 @@
// (found in the LICENSE.Apache file in the root directory).
//
#pragma once
#include "rocksdb/statistics.h"
#include <atomic>
#include <map>
#include <string>
@ -14,6 +12,7 @@
#include "monitoring/histogram.h"
#include "port/likely.h"
#include "port/port.h"
#include "rocksdb/statistics.h"
#include "util/core_local.h"
#include "util/mutexlock.h"
@ -94,14 +93,15 @@ class StatisticsImpl : public Statistics {
INTERNAL_HISTOGRAM_ENUM_MAX * sizeof(HistogramImpl)) %
CACHE_LINE_SIZE)] ROCKSDB_FIELD_UNUSED;
#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 delete(void *p) { port::cacheline_aligned_free(p); }
void operator delete[](void *p) { port::cacheline_aligned_free(p); }
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); }
};
#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
CoreLocalArray<StatisticsData> per_core_stats_;

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

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

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

Loading…
Cancel
Save