1 | /* |
2 | Portions Copyright (c) 2015-Present, Facebook, Inc. |
3 | Portions Copyright (c) 2012,2013 Monty Program Ab |
4 | |
5 | This program is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published by |
7 | the Free Software Foundation; version 2 of the License. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ |
17 | #pragma once |
18 | |
19 | /* C++ standard header files */ |
20 | #include <atomic> |
21 | #include <cstdint> |
22 | #include <string> |
23 | |
24 | /* MySQL header files */ |
25 | #include "./handler.h" |
26 | #include <my_global.h> |
27 | |
28 | #include "rdb_mariadb_port.h" |
29 | |
30 | namespace myrocks { |
31 | |
32 | enum { |
33 | PC_USER_KEY_COMPARISON_COUNT = 0, |
34 | PC_BLOCK_CACHE_HIT_COUNT, |
35 | PC_BLOCK_READ_COUNT, |
36 | PC_BLOCK_READ_BYTE, |
37 | PC_BLOCK_READ_TIME, |
38 | PC_BLOCK_CHECKSUM_TIME, |
39 | PC_BLOCK_DECOMPRESS_TIME, |
40 | PC_GET_READ_BYTES, |
41 | PC_MULTIGET_READ_BYTES, |
42 | PC_ITER_READ_BYTES, |
43 | PC_KEY_SKIPPED, |
44 | PC_DELETE_SKIPPED, |
45 | PC_RECENT_SKIPPED, |
46 | PC_MERGE, |
47 | PC_GET_SNAPSHOT_TIME, |
48 | PC_GET_FROM_MEMTABLE_TIME, |
49 | PC_GET_FROM_MEMTABLE_COUNT, |
50 | PC_GET_POST_PROCESS_TIME, |
51 | PC_GET_FROM_OUTPUT_FILES_TIME, |
52 | PC_SEEK_ON_MEMTABLE_TIME, |
53 | PC_SEEK_ON_MEMTABLE_COUNT, |
54 | PC_NEXT_ON_MEMTABLE_COUNT, |
55 | PC_PREV_ON_MEMTABLE_COUNT, |
56 | PC_SEEK_CHILD_SEEK_TIME, |
57 | PC_SEEK_CHILD_SEEK_COUNT, |
58 | PC_SEEK_MIN_HEAP_TIME, |
59 | PC_SEEK_MAX_HEAP_TIME, |
60 | PC_SEEK_INTERNAL_SEEK_TIME, |
61 | PC_FIND_NEXT_USER_ENTRY_TIME, |
62 | PC_WRITE_WAL_TIME, |
63 | PC_WRITE_MEMTABLE_TIME, |
64 | PC_WRITE_DELAY_TIME, |
65 | PC_WRITE_PRE_AND_POST_PROCESSS_TIME, |
66 | PC_DB_MUTEX_LOCK_NANOS, |
67 | PC_DB_CONDITION_WAIT_NANOS, |
68 | PC_MERGE_OPERATOR_TIME_NANOS, |
69 | PC_READ_INDEX_BLOCK_NANOS, |
70 | PC_READ_FILTER_BLOCK_NANOS, |
71 | PC_NEW_TABLE_BLOCK_ITER_NANOS, |
72 | PC_NEW_TABLE_ITERATOR_NANOS, |
73 | PC_BLOCK_SEEK_NANOS, |
74 | PC_FIND_TABLE_NANOS, |
75 | PC_BLOOM_MEMTABLE_HIT_COUNT, |
76 | PC_BLOOM_MEMTABLE_MISS_COUNT, |
77 | PC_BLOOM_SST_HIT_COUNT, |
78 | PC_BLOOM_SST_MISS_COUNT, |
79 | PC_KEY_LOCK_WAIT_TIME, |
80 | PC_KEY_LOCK_WAIT_COUNT, |
81 | PC_IO_THREAD_POOL_ID, |
82 | PC_IO_BYTES_WRITTEN, |
83 | PC_IO_BYTES_READ, |
84 | PC_IO_OPEN_NANOS, |
85 | PC_IO_ALLOCATE_NANOS, |
86 | PC_IO_WRITE_NANOS, |
87 | PC_IO_READ_NANOS, |
88 | PC_IO_RANGE_SYNC_NANOS, |
89 | PC_IO_LOGGER_NANOS, |
90 | PC_MAX_IDX |
91 | }; |
92 | |
93 | class Rdb_perf_counters; |
94 | |
95 | /* |
96 | A collection of performance counters that can be safely incremented by |
97 | multiple threads since it stores atomic datapoints. |
98 | */ |
99 | struct Rdb_atomic_perf_counters { |
100 | std::atomic_ullong m_value[PC_MAX_IDX]; |
101 | }; |
102 | |
103 | /* |
104 | A collection of performance counters that is meant to be incremented by |
105 | a single thread. |
106 | */ |
107 | class Rdb_perf_counters { |
108 | Rdb_perf_counters(const Rdb_perf_counters &) = delete; |
109 | Rdb_perf_counters &operator=(const Rdb_perf_counters &) = delete; |
110 | |
111 | public: |
112 | Rdb_perf_counters() = default; |
113 | uint64_t m_value[PC_MAX_IDX]; |
114 | |
115 | void load(const Rdb_atomic_perf_counters &atomic_counters); |
116 | }; |
117 | |
118 | extern std::string rdb_pc_stat_types[PC_MAX_IDX]; |
119 | |
120 | /* |
121 | Perf timers for data reads |
122 | */ |
123 | class Rdb_io_perf { |
124 | // Context management |
125 | Rdb_atomic_perf_counters *m_atomic_counters = nullptr; |
126 | my_io_perf_atomic_t *m_shared_io_perf_read = nullptr; |
127 | my_io_perf_atomic_t *m_shared_io_perf_write = nullptr; |
128 | ha_statistics *m_stats = nullptr; |
129 | |
130 | uint64_t io_write_bytes; |
131 | uint64_t io_write_requests; |
132 | |
133 | public: |
134 | Rdb_io_perf(const Rdb_io_perf &) = delete; |
135 | Rdb_io_perf &operator=(const Rdb_io_perf &) = delete; |
136 | |
137 | void init(Rdb_atomic_perf_counters *const atomic_counters, |
138 | my_io_perf_atomic_t *const shared_io_perf_read, |
139 | my_io_perf_atomic_t *const shared_io_perf_write, |
140 | ha_statistics *const stats) { |
141 | DBUG_ASSERT(atomic_counters != nullptr); |
142 | DBUG_ASSERT(shared_io_perf_read != nullptr); |
143 | DBUG_ASSERT(shared_io_perf_write != nullptr); |
144 | DBUG_ASSERT(stats != nullptr); |
145 | |
146 | m_atomic_counters = atomic_counters; |
147 | m_shared_io_perf_read = shared_io_perf_read; |
148 | m_shared_io_perf_write = shared_io_perf_write; |
149 | m_stats = stats; |
150 | |
151 | io_write_bytes = 0; |
152 | io_write_requests = 0; |
153 | } |
154 | |
155 | bool start(const uint32_t perf_context_level); |
156 | void update_bytes_written(const uint32_t perf_context_level, |
157 | ulonglong bytes_written); |
158 | void end_and_record(const uint32_t perf_context_level); |
159 | |
160 | explicit Rdb_io_perf() |
161 | : m_atomic_counters(nullptr), m_shared_io_perf_read(nullptr), |
162 | m_stats(nullptr), io_write_bytes(0), io_write_requests(0) {} |
163 | }; |
164 | |
165 | } // namespace myrocks |
166 | |