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).
11 #include "rocksdb/perf_level.h"
13 // A thread local context for gathering io-stats efficiently and transparently.
14 // Use SetPerfLevel(PerfLevel::kEnableTime) to enable time stats.
16 namespace ROCKSDB_NAMESPACE
{
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.
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;
44 struct IOStatsContext
{
45 // reset all io-stats counter to zero
48 std::string
ToString(bool exclude_zero_counters
= false) const;
51 uint64_t thread_pool_id
;
53 // number of bytes that has been written.
54 uint64_t bytes_written
;
55 // number of bytes that has been read.
58 // time spent in open() and fopen().
60 // time spent in fallocate().
61 uint64_t allocate_nanos
;
62 // time spent in write() and pwrite().
64 // time spent in read() and pread()
66 // time spent in sync_file_range().
67 uint64_t range_sync_nanos
;
68 // time spent in fsync
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
;
79 FileIOByTemperature file_io_stats_by_temperature
;
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
86 bool disable_iostats
= false;
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
95 // This function never returns nullptr.
96 IOStatsContext
* get_iostats_context();
98 } // namespace ROCKSDB_NAMESPACE