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 10 namespace ROCKSDB_NAMESPACE { 11 static const uint32_t kFileReadSampleRate = 1024; 12 extern bool should_sample_file_read(); 13 extern void sample_file_read_inc(FileMetaData*); 14 should_sample_file_read()15inline bool should_sample_file_read() { 16 return (Random::GetTLSInstance()->Next() % kFileReadSampleRate == 307); 17 } 18 sample_file_read_inc(FileMetaData * meta)19inline void sample_file_read_inc(FileMetaData* meta) { 20 meta->stats.num_reads_sampled.fetch_add(kFileReadSampleRate, 21 std::memory_order_relaxed); 22 } 23 } // namespace ROCKSDB_NAMESPACE 24