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 #include <string>
9 
10 #include "rocksdb/perf_level.h"
11 
12 // A thread local context for gathering io-stats efficiently and transparently.
13 // Use SetPerfLevel(PerfLevel::kEnableTime) to enable time stats.
14 
15 namespace ROCKSDB_NAMESPACE {
16 
17 struct IOStatsContext {
18   // reset all io-stats counter to zero
19   void Reset();
20 
21   std::string ToString(bool exclude_zero_counters = false) const;
22 
23   // the thread pool id
24   uint64_t thread_pool_id;
25 
26   // number of bytes that has been written.
27   uint64_t bytes_written;
28   // number of bytes that has been read.
29   uint64_t bytes_read;
30 
31   // time spent in open() and fopen().
32   uint64_t open_nanos;
33   // time spent in fallocate().
34   uint64_t allocate_nanos;
35   // time spent in write() and pwrite().
36   uint64_t write_nanos;
37   // time spent in read() and pread()
38   uint64_t read_nanos;
39   // time spent in sync_file_range().
40   uint64_t range_sync_nanos;
41   // time spent in fsync
42   uint64_t fsync_nanos;
43   // time spent in preparing write (fallocate etc).
44   uint64_t prepare_write_nanos;
45   // time spent in Logger::Logv().
46   uint64_t logger_nanos;
47   // CPU time spent in write() and pwrite()
48   uint64_t cpu_write_nanos;
49   // CPU time spent in read() and pread()
50   uint64_t cpu_read_nanos;
51 };
52 
53 // Get Thread-local IOStatsContext object pointer
54 IOStatsContext* get_iostats_context();
55 
56 }  // namespace ROCKSDB_NAMESPACE
57