/src/rocksdb/include/rocksdb/iostats_context.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 | | #pragma once |
6 | | |
7 | | #include <stdint.h> |
8 | | |
9 | | #include <string> |
10 | | |
11 | | #include "rocksdb/perf_level.h" |
12 | | |
13 | | /* |
14 | | * NOTE: |
15 | | * If you plan to add new metrics, please read documentation in perf_level.h and |
16 | | * try to come up with a metric name that follows the naming conventions |
17 | | * mentioned there. It helps to indicate the metric's starting enabling P |
18 | | * erfLevel. Document this starting PerfLevel if the metric name cannot meet the |
19 | | * naming conventions. |
20 | | */ |
21 | | |
22 | | // A thread local context for gathering io-stats efficiently and transparently. |
23 | | // Use SetPerfLevel(PerfLevel::kEnableTime) to enable time stats. |
24 | | // |
25 | | |
26 | | namespace ROCKSDB_NAMESPACE { |
27 | | |
28 | | // EXPERIMENTAL: the IO statistics for tiered storage. It matches with each |
29 | | // item in Temperature class. |
30 | | struct FileIOByTemperature { |
31 | | // the number of bytes read to Temperature::kHot file |
32 | | uint64_t hot_file_bytes_read; |
33 | | // the number of bytes read to Temperature::kWarm file |
34 | | uint64_t warm_file_bytes_read; |
35 | | // the number of bytes read to Temperature::kCool file |
36 | | uint64_t cool_file_bytes_read; |
37 | | // the number of bytes read to Temperature::kCold file |
38 | | uint64_t cold_file_bytes_read; |
39 | | // the number of bytes read to Temperature::kIce file |
40 | | uint64_t ice_file_bytes_read; |
41 | | // the number of bytes read to Temperature::kUnknown file not in last level |
42 | | uint64_t unknown_non_last_level_bytes_read; |
43 | | // the number of bytes read to Temperature::kUnknown file in last level |
44 | | uint64_t unknown_last_level_bytes_read; |
45 | | // total number of reads to Temperature::kHot file |
46 | | uint64_t hot_file_read_count; |
47 | | // total number of reads to Temperature::kWarm file |
48 | | uint64_t warm_file_read_count; |
49 | | // total number of reads to Temperature::kCool file |
50 | | uint64_t cool_file_read_count; |
51 | | // total number of reads to Temperature::kCold file |
52 | | uint64_t cold_file_read_count; |
53 | | // total number of reads to Temperature::kIce file |
54 | | uint64_t ice_file_read_count; |
55 | | // total number of reads to Temperature::kUnknown file not in last level |
56 | | uint64_t unknown_non_last_level_read_count; |
57 | | // total number of reads to Temperature::kUnknown file in last level |
58 | | uint64_t unknown_last_level_read_count; |
59 | | |
60 | | // reset all the statistics to 0. |
61 | 0 | void Reset() { |
62 | 0 | hot_file_bytes_read = 0; |
63 | 0 | warm_file_bytes_read = 0; |
64 | 0 | cool_file_bytes_read = 0; |
65 | 0 | cold_file_bytes_read = 0; |
66 | 0 | ice_file_bytes_read = 0; |
67 | 0 | unknown_non_last_level_bytes_read = 0; |
68 | 0 | unknown_last_level_bytes_read = 0; |
69 | 0 | hot_file_read_count = 0; |
70 | 0 | warm_file_read_count = 0; |
71 | 0 | cool_file_read_count = 0; |
72 | 0 | cold_file_read_count = 0; |
73 | 0 | ice_file_read_count = 0; |
74 | 0 | unknown_non_last_level_read_count = 0; |
75 | 0 | unknown_last_level_read_count = 0; |
76 | 0 | } |
77 | | }; |
78 | | |
79 | | struct IOStatsContext { |
80 | | // reset all io-stats counter to zero |
81 | | void Reset(); |
82 | | |
83 | | std::string ToString(bool exclude_zero_counters = false) const; |
84 | | |
85 | | // the thread pool id |
86 | | uint64_t thread_pool_id; |
87 | | |
88 | | // number of bytes that has been written. |
89 | | uint64_t bytes_written; |
90 | | // number of bytes that has been read. |
91 | | uint64_t bytes_read; |
92 | | |
93 | | // time spent in open() and fopen(). |
94 | | uint64_t open_nanos; |
95 | | // time spent in fallocate(). |
96 | | uint64_t allocate_nanos; |
97 | | // time spent in write() and pwrite(). |
98 | | uint64_t write_nanos; |
99 | | // time spent in read() and pread() |
100 | | uint64_t read_nanos; |
101 | | // time spent in sync_file_range(). |
102 | | uint64_t range_sync_nanos; |
103 | | // time spent in fsync |
104 | | uint64_t fsync_nanos; |
105 | | // time spent in preparing write (fallocate etc). |
106 | | uint64_t prepare_write_nanos; |
107 | | // time spent in Logger::Logv(). |
108 | | uint64_t logger_nanos; |
109 | | // CPU time spent in write() and pwrite() |
110 | | uint64_t cpu_write_nanos; |
111 | | // CPU time spent in read() and pread() |
112 | | uint64_t cpu_read_nanos; |
113 | | |
114 | | FileIOByTemperature file_io_stats_by_temperature; |
115 | | |
116 | | // It is not consistent that whether iostats follows PerfLevel.Timer counters |
117 | | // follows it but BackupEngine relies on counter metrics to always be there. |
118 | | // Here we create a backdoor option to disable some counters, so that some |
119 | | // existing stats are not polluted by file operations, such as logging, by |
120 | | // turning this off. |
121 | | bool disable_iostats = false; |
122 | | }; |
123 | | |
124 | | // If RocksDB is compiled with -DNIOSTATS_CONTEXT, then a pointer to a global, |
125 | | // non-thread-local IOStatsContext object will be returned. Attempts to update |
126 | | // this object will be ignored, and reading from it will also be no-op. |
127 | | // Otherwise, a pointer to a thread-local IOStatsContext object will be |
128 | | // returned. |
129 | | // |
130 | | // This function never returns nullptr. |
131 | | IOStatsContext* get_iostats_context(); |
132 | | |
133 | | } // namespace ROCKSDB_NAMESPACE |