/src/rocksdb/monitoring/file_read_sample.h
Line | Count | Source |
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 "test_util/sync_point.h" |
9 | | #include "util/random.h" |
10 | | |
11 | | namespace ROCKSDB_NAMESPACE { |
12 | | static const uint32_t kFileReadSampleRate = 1024; |
13 | | static const uint32_t kFileReadNextSampleRate = |
14 | | kFileReadSampleRate * 64; // Must be kept a power of 2 |
15 | | |
16 | 22.0k | inline bool should_sample_file_read() { |
17 | 22.0k | bool result = (Random::GetTLSInstance()->Next() % kFileReadSampleRate == 307); |
18 | 22.0k | TEST_SYNC_POINT_CALLBACK("should_sample_file_read:override", &result); |
19 | 22.0k | return result; |
20 | 22.0k | } |
21 | | |
22 | 22.5k | inline bool should_sample_file_read_next() { |
23 | | // Decrease probability of sampling next() to discount it as it is cheaper |
24 | | // than seek() |
25 | 22.5k | thread_local uint32_t counter = 0; |
26 | 22.5k | bool result = (++counter & (kFileReadNextSampleRate - 1)) == 0; |
27 | 22.5k | TEST_SYNC_POINT_CALLBACK("should_sample_file_read:override", &result); |
28 | 22.5k | return result; |
29 | 22.5k | } |
30 | | |
31 | 35 | inline void sample_file_read_inc(const FileMetaData* meta) { |
32 | 35 | meta->stats.num_reads_sampled.fetch_add(kFileReadSampleRate, |
33 | 35 | std::memory_order_relaxed); |
34 | 35 | } |
35 | | |
36 | 6 | inline void sample_collapsible_entry_file_read_inc(const FileMetaData* meta) { |
37 | 6 | meta->stats.num_collapsible_entry_reads_sampled.fetch_add( |
38 | 6 | kFileReadSampleRate, std::memory_order_relaxed); |
39 | 6 | } |
40 | | } // namespace ROCKSDB_NAMESPACE |