diff --git a/db/db_iter.cc b/db/db_iter.cc index 587da72ad..571e8ee2a 100644 --- a/db/db_iter.cc +++ b/db/db_iter.cc @@ -189,6 +189,13 @@ void DBIter::Next() { return; } FindNextUserEntry(true /* skipping the current user key */); + if (statistics_ != nullptr) { + RecordTick(statistics_, NUMBER_DB_NEXT); + if (valid_) { + RecordTick(statistics_, NUMBER_DB_NEXT_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } // PRE: saved_key_ has the current user key if skipping @@ -355,6 +362,13 @@ void DBIter::Prev() { ReverseToBackward(); } PrevInternal(); + if (statistics_ != nullptr) { + RecordTick(statistics_, NUMBER_DB_PREV); + if (valid_) { + RecordTick(statistics_, NUMBER_DB_PREV_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } void DBIter::ReverseToBackward() { @@ -637,10 +651,17 @@ void DBIter::Seek(const Slice& target) { iter_->Seek(saved_key_.GetKey()); } + RecordTick(statistics_, NUMBER_DB_SEEK); if (iter_->Valid()) { direction_ = kForward; ClearSavedValue(); FindNextUserEntry(false /* not skipping */); + if (statistics_ != nullptr) { + if (valid_) { + RecordTick(statistics_, NUMBER_DB_SEEK_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } else { valid_ = false; } @@ -660,8 +681,15 @@ void DBIter::SeekToFirst() { iter_->SeekToFirst(); } + RecordTick(statistics_, NUMBER_DB_SEEK); if (iter_->Valid()) { FindNextUserEntry(false /* not skipping */); + if (statistics_ != nullptr) { + if (valid_) { + RecordTick(statistics_, NUMBER_DB_SEEK_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } else { valid_ = false; } @@ -703,6 +731,13 @@ void DBIter::SeekToLast() { } } PrevInternal(); + if (statistics_ != nullptr) { + RecordTick(statistics_, NUMBER_DB_SEEK); + if (valid_) { + RecordTick(statistics_, NUMBER_DB_SEEK_FOUND); + RecordTick(statistics_, ITER_BYTES_READ, key().size() + value().size()); + } + } } Iterator* NewDBIterator(Env* env, const ImmutableCFOptions& ioptions, diff --git a/include/rocksdb/statistics.h b/include/rocksdb/statistics.h index 2aa1ce7a0..5d610c15a 100644 --- a/include/rocksdb/statistics.h +++ b/include/rocksdb/statistics.h @@ -82,6 +82,17 @@ enum Tickers : uint32_t { // For the number of logical bytes read from DB::MultiGet(), // please use NUMBER_MULTIGET_BYTES_READ. BYTES_READ, + // The number of calls to seek/next/prev + NUMBER_DB_SEEK, + NUMBER_DB_NEXT, + NUMBER_DB_PREV, + // The number of calls to seek/next/prev that returned data + NUMBER_DB_SEEK_FOUND, + NUMBER_DB_NEXT_FOUND, + NUMBER_DB_PREV_FOUND, + // The number of uncompressed bytes read from an iterator. + // Includes size of key and value. + ITER_BYTES_READ, NO_FILE_CLOSES, NO_FILE_OPENS, NO_FILE_ERRORS, @@ -180,6 +191,13 @@ const std::vector> TickersNameMap = { {NUMBER_KEYS_UPDATED, "rocksdb.number.keys.updated"}, {BYTES_WRITTEN, "rocksdb.bytes.written"}, {BYTES_READ, "rocksdb.bytes.read"}, + {NUMBER_DB_SEEK, "rocksdb.number.db.seek"}, + {NUMBER_DB_NEXT, "rocksdb.number.db.next"}, + {NUMBER_DB_PREV, "rocksdb.number.db.prev"}, + {NUMBER_DB_SEEK_FOUND, "rocksdb.number.db.seek.found"}, + {NUMBER_DB_NEXT_FOUND, "rocksdb.number.db.next.found"}, + {NUMBER_DB_PREV_FOUND, "rocksdb.number.db.prev.found"}, + {ITER_BYTES_READ, "rocksdb.db.iter.bytes.read"}, {NO_FILE_CLOSES, "rocksdb.no.file.closes"}, {NO_FILE_OPENS, "rocksdb.no.file.opens"}, {NO_FILE_ERRORS, "rocksdb.no.file.errors"},