Skip to content

Commit

Permalink
Accept two histograms in StopWatch
Browse files Browse the repository at this point in the history
  • Loading branch information
hx235 committed Mar 15, 2023
1 parent b0ada30 commit 326b5b2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion db/db_impl/db_impl_write.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1776,7 +1776,7 @@ Status DBImpl::DelayWrite(uint64_t num_bytes, WriteThread& write_thread,
bool delayed = false;
{
StopWatch sw(immutable_db_options_.clock, stats_, WRITE_STALL,
&time_delayed);
Histograms::HISTOGRAM_ENUM_MAX, &time_delayed);
// To avoid parallel timed delays (bad throttling), only support them
// on the primary write queue.
uint64_t delay;
Expand Down
1 change: 1 addition & 0 deletions db/perf_context_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ TEST_F(PerfContextTest, StopWatchOverhead) {
std::vector<uint64_t> timings(kTotalIterations);

StopWatch timer(SystemClock::Default().get(), nullptr,
Histograms::HISTOGRAM_ENUM_MAX,
Histograms::HISTOGRAM_ENUM_MAX, &elapsed);
for (auto& timing : timings) {
timing = elapsed;
Expand Down
30 changes: 13 additions & 17 deletions file/random_access_file_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "util/rate_limiter.h"

namespace ROCKSDB_NAMESPACE {
std::array<Histograms, std::size_t(IOActivity::kIOActivityTotal)>
const std::array<Histograms, std::size_t(IOActivity::kIOActivityTotal)>
kReadHistograms{{
SST_READ_FLUSH_MICROS, SST_READ_COMPACTION_MICROS,
BLOB_DB_BLOB_FILE_READ_MICROS,
Expand Down Expand Up @@ -104,15 +104,12 @@ IOStatus RandomAccessFileReader::Read(const IOOptions& opts, uint64_t offset,
{
IOActivity io_activity_to_use =
op_io_activity != IOActivity::kUnknown ? op_io_activity : io_activity_;
StopWatch sw_sst_read_mircos(
clock_, stats_, SST_READ_MICROS,
(stats_ != nullptr && (io_activity_to_use == IOActivity::kCompaction ||
io_activity_to_use == IOActivity::kFlush))
? &elapsed
: nullptr,
true /*overwrite*/, true /*delay_enabled*/);
StopWatch sw(clock_, stats_,
kReadHistograms[(std::size_t)(io_activity_to_use)],
(io_activity_to_use == IOActivity::kCompaction ||
io_activity_to_use == IOActivity::kFlush)
? SST_READ_MICROS
: Histograms::HISTOGRAM_ENUM_MAX,
(stats_ != nullptr) ? &elapsed : nullptr, true /*overwrite*/,
true /*delay_enabled*/);
auto prev_perf_level = GetPerfLevel();
Expand Down Expand Up @@ -309,15 +306,12 @@ IOStatus RandomAccessFileReader::MultiRead(
{
IOActivity io_activity_to_use =
op_io_activity != IOActivity::kUnknown ? op_io_activity : io_activity_;
StopWatch sw_sst_read_mircos(
clock_, stats_, SST_READ_MICROS,
(stats_ != nullptr && (io_activity_to_use == IOActivity::kCompaction ||
io_activity_to_use == IOActivity::kFlush))
? &elapsed
: nullptr,
true /*overwrite*/, true /*delay_enabled*/);
StopWatch sw(clock_, stats_,
kReadHistograms[(std::size_t)(io_activity_to_use)],
(io_activity_to_use == IOActivity::kCompaction ||
io_activity_to_use == IOActivity::kFlush)
? SST_READ_MICROS
: Histograms::HISTOGRAM_ENUM_MAX,
(stats_ != nullptr) ? &elapsed : nullptr, true /*overwrite*/,
true /*delay_enabled*/);
auto prev_perf_level = GetPerfLevel();
Expand Down Expand Up @@ -506,12 +500,14 @@ IOStatus RandomAccessFileReader::ReadAsync(

assert(read_async_info->buf_.CurrentSize() == 0);

StopWatch sw(clock_, nullptr /*stats*/, DB_GET /*hist_type*/, &elapsed,
StopWatch sw(clock_, nullptr /*stats*/, DB_GET /*hist_type_1*/,
Histograms::HISTOGRAM_ENUM_MAX /*hist_type_2*/, &elapsed,
true /*overwrite*/, true /*delay_enabled*/);
s = file_->ReadAsync(aligned_req, opts, read_async_callback,
read_async_info, io_handle, del_fn, nullptr /*dbg*/);
} else {
StopWatch sw(clock_, nullptr /*stats*/, DB_GET /*hist_type*/, &elapsed,
StopWatch sw(clock_, nullptr /*stats*/, DB_GET /*hist_type_1*/,
Histograms::HISTOGRAM_ENUM_MAX /*hist_type_2*/, &elapsed,
true /*overwrite*/, true /*delay_enabled*/);
s = file_->ReadAsync(req, opts, read_async_callback, read_async_info,
io_handle, del_fn, nullptr /*dbg*/);
Expand Down
29 changes: 19 additions & 10 deletions util/stop_watch.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,28 @@

namespace ROCKSDB_NAMESPACE {
// Auto-scoped.
// Records the measure time into the corresponding histogram if statistics
// Records the measure time into the corresponding histogram(s) if statistics
// is not nullptr. It is also saved into *elapsed if the pointer is not nullptr
// and overwrite is true, it will be added to *elapsed if overwrite is false.
class StopWatch {
public:
StopWatch(SystemClock* clock, Statistics* statistics,
const uint32_t hist_type, uint64_t* elapsed = nullptr,
bool overwrite = true, bool delay_enabled = false)
const uint32_t hist_type_1,
const uint32_t hist_type_2 = Histograms::HISTOGRAM_ENUM_MAX,
uint64_t* elapsed = nullptr, bool overwrite = true,
bool delay_enabled = false)
: clock_(clock),
statistics_(statistics),
hist_type_(hist_type),
hist_type_1_(hist_type_1),
hist_type_2_(hist_type_2),
elapsed_(elapsed),
overwrite_(overwrite),
stats_enabled_(statistics &&
statistics->get_stats_level() >=
StatsLevel::kExceptTimers &&
statistics->HistEnabledForType(hist_type)),
statistics->HistEnabledForType(hist_type_1) &&
(hist_type_2 == Histograms::HISTOGRAM_ENUM_MAX ||
statistics->HistEnabledForType(hist_type_2))),
delay_enabled_(delay_enabled),
total_delay_(0),
delay_start_time_(0),
Expand All @@ -44,10 +49,13 @@ class StopWatch {
*elapsed_ -= total_delay_;
}
if (stats_enabled_) {
statistics_->reportTimeToHistogram(
hist_type_, (elapsed_ != nullptr)
? *elapsed_
: (clock_->NowMicros() - start_time_));
const auto time = (elapsed_ != nullptr)
? *elapsed_
: (clock_->NowMicros() - start_time_);
statistics_->reportTimeToHistogram(hist_type_1_, time);
if (hist_type_2_ != Histograms::HISTOGRAM_ENUM_MAX) {
statistics_->reportTimeToHistogram(hist_type_2_, time);
}
}
}

Expand Down Expand Up @@ -75,7 +83,8 @@ class StopWatch {
private:
SystemClock* clock_;
Statistics* statistics_;
const uint32_t hist_type_;
const uint32_t hist_type_1_;
const uint32_t hist_type_2_;
uint64_t* elapsed_;
bool overwrite_;
bool stats_enabled_;
Expand Down

0 comments on commit 326b5b2

Please sign in to comment.