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 #include <my_io_perf.h> 28 29 namespace myrocks { 30 31 enum { 32 PC_USER_KEY_COMPARISON_COUNT = 0, 33 PC_BLOCK_CACHE_HIT_COUNT, 34 PC_BLOCK_READ_COUNT, 35 PC_BLOCK_READ_BYTE, 36 PC_BLOCK_READ_TIME, 37 PC_BLOCK_CHECKSUM_TIME, 38 PC_BLOCK_DECOMPRESS_TIME, 39 PC_KEY_SKIPPED, 40 PC_DELETE_SKIPPED, 41 PC_GET_SNAPSHOT_TIME, 42 PC_GET_FROM_MEMTABLE_TIME, 43 PC_GET_FROM_MEMTABLE_COUNT, 44 PC_GET_POST_PROCESS_TIME, 45 PC_GET_FROM_OUTPUT_FILES_TIME, 46 PC_SEEK_ON_MEMTABLE_TIME, 47 PC_SEEK_ON_MEMTABLE_COUNT, 48 PC_SEEK_CHILD_SEEK_TIME, 49 PC_SEEK_CHILD_SEEK_COUNT, 50 PC_SEEK_MIN_HEAP_TIME, 51 PC_SEEK_INTERNAL_SEEK_TIME, 52 PC_FIND_NEXT_USER_ENTRY_TIME, 53 PC_WRITE_WAL_TIME, 54 PC_WRITE_MEMTABLE_TIME, 55 PC_WRITE_DELAY_TIME, 56 PC_WRITE_PRE_AND_POST_PROCESSS_TIME, 57 PC_DB_MUTEX_LOCK_NANOS, 58 PC_DB_CONDITION_WAIT_NANOS, 59 PC_MERGE_OPERATOR_TIME_NANOS, 60 PC_READ_INDEX_BLOCK_NANOS, 61 PC_READ_FILTER_BLOCK_NANOS, 62 PC_NEW_TABLE_BLOCK_ITER_NANOS, 63 PC_NEW_TABLE_ITERATOR_NANOS, 64 PC_BLOCK_SEEK_NANOS, 65 PC_FIND_TABLE_NANOS, 66 PC_IO_THREAD_POOL_ID, 67 PC_IO_BYTES_WRITTEN, 68 PC_IO_BYTES_READ, 69 PC_IO_OPEN_NANOS, 70 PC_IO_ALLOCATE_NANOS, 71 PC_IO_WRITE_NANOS, 72 PC_IO_READ_NANOS, 73 PC_IO_RANGE_SYNC_NANOS, 74 PC_IO_LOGGER_NANOS, 75 PC_MAX_IDX 76 }; 77 78 class Rdb_perf_counters; 79 80 /* 81 A collection of performance counters that can be safely incremented by 82 multiple threads since it stores atomic datapoints. 83 */ 84 struct Rdb_atomic_perf_counters { 85 std::atomic_ullong m_value[PC_MAX_IDX]; 86 }; 87 88 /* 89 A collection of performance counters that is meant to be incremented by 90 a single thread. 91 */ 92 class Rdb_perf_counters { 93 Rdb_perf_counters(const Rdb_perf_counters &) = delete; 94 Rdb_perf_counters &operator=(const Rdb_perf_counters &) = delete; 95 96 public: 97 Rdb_perf_counters() = default; 98 uint64_t m_value[PC_MAX_IDX]; 99 100 void load(const Rdb_atomic_perf_counters &atomic_counters); 101 }; 102 103 extern std::string rdb_pc_stat_types[PC_MAX_IDX]; 104 105 /* 106 Perf timers for data reads 107 */ 108 class Rdb_io_perf { 109 // Context management 110 Rdb_atomic_perf_counters *m_atomic_counters = nullptr; 111 my_io_perf_atomic_t *m_shared_io_perf_read = nullptr; 112 ha_statistics *m_stats = nullptr; 113 114 public: 115 Rdb_io_perf(const Rdb_io_perf &) = delete; 116 Rdb_io_perf &operator=(const Rdb_io_perf &) = delete; 117 init(Rdb_atomic_perf_counters * const atomic_counters,my_io_perf_atomic_t * const shared_io_perf_read,ha_statistics * const stats)118 void init(Rdb_atomic_perf_counters *const atomic_counters, 119 my_io_perf_atomic_t *const shared_io_perf_read, 120 ha_statistics *const stats) { 121 DBUG_ASSERT(atomic_counters != nullptr); 122 DBUG_ASSERT(shared_io_perf_read != nullptr); 123 DBUG_ASSERT(stats != nullptr); 124 125 m_atomic_counters = atomic_counters; 126 m_shared_io_perf_read = shared_io_perf_read; 127 m_stats = stats; 128 } 129 130 bool start(const uint32_t perf_context_level); 131 void end_and_record(const uint32_t perf_context_level); 132 Rdb_io_perf()133 explicit Rdb_io_perf() 134 : m_atomic_counters(nullptr), m_shared_io_perf_read(nullptr), 135 m_stats(nullptr) {} 136 }; 137 138 } // namespace myrocks 139