]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | // Copyright (c) 2011-present, Facebook, Inc. All rights reserved. |
11fdf7f2 TL |
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). | |
7c673cae FG |
5 | // |
6 | ||
7 | #include <sstream> | |
1e59de90 | 8 | |
7c673cae FG |
9 | #include "monitoring/perf_context_imp.h" |
10 | ||
f67539c2 | 11 | namespace ROCKSDB_NAMESPACE { |
7c673cae | 12 | |
1e59de90 TL |
13 | #if defined(NPERF_CONTEXT) |
14 | // Should not be used because the counters are not thread-safe. | |
15 | // Put here just to make get_perf_context() simple without ifdef. | |
11fdf7f2 | 16 | PerfContext perf_context; |
7c673cae | 17 | #else |
494da23a | 18 | thread_local PerfContext perf_context; |
11fdf7f2 | 19 | #endif |
11fdf7f2 | 20 | |
1e59de90 | 21 | PerfContext* get_perf_context() { return &perf_context; } |
7c673cae | 22 | |
494da23a | 23 | PerfContext::~PerfContext() { |
1e59de90 | 24 | #if !defined(NPERF_CONTEXT) && !defined(OS_SOLARIS) |
494da23a TL |
25 | ClearPerLevelPerfContext(); |
26 | #endif | |
27 | } | |
28 | ||
29 | PerfContext::PerfContext(const PerfContext& other) { | |
20effc67 TL |
30 | #ifdef NPERF_CONTEXT |
31 | (void)other; | |
32 | #else | |
494da23a TL |
33 | user_key_comparison_count = other.user_key_comparison_count; |
34 | block_cache_hit_count = other.block_cache_hit_count; | |
35 | block_read_count = other.block_read_count; | |
36 | block_read_byte = other.block_read_byte; | |
37 | block_read_time = other.block_read_time; | |
38 | block_cache_index_hit_count = other.block_cache_index_hit_count; | |
1e59de90 TL |
39 | block_cache_standalone_handle_count = |
40 | other.block_cache_standalone_handle_count; | |
41 | block_cache_real_handle_count = other.block_cache_real_handle_count; | |
494da23a TL |
42 | index_block_read_count = other.index_block_read_count; |
43 | block_cache_filter_hit_count = other.block_cache_filter_hit_count; | |
44 | filter_block_read_count = other.filter_block_read_count; | |
45 | compression_dict_block_read_count = other.compression_dict_block_read_count; | |
1e59de90 TL |
46 | secondary_cache_hit_count = other.secondary_cache_hit_count; |
47 | compressed_sec_cache_insert_real_count = | |
48 | other.compressed_sec_cache_insert_real_count; | |
49 | compressed_sec_cache_insert_dummy_count = | |
50 | other.compressed_sec_cache_insert_dummy_count; | |
51 | compressed_sec_cache_uncompressed_bytes = | |
52 | other.compressed_sec_cache_uncompressed_bytes; | |
53 | compressed_sec_cache_compressed_bytes = | |
54 | other.compressed_sec_cache_compressed_bytes; | |
494da23a TL |
55 | block_checksum_time = other.block_checksum_time; |
56 | block_decompress_time = other.block_decompress_time; | |
57 | get_read_bytes = other.get_read_bytes; | |
58 | multiget_read_bytes = other.multiget_read_bytes; | |
59 | iter_read_bytes = other.iter_read_bytes; | |
1e59de90 TL |
60 | |
61 | blob_cache_hit_count = other.blob_cache_hit_count; | |
62 | blob_read_count = other.blob_read_count; | |
63 | blob_read_byte = other.blob_read_byte; | |
64 | blob_read_time = other.blob_read_time; | |
65 | blob_checksum_time = other.blob_checksum_time; | |
66 | blob_decompress_time = other.blob_decompress_time; | |
67 | ||
494da23a TL |
68 | internal_key_skipped_count = other.internal_key_skipped_count; |
69 | internal_delete_skipped_count = other.internal_delete_skipped_count; | |
70 | internal_recent_skipped_count = other.internal_recent_skipped_count; | |
71 | internal_merge_count = other.internal_merge_count; | |
1e59de90 | 72 | internal_range_del_reseek_count = other.internal_range_del_reseek_count; |
494da23a TL |
73 | write_wal_time = other.write_wal_time; |
74 | get_snapshot_time = other.get_snapshot_time; | |
75 | get_from_memtable_time = other.get_from_memtable_time; | |
76 | get_from_memtable_count = other.get_from_memtable_count; | |
77 | get_post_process_time = other.get_post_process_time; | |
78 | get_from_output_files_time = other.get_from_output_files_time; | |
79 | seek_on_memtable_time = other.seek_on_memtable_time; | |
80 | seek_on_memtable_count = other.seek_on_memtable_count; | |
81 | next_on_memtable_count = other.next_on_memtable_count; | |
82 | prev_on_memtable_count = other.prev_on_memtable_count; | |
83 | seek_child_seek_time = other.seek_child_seek_time; | |
84 | seek_child_seek_count = other.seek_child_seek_count; | |
85 | seek_min_heap_time = other.seek_min_heap_time; | |
86 | seek_internal_seek_time = other.seek_internal_seek_time; | |
87 | find_next_user_entry_time = other.find_next_user_entry_time; | |
88 | write_pre_and_post_process_time = other.write_pre_and_post_process_time; | |
89 | write_memtable_time = other.write_memtable_time; | |
90 | write_delay_time = other.write_delay_time; | |
91 | write_thread_wait_nanos = other.write_thread_wait_nanos; | |
92 | write_scheduling_flushes_compactions_time = | |
93 | other.write_scheduling_flushes_compactions_time; | |
94 | db_mutex_lock_nanos = other.db_mutex_lock_nanos; | |
95 | db_condition_wait_nanos = other.db_condition_wait_nanos; | |
96 | merge_operator_time_nanos = other.merge_operator_time_nanos; | |
97 | read_index_block_nanos = other.read_index_block_nanos; | |
98 | read_filter_block_nanos = other.read_filter_block_nanos; | |
99 | new_table_block_iter_nanos = other.new_table_block_iter_nanos; | |
100 | new_table_iterator_nanos = other.new_table_iterator_nanos; | |
101 | block_seek_nanos = other.block_seek_nanos; | |
102 | find_table_nanos = other.find_table_nanos; | |
103 | bloom_memtable_hit_count = other.bloom_memtable_hit_count; | |
104 | bloom_memtable_miss_count = other.bloom_memtable_miss_count; | |
105 | bloom_sst_hit_count = other.bloom_sst_hit_count; | |
106 | bloom_sst_miss_count = other.bloom_sst_miss_count; | |
107 | key_lock_wait_time = other.key_lock_wait_time; | |
108 | key_lock_wait_count = other.key_lock_wait_count; | |
109 | ||
110 | env_new_sequential_file_nanos = other.env_new_sequential_file_nanos; | |
111 | env_new_random_access_file_nanos = other.env_new_random_access_file_nanos; | |
112 | env_new_writable_file_nanos = other.env_new_writable_file_nanos; | |
113 | env_reuse_writable_file_nanos = other.env_reuse_writable_file_nanos; | |
114 | env_new_random_rw_file_nanos = other.env_new_random_rw_file_nanos; | |
115 | env_new_directory_nanos = other.env_new_directory_nanos; | |
116 | env_file_exists_nanos = other.env_file_exists_nanos; | |
117 | env_get_children_nanos = other.env_get_children_nanos; | |
118 | env_get_children_file_attributes_nanos = | |
119 | other.env_get_children_file_attributes_nanos; | |
120 | env_delete_file_nanos = other.env_delete_file_nanos; | |
121 | env_create_dir_nanos = other.env_create_dir_nanos; | |
122 | env_create_dir_if_missing_nanos = other.env_create_dir_if_missing_nanos; | |
123 | env_delete_dir_nanos = other.env_delete_dir_nanos; | |
124 | env_get_file_size_nanos = other.env_get_file_size_nanos; | |
125 | env_get_file_modification_time_nanos = | |
126 | other.env_get_file_modification_time_nanos; | |
127 | env_rename_file_nanos = other.env_rename_file_nanos; | |
128 | env_link_file_nanos = other.env_link_file_nanos; | |
129 | env_lock_file_nanos = other.env_lock_file_nanos; | |
130 | env_unlock_file_nanos = other.env_unlock_file_nanos; | |
131 | env_new_logger_nanos = other.env_new_logger_nanos; | |
132 | get_cpu_nanos = other.get_cpu_nanos; | |
133 | iter_next_cpu_nanos = other.iter_next_cpu_nanos; | |
134 | iter_prev_cpu_nanos = other.iter_prev_cpu_nanos; | |
135 | iter_seek_cpu_nanos = other.iter_seek_cpu_nanos; | |
1e59de90 | 136 | number_async_seek = other.number_async_seek; |
494da23a TL |
137 | if (per_level_perf_context_enabled && level_to_perf_context != nullptr) { |
138 | ClearPerLevelPerfContext(); | |
139 | } | |
140 | if (other.level_to_perf_context != nullptr) { | |
141 | level_to_perf_context = new std::map<uint32_t, PerfContextByLevel>(); | |
142 | *level_to_perf_context = *other.level_to_perf_context; | |
143 | } | |
144 | per_level_perf_context_enabled = other.per_level_perf_context_enabled; | |
145 | #endif | |
146 | } | |
147 | ||
148 | PerfContext::PerfContext(PerfContext&& other) noexcept { | |
20effc67 TL |
149 | #ifdef NPERF_CONTEXT |
150 | (void)other; | |
151 | #else | |
494da23a TL |
152 | user_key_comparison_count = other.user_key_comparison_count; |
153 | block_cache_hit_count = other.block_cache_hit_count; | |
154 | block_read_count = other.block_read_count; | |
155 | block_read_byte = other.block_read_byte; | |
156 | block_read_time = other.block_read_time; | |
157 | block_cache_index_hit_count = other.block_cache_index_hit_count; | |
1e59de90 TL |
158 | block_cache_standalone_handle_count = |
159 | other.block_cache_standalone_handle_count; | |
160 | block_cache_real_handle_count = other.block_cache_real_handle_count; | |
494da23a TL |
161 | index_block_read_count = other.index_block_read_count; |
162 | block_cache_filter_hit_count = other.block_cache_filter_hit_count; | |
163 | filter_block_read_count = other.filter_block_read_count; | |
164 | compression_dict_block_read_count = other.compression_dict_block_read_count; | |
1e59de90 TL |
165 | secondary_cache_hit_count = other.secondary_cache_hit_count; |
166 | compressed_sec_cache_insert_real_count = | |
167 | other.compressed_sec_cache_insert_real_count; | |
168 | compressed_sec_cache_insert_dummy_count = | |
169 | other.compressed_sec_cache_insert_dummy_count; | |
170 | compressed_sec_cache_uncompressed_bytes = | |
171 | other.compressed_sec_cache_uncompressed_bytes; | |
172 | compressed_sec_cache_compressed_bytes = | |
173 | other.compressed_sec_cache_compressed_bytes; | |
494da23a TL |
174 | block_checksum_time = other.block_checksum_time; |
175 | block_decompress_time = other.block_decompress_time; | |
176 | get_read_bytes = other.get_read_bytes; | |
177 | multiget_read_bytes = other.multiget_read_bytes; | |
178 | iter_read_bytes = other.iter_read_bytes; | |
1e59de90 TL |
179 | |
180 | blob_cache_hit_count = other.blob_cache_hit_count; | |
181 | blob_read_count = other.blob_read_count; | |
182 | blob_read_byte = other.blob_read_byte; | |
183 | blob_read_time = other.blob_read_time; | |
184 | blob_checksum_time = other.blob_checksum_time; | |
185 | blob_decompress_time = other.blob_decompress_time; | |
186 | ||
494da23a TL |
187 | internal_key_skipped_count = other.internal_key_skipped_count; |
188 | internal_delete_skipped_count = other.internal_delete_skipped_count; | |
189 | internal_recent_skipped_count = other.internal_recent_skipped_count; | |
190 | internal_merge_count = other.internal_merge_count; | |
1e59de90 | 191 | internal_range_del_reseek_count = other.internal_range_del_reseek_count; |
494da23a TL |
192 | write_wal_time = other.write_wal_time; |
193 | get_snapshot_time = other.get_snapshot_time; | |
194 | get_from_memtable_time = other.get_from_memtable_time; | |
195 | get_from_memtable_count = other.get_from_memtable_count; | |
196 | get_post_process_time = other.get_post_process_time; | |
197 | get_from_output_files_time = other.get_from_output_files_time; | |
198 | seek_on_memtable_time = other.seek_on_memtable_time; | |
199 | seek_on_memtable_count = other.seek_on_memtable_count; | |
200 | next_on_memtable_count = other.next_on_memtable_count; | |
201 | prev_on_memtable_count = other.prev_on_memtable_count; | |
202 | seek_child_seek_time = other.seek_child_seek_time; | |
203 | seek_child_seek_count = other.seek_child_seek_count; | |
204 | seek_min_heap_time = other.seek_min_heap_time; | |
205 | seek_internal_seek_time = other.seek_internal_seek_time; | |
206 | find_next_user_entry_time = other.find_next_user_entry_time; | |
207 | write_pre_and_post_process_time = other.write_pre_and_post_process_time; | |
208 | write_memtable_time = other.write_memtable_time; | |
209 | write_delay_time = other.write_delay_time; | |
210 | write_thread_wait_nanos = other.write_thread_wait_nanos; | |
211 | write_scheduling_flushes_compactions_time = | |
212 | other.write_scheduling_flushes_compactions_time; | |
213 | db_mutex_lock_nanos = other.db_mutex_lock_nanos; | |
214 | db_condition_wait_nanos = other.db_condition_wait_nanos; | |
215 | merge_operator_time_nanos = other.merge_operator_time_nanos; | |
216 | read_index_block_nanos = other.read_index_block_nanos; | |
217 | read_filter_block_nanos = other.read_filter_block_nanos; | |
218 | new_table_block_iter_nanos = other.new_table_block_iter_nanos; | |
219 | new_table_iterator_nanos = other.new_table_iterator_nanos; | |
220 | block_seek_nanos = other.block_seek_nanos; | |
221 | find_table_nanos = other.find_table_nanos; | |
222 | bloom_memtable_hit_count = other.bloom_memtable_hit_count; | |
223 | bloom_memtable_miss_count = other.bloom_memtable_miss_count; | |
224 | bloom_sst_hit_count = other.bloom_sst_hit_count; | |
225 | bloom_sst_miss_count = other.bloom_sst_miss_count; | |
226 | key_lock_wait_time = other.key_lock_wait_time; | |
227 | key_lock_wait_count = other.key_lock_wait_count; | |
228 | ||
229 | env_new_sequential_file_nanos = other.env_new_sequential_file_nanos; | |
230 | env_new_random_access_file_nanos = other.env_new_random_access_file_nanos; | |
231 | env_new_writable_file_nanos = other.env_new_writable_file_nanos; | |
232 | env_reuse_writable_file_nanos = other.env_reuse_writable_file_nanos; | |
233 | env_new_random_rw_file_nanos = other.env_new_random_rw_file_nanos; | |
234 | env_new_directory_nanos = other.env_new_directory_nanos; | |
235 | env_file_exists_nanos = other.env_file_exists_nanos; | |
236 | env_get_children_nanos = other.env_get_children_nanos; | |
237 | env_get_children_file_attributes_nanos = | |
238 | other.env_get_children_file_attributes_nanos; | |
239 | env_delete_file_nanos = other.env_delete_file_nanos; | |
240 | env_create_dir_nanos = other.env_create_dir_nanos; | |
241 | env_create_dir_if_missing_nanos = other.env_create_dir_if_missing_nanos; | |
242 | env_delete_dir_nanos = other.env_delete_dir_nanos; | |
243 | env_get_file_size_nanos = other.env_get_file_size_nanos; | |
244 | env_get_file_modification_time_nanos = | |
245 | other.env_get_file_modification_time_nanos; | |
246 | env_rename_file_nanos = other.env_rename_file_nanos; | |
247 | env_link_file_nanos = other.env_link_file_nanos; | |
248 | env_lock_file_nanos = other.env_lock_file_nanos; | |
249 | env_unlock_file_nanos = other.env_unlock_file_nanos; | |
250 | env_new_logger_nanos = other.env_new_logger_nanos; | |
251 | get_cpu_nanos = other.get_cpu_nanos; | |
252 | iter_next_cpu_nanos = other.iter_next_cpu_nanos; | |
253 | iter_prev_cpu_nanos = other.iter_prev_cpu_nanos; | |
254 | iter_seek_cpu_nanos = other.iter_seek_cpu_nanos; | |
1e59de90 | 255 | number_async_seek = other.number_async_seek; |
494da23a TL |
256 | if (per_level_perf_context_enabled && level_to_perf_context != nullptr) { |
257 | ClearPerLevelPerfContext(); | |
258 | } | |
259 | if (other.level_to_perf_context != nullptr) { | |
260 | level_to_perf_context = other.level_to_perf_context; | |
261 | other.level_to_perf_context = nullptr; | |
262 | } | |
263 | per_level_perf_context_enabled = other.per_level_perf_context_enabled; | |
264 | #endif | |
265 | } | |
266 | ||
267 | // TODO(Zhongyi): reduce code duplication between copy constructor and | |
268 | // assignment operator | |
269 | PerfContext& PerfContext::operator=(const PerfContext& other) { | |
20effc67 TL |
270 | #ifdef NPERF_CONTEXT |
271 | (void)other; | |
272 | #else | |
494da23a TL |
273 | user_key_comparison_count = other.user_key_comparison_count; |
274 | block_cache_hit_count = other.block_cache_hit_count; | |
275 | block_read_count = other.block_read_count; | |
276 | block_read_byte = other.block_read_byte; | |
277 | block_read_time = other.block_read_time; | |
278 | block_cache_index_hit_count = other.block_cache_index_hit_count; | |
1e59de90 TL |
279 | block_cache_standalone_handle_count = |
280 | other.block_cache_standalone_handle_count; | |
281 | block_cache_real_handle_count = other.block_cache_real_handle_count; | |
494da23a TL |
282 | index_block_read_count = other.index_block_read_count; |
283 | block_cache_filter_hit_count = other.block_cache_filter_hit_count; | |
284 | filter_block_read_count = other.filter_block_read_count; | |
285 | compression_dict_block_read_count = other.compression_dict_block_read_count; | |
1e59de90 TL |
286 | secondary_cache_hit_count = other.secondary_cache_hit_count; |
287 | compressed_sec_cache_insert_real_count = | |
288 | other.compressed_sec_cache_insert_real_count; | |
289 | compressed_sec_cache_insert_dummy_count = | |
290 | other.compressed_sec_cache_insert_dummy_count; | |
291 | compressed_sec_cache_uncompressed_bytes = | |
292 | other.compressed_sec_cache_uncompressed_bytes; | |
293 | compressed_sec_cache_compressed_bytes = | |
294 | other.compressed_sec_cache_compressed_bytes; | |
494da23a TL |
295 | block_checksum_time = other.block_checksum_time; |
296 | block_decompress_time = other.block_decompress_time; | |
297 | get_read_bytes = other.get_read_bytes; | |
298 | multiget_read_bytes = other.multiget_read_bytes; | |
299 | iter_read_bytes = other.iter_read_bytes; | |
1e59de90 TL |
300 | |
301 | blob_cache_hit_count = other.blob_cache_hit_count; | |
302 | blob_read_count = other.blob_read_count; | |
303 | blob_read_byte = other.blob_read_byte; | |
304 | blob_read_time = other.blob_read_time; | |
305 | blob_checksum_time = other.blob_checksum_time; | |
306 | blob_decompress_time = other.blob_decompress_time; | |
307 | ||
494da23a TL |
308 | internal_key_skipped_count = other.internal_key_skipped_count; |
309 | internal_delete_skipped_count = other.internal_delete_skipped_count; | |
310 | internal_recent_skipped_count = other.internal_recent_skipped_count; | |
311 | internal_merge_count = other.internal_merge_count; | |
1e59de90 | 312 | internal_range_del_reseek_count = other.internal_range_del_reseek_count; |
494da23a TL |
313 | write_wal_time = other.write_wal_time; |
314 | get_snapshot_time = other.get_snapshot_time; | |
315 | get_from_memtable_time = other.get_from_memtable_time; | |
316 | get_from_memtable_count = other.get_from_memtable_count; | |
317 | get_post_process_time = other.get_post_process_time; | |
318 | get_from_output_files_time = other.get_from_output_files_time; | |
319 | seek_on_memtable_time = other.seek_on_memtable_time; | |
320 | seek_on_memtable_count = other.seek_on_memtable_count; | |
321 | next_on_memtable_count = other.next_on_memtable_count; | |
322 | prev_on_memtable_count = other.prev_on_memtable_count; | |
323 | seek_child_seek_time = other.seek_child_seek_time; | |
324 | seek_child_seek_count = other.seek_child_seek_count; | |
325 | seek_min_heap_time = other.seek_min_heap_time; | |
326 | seek_internal_seek_time = other.seek_internal_seek_time; | |
327 | find_next_user_entry_time = other.find_next_user_entry_time; | |
328 | write_pre_and_post_process_time = other.write_pre_and_post_process_time; | |
329 | write_memtable_time = other.write_memtable_time; | |
330 | write_delay_time = other.write_delay_time; | |
331 | write_thread_wait_nanos = other.write_thread_wait_nanos; | |
332 | write_scheduling_flushes_compactions_time = | |
333 | other.write_scheduling_flushes_compactions_time; | |
334 | db_mutex_lock_nanos = other.db_mutex_lock_nanos; | |
335 | db_condition_wait_nanos = other.db_condition_wait_nanos; | |
336 | merge_operator_time_nanos = other.merge_operator_time_nanos; | |
337 | read_index_block_nanos = other.read_index_block_nanos; | |
338 | read_filter_block_nanos = other.read_filter_block_nanos; | |
339 | new_table_block_iter_nanos = other.new_table_block_iter_nanos; | |
340 | new_table_iterator_nanos = other.new_table_iterator_nanos; | |
341 | block_seek_nanos = other.block_seek_nanos; | |
342 | find_table_nanos = other.find_table_nanos; | |
343 | bloom_memtable_hit_count = other.bloom_memtable_hit_count; | |
344 | bloom_memtable_miss_count = other.bloom_memtable_miss_count; | |
345 | bloom_sst_hit_count = other.bloom_sst_hit_count; | |
346 | bloom_sst_miss_count = other.bloom_sst_miss_count; | |
347 | key_lock_wait_time = other.key_lock_wait_time; | |
348 | key_lock_wait_count = other.key_lock_wait_count; | |
349 | ||
350 | env_new_sequential_file_nanos = other.env_new_sequential_file_nanos; | |
351 | env_new_random_access_file_nanos = other.env_new_random_access_file_nanos; | |
352 | env_new_writable_file_nanos = other.env_new_writable_file_nanos; | |
353 | env_reuse_writable_file_nanos = other.env_reuse_writable_file_nanos; | |
354 | env_new_random_rw_file_nanos = other.env_new_random_rw_file_nanos; | |
355 | env_new_directory_nanos = other.env_new_directory_nanos; | |
356 | env_file_exists_nanos = other.env_file_exists_nanos; | |
357 | env_get_children_nanos = other.env_get_children_nanos; | |
358 | env_get_children_file_attributes_nanos = | |
359 | other.env_get_children_file_attributes_nanos; | |
360 | env_delete_file_nanos = other.env_delete_file_nanos; | |
361 | env_create_dir_nanos = other.env_create_dir_nanos; | |
362 | env_create_dir_if_missing_nanos = other.env_create_dir_if_missing_nanos; | |
363 | env_delete_dir_nanos = other.env_delete_dir_nanos; | |
364 | env_get_file_size_nanos = other.env_get_file_size_nanos; | |
365 | env_get_file_modification_time_nanos = | |
366 | other.env_get_file_modification_time_nanos; | |
367 | env_rename_file_nanos = other.env_rename_file_nanos; | |
368 | env_link_file_nanos = other.env_link_file_nanos; | |
369 | env_lock_file_nanos = other.env_lock_file_nanos; | |
370 | env_unlock_file_nanos = other.env_unlock_file_nanos; | |
371 | env_new_logger_nanos = other.env_new_logger_nanos; | |
372 | get_cpu_nanos = other.get_cpu_nanos; | |
373 | iter_next_cpu_nanos = other.iter_next_cpu_nanos; | |
374 | iter_prev_cpu_nanos = other.iter_prev_cpu_nanos; | |
375 | iter_seek_cpu_nanos = other.iter_seek_cpu_nanos; | |
1e59de90 | 376 | number_async_seek = other.number_async_seek; |
494da23a TL |
377 | if (per_level_perf_context_enabled && level_to_perf_context != nullptr) { |
378 | ClearPerLevelPerfContext(); | |
379 | } | |
380 | if (other.level_to_perf_context != nullptr) { | |
381 | level_to_perf_context = new std::map<uint32_t, PerfContextByLevel>(); | |
382 | *level_to_perf_context = *other.level_to_perf_context; | |
383 | } | |
384 | per_level_perf_context_enabled = other.per_level_perf_context_enabled; | |
385 | #endif | |
386 | return *this; | |
387 | } | |
388 | ||
7c673cae | 389 | void PerfContext::Reset() { |
11fdf7f2 | 390 | #ifndef NPERF_CONTEXT |
7c673cae FG |
391 | user_key_comparison_count = 0; |
392 | block_cache_hit_count = 0; | |
393 | block_read_count = 0; | |
394 | block_read_byte = 0; | |
395 | block_read_time = 0; | |
494da23a | 396 | block_cache_index_hit_count = 0; |
1e59de90 TL |
397 | block_cache_standalone_handle_count = 0; |
398 | block_cache_real_handle_count = 0; | |
494da23a TL |
399 | index_block_read_count = 0; |
400 | block_cache_filter_hit_count = 0; | |
401 | filter_block_read_count = 0; | |
402 | compression_dict_block_read_count = 0; | |
1e59de90 TL |
403 | secondary_cache_hit_count = 0; |
404 | compressed_sec_cache_insert_real_count = 0; | |
405 | compressed_sec_cache_insert_dummy_count = 0; | |
406 | compressed_sec_cache_uncompressed_bytes = 0; | |
407 | compressed_sec_cache_compressed_bytes = 0; | |
7c673cae FG |
408 | block_checksum_time = 0; |
409 | block_decompress_time = 0; | |
11fdf7f2 TL |
410 | get_read_bytes = 0; |
411 | multiget_read_bytes = 0; | |
412 | iter_read_bytes = 0; | |
1e59de90 TL |
413 | |
414 | blob_cache_hit_count = 0; | |
415 | blob_read_count = 0; | |
416 | blob_read_byte = 0; | |
417 | blob_read_time = 0; | |
418 | blob_checksum_time = 0; | |
419 | blob_decompress_time = 0; | |
420 | ||
7c673cae FG |
421 | internal_key_skipped_count = 0; |
422 | internal_delete_skipped_count = 0; | |
423 | internal_recent_skipped_count = 0; | |
424 | internal_merge_count = 0; | |
1e59de90 | 425 | internal_range_del_reseek_count = 0; |
7c673cae FG |
426 | write_wal_time = 0; |
427 | ||
428 | get_snapshot_time = 0; | |
429 | get_from_memtable_time = 0; | |
430 | get_from_memtable_count = 0; | |
431 | get_post_process_time = 0; | |
432 | get_from_output_files_time = 0; | |
433 | seek_on_memtable_time = 0; | |
434 | seek_on_memtable_count = 0; | |
435 | next_on_memtable_count = 0; | |
436 | prev_on_memtable_count = 0; | |
437 | seek_child_seek_time = 0; | |
438 | seek_child_seek_count = 0; | |
439 | seek_min_heap_time = 0; | |
440 | seek_internal_seek_time = 0; | |
441 | find_next_user_entry_time = 0; | |
442 | write_pre_and_post_process_time = 0; | |
443 | write_memtable_time = 0; | |
444 | write_delay_time = 0; | |
11fdf7f2 TL |
445 | write_thread_wait_nanos = 0; |
446 | write_scheduling_flushes_compactions_time = 0; | |
7c673cae FG |
447 | db_mutex_lock_nanos = 0; |
448 | db_condition_wait_nanos = 0; | |
449 | merge_operator_time_nanos = 0; | |
450 | read_index_block_nanos = 0; | |
451 | read_filter_block_nanos = 0; | |
452 | new_table_block_iter_nanos = 0; | |
453 | new_table_iterator_nanos = 0; | |
454 | block_seek_nanos = 0; | |
455 | find_table_nanos = 0; | |
456 | bloom_memtable_hit_count = 0; | |
457 | bloom_memtable_miss_count = 0; | |
458 | bloom_sst_hit_count = 0; | |
459 | bloom_sst_miss_count = 0; | |
11fdf7f2 TL |
460 | key_lock_wait_time = 0; |
461 | key_lock_wait_count = 0; | |
7c673cae FG |
462 | |
463 | env_new_sequential_file_nanos = 0; | |
464 | env_new_random_access_file_nanos = 0; | |
465 | env_new_writable_file_nanos = 0; | |
466 | env_reuse_writable_file_nanos = 0; | |
467 | env_new_random_rw_file_nanos = 0; | |
468 | env_new_directory_nanos = 0; | |
469 | env_file_exists_nanos = 0; | |
470 | env_get_children_nanos = 0; | |
471 | env_get_children_file_attributes_nanos = 0; | |
472 | env_delete_file_nanos = 0; | |
473 | env_create_dir_nanos = 0; | |
474 | env_create_dir_if_missing_nanos = 0; | |
475 | env_delete_dir_nanos = 0; | |
476 | env_get_file_size_nanos = 0; | |
477 | env_get_file_modification_time_nanos = 0; | |
478 | env_rename_file_nanos = 0; | |
479 | env_link_file_nanos = 0; | |
480 | env_lock_file_nanos = 0; | |
481 | env_unlock_file_nanos = 0; | |
482 | env_new_logger_nanos = 0; | |
494da23a TL |
483 | get_cpu_nanos = 0; |
484 | iter_next_cpu_nanos = 0; | |
485 | iter_prev_cpu_nanos = 0; | |
486 | iter_seek_cpu_nanos = 0; | |
1e59de90 | 487 | number_async_seek = 0; |
494da23a TL |
488 | if (per_level_perf_context_enabled && level_to_perf_context) { |
489 | for (auto& kv : *level_to_perf_context) { | |
490 | kv.second.Reset(); | |
491 | } | |
492 | } | |
7c673cae FG |
493 | #endif |
494 | } | |
495 | ||
496 | #define PERF_CONTEXT_OUTPUT(counter) \ | |
497 | if (!exclude_zero_counters || (counter > 0)) { \ | |
498 | ss << #counter << " = " << counter << ", "; \ | |
499 | } | |
500 | ||
1e59de90 TL |
501 | #define PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(counter) \ |
502 | if (per_level_perf_context_enabled && level_to_perf_context) { \ | |
503 | ss << #counter << " = "; \ | |
504 | for (auto& kv : *level_to_perf_context) { \ | |
505 | if (!exclude_zero_counters || (kv.second.counter > 0)) { \ | |
506 | ss << kv.second.counter << "@level" << kv.first << ", "; \ | |
507 | } \ | |
508 | } \ | |
494da23a TL |
509 | } |
510 | ||
511 | void PerfContextByLevel::Reset() { | |
512 | #ifndef NPERF_CONTEXT | |
513 | bloom_filter_useful = 0; | |
514 | bloom_filter_full_positive = 0; | |
515 | bloom_filter_full_true_positive = 0; | |
516 | block_cache_hit_count = 0; | |
517 | block_cache_miss_count = 0; | |
518 | #endif | |
519 | } | |
520 | ||
7c673cae | 521 | std::string PerfContext::ToString(bool exclude_zero_counters) const { |
11fdf7f2 | 522 | #ifdef NPERF_CONTEXT |
20effc67 | 523 | (void)exclude_zero_counters; |
7c673cae FG |
524 | return ""; |
525 | #else | |
526 | std::ostringstream ss; | |
527 | PERF_CONTEXT_OUTPUT(user_key_comparison_count); | |
528 | PERF_CONTEXT_OUTPUT(block_cache_hit_count); | |
529 | PERF_CONTEXT_OUTPUT(block_read_count); | |
530 | PERF_CONTEXT_OUTPUT(block_read_byte); | |
531 | PERF_CONTEXT_OUTPUT(block_read_time); | |
494da23a | 532 | PERF_CONTEXT_OUTPUT(block_cache_index_hit_count); |
1e59de90 TL |
533 | PERF_CONTEXT_OUTPUT(block_cache_standalone_handle_count); |
534 | PERF_CONTEXT_OUTPUT(block_cache_real_handle_count); | |
494da23a TL |
535 | PERF_CONTEXT_OUTPUT(index_block_read_count); |
536 | PERF_CONTEXT_OUTPUT(block_cache_filter_hit_count); | |
537 | PERF_CONTEXT_OUTPUT(filter_block_read_count); | |
538 | PERF_CONTEXT_OUTPUT(compression_dict_block_read_count); | |
1e59de90 TL |
539 | PERF_CONTEXT_OUTPUT(secondary_cache_hit_count); |
540 | PERF_CONTEXT_OUTPUT(compressed_sec_cache_insert_real_count); | |
541 | PERF_CONTEXT_OUTPUT(compressed_sec_cache_insert_dummy_count); | |
542 | PERF_CONTEXT_OUTPUT(compressed_sec_cache_uncompressed_bytes); | |
543 | PERF_CONTEXT_OUTPUT(compressed_sec_cache_compressed_bytes); | |
7c673cae FG |
544 | PERF_CONTEXT_OUTPUT(block_checksum_time); |
545 | PERF_CONTEXT_OUTPUT(block_decompress_time); | |
11fdf7f2 TL |
546 | PERF_CONTEXT_OUTPUT(get_read_bytes); |
547 | PERF_CONTEXT_OUTPUT(multiget_read_bytes); | |
548 | PERF_CONTEXT_OUTPUT(iter_read_bytes); | |
1e59de90 TL |
549 | PERF_CONTEXT_OUTPUT(blob_cache_hit_count); |
550 | PERF_CONTEXT_OUTPUT(blob_read_count); | |
551 | PERF_CONTEXT_OUTPUT(blob_read_byte); | |
552 | PERF_CONTEXT_OUTPUT(blob_read_time); | |
553 | PERF_CONTEXT_OUTPUT(blob_checksum_time); | |
554 | PERF_CONTEXT_OUTPUT(blob_decompress_time); | |
7c673cae FG |
555 | PERF_CONTEXT_OUTPUT(internal_key_skipped_count); |
556 | PERF_CONTEXT_OUTPUT(internal_delete_skipped_count); | |
557 | PERF_CONTEXT_OUTPUT(internal_recent_skipped_count); | |
558 | PERF_CONTEXT_OUTPUT(internal_merge_count); | |
1e59de90 | 559 | PERF_CONTEXT_OUTPUT(internal_range_del_reseek_count); |
7c673cae FG |
560 | PERF_CONTEXT_OUTPUT(write_wal_time); |
561 | PERF_CONTEXT_OUTPUT(get_snapshot_time); | |
562 | PERF_CONTEXT_OUTPUT(get_from_memtable_time); | |
563 | PERF_CONTEXT_OUTPUT(get_from_memtable_count); | |
564 | PERF_CONTEXT_OUTPUT(get_post_process_time); | |
565 | PERF_CONTEXT_OUTPUT(get_from_output_files_time); | |
566 | PERF_CONTEXT_OUTPUT(seek_on_memtable_time); | |
567 | PERF_CONTEXT_OUTPUT(seek_on_memtable_count); | |
568 | PERF_CONTEXT_OUTPUT(next_on_memtable_count); | |
569 | PERF_CONTEXT_OUTPUT(prev_on_memtable_count); | |
570 | PERF_CONTEXT_OUTPUT(seek_child_seek_time); | |
571 | PERF_CONTEXT_OUTPUT(seek_child_seek_count); | |
572 | PERF_CONTEXT_OUTPUT(seek_min_heap_time); | |
573 | PERF_CONTEXT_OUTPUT(seek_internal_seek_time); | |
574 | PERF_CONTEXT_OUTPUT(find_next_user_entry_time); | |
575 | PERF_CONTEXT_OUTPUT(write_pre_and_post_process_time); | |
576 | PERF_CONTEXT_OUTPUT(write_memtable_time); | |
11fdf7f2 TL |
577 | PERF_CONTEXT_OUTPUT(write_thread_wait_nanos); |
578 | PERF_CONTEXT_OUTPUT(write_scheduling_flushes_compactions_time); | |
7c673cae FG |
579 | PERF_CONTEXT_OUTPUT(db_mutex_lock_nanos); |
580 | PERF_CONTEXT_OUTPUT(db_condition_wait_nanos); | |
581 | PERF_CONTEXT_OUTPUT(merge_operator_time_nanos); | |
582 | PERF_CONTEXT_OUTPUT(write_delay_time); | |
583 | PERF_CONTEXT_OUTPUT(read_index_block_nanos); | |
584 | PERF_CONTEXT_OUTPUT(read_filter_block_nanos); | |
585 | PERF_CONTEXT_OUTPUT(new_table_block_iter_nanos); | |
586 | PERF_CONTEXT_OUTPUT(new_table_iterator_nanos); | |
587 | PERF_CONTEXT_OUTPUT(block_seek_nanos); | |
588 | PERF_CONTEXT_OUTPUT(find_table_nanos); | |
589 | PERF_CONTEXT_OUTPUT(bloom_memtable_hit_count); | |
590 | PERF_CONTEXT_OUTPUT(bloom_memtable_miss_count); | |
591 | PERF_CONTEXT_OUTPUT(bloom_sst_hit_count); | |
592 | PERF_CONTEXT_OUTPUT(bloom_sst_miss_count); | |
11fdf7f2 TL |
593 | PERF_CONTEXT_OUTPUT(key_lock_wait_time); |
594 | PERF_CONTEXT_OUTPUT(key_lock_wait_count); | |
7c673cae FG |
595 | PERF_CONTEXT_OUTPUT(env_new_sequential_file_nanos); |
596 | PERF_CONTEXT_OUTPUT(env_new_random_access_file_nanos); | |
597 | PERF_CONTEXT_OUTPUT(env_new_writable_file_nanos); | |
598 | PERF_CONTEXT_OUTPUT(env_reuse_writable_file_nanos); | |
599 | PERF_CONTEXT_OUTPUT(env_new_random_rw_file_nanos); | |
600 | PERF_CONTEXT_OUTPUT(env_new_directory_nanos); | |
601 | PERF_CONTEXT_OUTPUT(env_file_exists_nanos); | |
602 | PERF_CONTEXT_OUTPUT(env_get_children_nanos); | |
603 | PERF_CONTEXT_OUTPUT(env_get_children_file_attributes_nanos); | |
604 | PERF_CONTEXT_OUTPUT(env_delete_file_nanos); | |
605 | PERF_CONTEXT_OUTPUT(env_create_dir_nanos); | |
606 | PERF_CONTEXT_OUTPUT(env_create_dir_if_missing_nanos); | |
607 | PERF_CONTEXT_OUTPUT(env_delete_dir_nanos); | |
608 | PERF_CONTEXT_OUTPUT(env_get_file_size_nanos); | |
609 | PERF_CONTEXT_OUTPUT(env_get_file_modification_time_nanos); | |
610 | PERF_CONTEXT_OUTPUT(env_rename_file_nanos); | |
611 | PERF_CONTEXT_OUTPUT(env_link_file_nanos); | |
612 | PERF_CONTEXT_OUTPUT(env_lock_file_nanos); | |
613 | PERF_CONTEXT_OUTPUT(env_unlock_file_nanos); | |
614 | PERF_CONTEXT_OUTPUT(env_new_logger_nanos); | |
494da23a TL |
615 | PERF_CONTEXT_OUTPUT(get_cpu_nanos); |
616 | PERF_CONTEXT_OUTPUT(iter_next_cpu_nanos); | |
617 | PERF_CONTEXT_OUTPUT(iter_prev_cpu_nanos); | |
618 | PERF_CONTEXT_OUTPUT(iter_seek_cpu_nanos); | |
1e59de90 | 619 | PERF_CONTEXT_OUTPUT(number_async_seek); |
494da23a TL |
620 | PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_useful); |
621 | PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_full_positive); | |
622 | PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(bloom_filter_full_true_positive); | |
623 | PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(block_cache_hit_count); | |
624 | PERF_CONTEXT_BY_LEVEL_OUTPUT_ONE_COUNTER(block_cache_miss_count); | |
f67539c2 TL |
625 | |
626 | std::string str = ss.str(); | |
627 | str.erase(str.find_last_not_of(", ") + 1); | |
628 | return str; | |
7c673cae FG |
629 | #endif |
630 | } | |
631 | ||
494da23a TL |
632 | void PerfContext::EnablePerLevelPerfContext() { |
633 | if (level_to_perf_context == nullptr) { | |
634 | level_to_perf_context = new std::map<uint32_t, PerfContextByLevel>(); | |
635 | } | |
636 | per_level_perf_context_enabled = true; | |
637 | } | |
638 | ||
1e59de90 | 639 | void PerfContext::DisablePerLevelPerfContext() { |
494da23a TL |
640 | per_level_perf_context_enabled = false; |
641 | } | |
642 | ||
1e59de90 | 643 | void PerfContext::ClearPerLevelPerfContext() { |
494da23a TL |
644 | if (level_to_perf_context != nullptr) { |
645 | level_to_perf_context->clear(); | |
646 | delete level_to_perf_context; | |
647 | level_to_perf_context = nullptr; | |
648 | } | |
649 | per_level_perf_context_enabled = false; | |
650 | } | |
651 | ||
f67539c2 | 652 | } // namespace ROCKSDB_NAMESPACE |