file_read_sample.h 843 B

1234567891011121314151617181920212223
  1. // Copyright (c) 2011-present, Facebook, Inc. All rights reserved.
  2. // This source code is licensed under both the GPLv2 (found in the
  3. // COPYING file in the root directory) and Apache 2.0 License
  4. // (found in the LICENSE.Apache file in the root directory).
  5. //
  6. #pragma once
  7. #include "db/version_edit.h"
  8. #include "util/random.h"
  9. namespace ROCKSDB_NAMESPACE {
  10. static const uint32_t kFileReadSampleRate = 1024;
  11. extern bool should_sample_file_read();
  12. extern void sample_file_read_inc(FileMetaData*);
  13. inline bool should_sample_file_read() {
  14. return (Random::GetTLSInstance()->Next() % kFileReadSampleRate == 307);
  15. }
  16. inline void sample_file_read_inc(FileMetaData* meta) {
  17. meta->stats.num_reads_sampled.fetch_add(kFileReadSampleRate,
  18. std::memory_order_relaxed);
  19. }
  20. } // namespace ROCKSDB_NAMESPACE