From 7015fd81c431da527d8038f264eb3a7168cfe592 Mon Sep 17 00:00:00 2001 From: krad Date: Fri, 19 Jun 2015 11:25:33 -0700 Subject: [PATCH] Add read_nanos to IOStatsContext. Summary: MyRocks need a mechanism to track read outliers. We need to expose this stat. Test Plan: None Reviewers: sdong CC: leveldb Task ID: #7152512 Blame Rev: --- include/rocksdb/iostats_context.h | 2 ++ util/env_posix.cc | 12 ++++++++++-- util/iostats_context.cc | 2 ++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/include/rocksdb/iostats_context.h b/include/rocksdb/iostats_context.h index d27879ad9..8bb082f55 100644 --- a/include/rocksdb/iostats_context.h +++ b/include/rocksdb/iostats_context.h @@ -34,6 +34,8 @@ struct IOStatsContext { uint64_t allocate_nanos; // time spent in write() and pwrite(). uint64_t write_nanos; + // time spent in read() and pread() + uint64_t read_nanos; // time spent in sync_file_range(). uint64_t range_sync_nanos; diff --git a/util/env_posix.cc b/util/env_posix.cc index 8b1f04143..cc81149f2 100644 --- a/util/env_posix.cc +++ b/util/env_posix.cc @@ -256,7 +256,11 @@ class PosixRandomAccessFile: public RandomAccessFile { size_t left = n; char* ptr = scratch; while (left > 0) { - r = pread(fd_, ptr, left, static_cast(offset)); + { + IOSTATS_TIMER_GUARD(read_nanos); + r = pread(fd_, ptr, left, static_cast(offset)); + } + if (r <= 0) { if (errno == EINTR) { continue; @@ -975,7 +979,11 @@ class PosixRandomRWFile : public RandomRWFile { size_t left = n; char* ptr = scratch; while (left > 0) { - r = pread(fd_, ptr, left, static_cast(offset)); + { + IOSTATS_TIMER_GUARD(read_nanos); + r = pread(fd_, ptr, left, static_cast(offset)); + } + if (r <= 0) { if (errno == EINTR) { continue; diff --git a/util/iostats_context.cc b/util/iostats_context.cc index 9daaf59d2..87c7a47ae 100644 --- a/util/iostats_context.cc +++ b/util/iostats_context.cc @@ -20,6 +20,7 @@ void IOStatsContext::Reset() { open_nanos = 0; allocate_nanos = 0; write_nanos = 0; + read_nanos = 0; range_sync_nanos = 0; logger_nanos = 0; } @@ -34,6 +35,7 @@ std::string IOStatsContext::ToString() const { << OUTPUT(open_nanos) << OUTPUT(allocate_nanos) << OUTPUT(write_nanos) + << OUTPUT(read_nanos) << OUTPUT(range_sync_nanos) << OUTPUT(logger_nanos);