]> git.proxmox.com Git - ceph.git/blob - ceph/src/rocksdb/include/rocksdb/iostats_context.h
559d44c57a6c526de325b0d7ba92eec68c1cf205
[ceph.git] / ceph / src / rocksdb / include / rocksdb / iostats_context.h
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 // A thread local context for gathering io-stats efficiently and transparently.
14 // Use SetPerfLevel(PerfLevel::kEnableTime) to enable time stats.
15
16 namespace ROCKSDB_NAMESPACE {
17
18 // EXPERIMENTAL: the IO statistics for tiered storage. It matches with each
19 // item in Temperature class.
20 struct FileIOByTemperature {
21 // the number of bytes read to Temperature::kHot file
22 uint64_t hot_file_bytes_read;
23 // the number of bytes read to Temperature::kWarm file
24 uint64_t warm_file_bytes_read;
25 // the number of bytes read to Temperature::kCold file
26 uint64_t cold_file_bytes_read;
27 // total number of reads to Temperature::kHot file
28 uint64_t hot_file_read_count;
29 // total number of reads to Temperature::kWarm file
30 uint64_t warm_file_read_count;
31 // total number of reads to Temperature::kCold file
32 uint64_t cold_file_read_count;
33 // reset all the statistics to 0.
34 void Reset() {
35 hot_file_bytes_read = 0;
36 warm_file_bytes_read = 0;
37 cold_file_bytes_read = 0;
38 hot_file_read_count = 0;
39 warm_file_read_count = 0;
40 cold_file_read_count = 0;
41 }
42 };
43
44 struct IOStatsContext {
45 // reset all io-stats counter to zero
46 void Reset();
47
48 std::string ToString(bool exclude_zero_counters = false) const;
49
50 // the thread pool id
51 uint64_t thread_pool_id;
52
53 // number of bytes that has been written.
54 uint64_t bytes_written;
55 // number of bytes that has been read.
56 uint64_t bytes_read;
57
58 // time spent in open() and fopen().
59 uint64_t open_nanos;
60 // time spent in fallocate().
61 uint64_t allocate_nanos;
62 // time spent in write() and pwrite().
63 uint64_t write_nanos;
64 // time spent in read() and pread()
65 uint64_t read_nanos;
66 // time spent in sync_file_range().
67 uint64_t range_sync_nanos;
68 // time spent in fsync
69 uint64_t fsync_nanos;
70 // time spent in preparing write (fallocate etc).
71 uint64_t prepare_write_nanos;
72 // time spent in Logger::Logv().
73 uint64_t logger_nanos;
74 // CPU time spent in write() and pwrite()
75 uint64_t cpu_write_nanos;
76 // CPU time spent in read() and pread()
77 uint64_t cpu_read_nanos;
78
79 FileIOByTemperature file_io_stats_by_temperature;
80
81 // It is not consistent that whether iostats follows PerfLevel.Timer counters
82 // follows it but BackupEngine relies on counter metrics to always be there.
83 // Here we create a backdoor option to disable some counters, so that some
84 // existing stats are not polluted by file operations, such as logging, by
85 // turning this off.
86 bool disable_iostats = false;
87 };
88
89 // If RocksDB is compiled with -DNIOSTATS_CONTEXT, then a pointer to a global,
90 // non-thread-local IOStatsContext object will be returned. Attempts to update
91 // this object will be ignored, and reading from it will also be no-op.
92 // Otherwise, a pointer to a thread-local IOStatsContext object will be
93 // returned.
94 //
95 // This function never returns nullptr.
96 IOStatsContext* get_iostats_context();
97
98 } // namespace ROCKSDB_NAMESPACE