1 /* Copyright (c) 2008, 2021, Oracle and/or its affiliates. 2 3 This program is free software; you can redistribute it and/or modify 4 it under the terms of the GNU General Public License, version 2.0, 5 as published by the Free Software Foundation. 6 7 This program is also distributed with certain software (including 8 but not limited to OpenSSL) that is licensed under separate terms, 9 as designated in a particular file or component or in included license 10 documentation. The authors of MySQL hereby grant you an additional 11 permission to link the program and your derivative works with the 12 separately licensed software that they have included with MySQL. 13 14 This program is distributed in the hope that it will be useful, 15 but WITHOUT ANY WARRANTY; without even the implied warranty of 16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 GNU General Public License, version 2.0, for more details. 18 19 You should have received a copy of the GNU General Public License 20 along with this program; if not, write to the Free Software Foundation, 21 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ 22 23 #ifndef TABLE_EVENTS_WAITS_H 24 #define TABLE_EVENTS_WAITS_H 25 26 /** 27 @file storage/perfschema/table_events_waits.h 28 Table EVENTS_WAITS_xxx (declarations). 29 */ 30 31 #include "pfs_column_types.h" 32 #include "pfs_engine_table.h" 33 #include "pfs_events_waits.h" 34 35 struct PFS_thread; 36 37 /** 38 @addtogroup Performance_schema_tables 39 @{ 40 */ 41 42 /** A row of table_events_waits_common. */ 43 struct row_events_waits 44 { 45 /** Column THREAD_ID. */ 46 ulonglong m_thread_internal_id; 47 /** Column EVENT_ID. */ 48 ulonglong m_event_id; 49 /** Column END_EVENT_ID. */ 50 ulonglong m_end_event_id; 51 /** Column NESTING_EVENT_ID. */ 52 ulonglong m_nesting_event_id; 53 /** Column NESTING_EVENT_TYPE. */ 54 enum_event_type m_nesting_event_type; 55 /** Column EVENT_NAME. */ 56 const char *m_name; 57 /** Length in bytes of @c m_name. */ 58 uint m_name_length; 59 /** Column TIMER_START. */ 60 ulonglong m_timer_start; 61 /** Column TIMER_END. */ 62 ulonglong m_timer_end; 63 /** Column TIMER_WAIT. */ 64 ulonglong m_timer_wait; 65 /** Column OBJECT_TYPE. */ 66 const char *m_object_type; 67 /** Length in bytes of @c m_object_type. */ 68 uint m_object_type_length; 69 /** Column OBJECT_SCHEMA. */ 70 char m_object_schema[COL_OBJECT_SCHEMA_SIZE]; 71 /** Length in bytes of @c m_object_schema. */ 72 uint m_object_schema_length; 73 /** Column OBJECT_NAME. */ 74 char m_object_name[COL_OBJECT_NAME_EXTENDED_SIZE]; 75 /** Length in bytes of @c m_object_name. */ 76 uint m_object_name_length; 77 /** Column INDEX_NAME. */ 78 char m_index_name[COL_INDEX_NAME_SIZE]; 79 /** Length in bytes of @c m_index_name. */ 80 uint m_index_name_length; 81 /** Column OBJECT_INSTANCE_BEGIN. */ 82 intptr m_object_instance_addr; 83 /** Column SOURCE. */ 84 char m_source[COL_SOURCE_SIZE]; 85 /** Length in bytes of @c m_source. */ 86 uint m_source_length; 87 /** Column OPERATION. */ 88 enum_operation_type m_operation; 89 /** Column NUMBER_OF_BYTES. */ 90 ulonglong m_number_of_bytes; 91 /** Column FLAGS. */ 92 uint m_flags; 93 }; 94 95 /** Position of a cursor on PERFORMANCE_SCHEMA.EVENTS_WAITS_CURRENT. */ 96 struct pos_events_waits_current : public PFS_double_index 97 { pos_events_waits_currentpos_events_waits_current98 pos_events_waits_current() 99 : PFS_double_index(0, 0) 100 {} 101 resetpos_events_waits_current102 inline void reset(void) 103 { 104 m_index_1= 0; 105 m_index_2= 0; 106 } 107 next_threadpos_events_waits_current108 inline void next_thread(void) 109 { 110 m_index_1++; 111 m_index_2= 0; 112 } 113 }; 114 115 /** Position of a cursor on PERFORMANCE_SCHEMA.EVENTS_WAITS_HISTORY. */ 116 struct pos_events_waits_history : public PFS_double_index 117 { pos_events_waits_historypos_events_waits_history118 pos_events_waits_history() 119 : PFS_double_index(0, 0) 120 {} 121 resetpos_events_waits_history122 inline void reset(void) 123 { 124 m_index_1= 0; 125 m_index_2= 0; 126 } 127 next_threadpos_events_waits_history128 inline void next_thread(void) 129 { 130 m_index_1++; 131 m_index_2= 0; 132 } 133 }; 134 135 /** 136 Adapter, for table sharing the structure of 137 PERFORMANCE_SCHEMA.EVENTS_WAITS_CURRENT. 138 */ 139 class table_events_waits_common : public PFS_engine_table 140 { 141 protected: 142 virtual int read_row_values(TABLE *table, 143 unsigned char *buf, 144 Field **fields, 145 bool read_all); 146 147 table_events_waits_common(const PFS_engine_table_share *share, void *pos); 148 ~table_events_waits_common()149 ~table_events_waits_common() 150 {} 151 152 void clear_object_columns(); 153 int make_table_object_columns(PFS_events_waits *wait); 154 int make_file_object_columns(PFS_events_waits *wait); 155 int make_socket_object_columns(PFS_events_waits *wait); 156 int make_metadata_lock_object_columns(PFS_events_waits *wait); 157 158 void make_row(PFS_events_waits *wait); 159 160 /** Current row. */ 161 row_events_waits m_row; 162 /** True if the current row exists. */ 163 bool m_row_exists; 164 }; 165 166 /** Table PERFORMANCE_SCHEMA.EVENTS_WAITS_CURRENT. */ 167 class table_events_waits_current : public table_events_waits_common 168 { 169 public: 170 /** Table share */ 171 static PFS_engine_table_share m_share; 172 static PFS_engine_table* create(); 173 static int delete_all_rows(); 174 static ha_rows get_row_count(); 175 176 virtual int rnd_next(); 177 virtual int rnd_pos(const void *pos); 178 virtual void reset_position(void); 179 180 protected: 181 table_events_waits_current(); 182 183 public: ~table_events_waits_current()184 ~table_events_waits_current() 185 {} 186 187 private: 188 friend class table_events_waits_history; 189 friend class table_events_waits_history_long; 190 191 /** Table share lock. */ 192 static THR_LOCK m_table_lock; 193 /** 194 Fields definition. 195 Also used by table_events_waits_history 196 and table_events_waits_history_long. 197 */ 198 static TABLE_FIELD_DEF m_field_def; 199 200 void make_row(PFS_thread *thread, PFS_events_waits *wait); 201 202 /** Current position. */ 203 pos_events_waits_current m_pos; 204 /** Next position. */ 205 pos_events_waits_current m_next_pos; 206 }; 207 208 /** Table PERFORMANCE_SCHEMA.EVENTS_WAITS_HISTORY. */ 209 class table_events_waits_history : public table_events_waits_common 210 { 211 public: 212 /** Table share */ 213 static PFS_engine_table_share m_share; 214 static PFS_engine_table* create(); 215 static int delete_all_rows(); 216 static ha_rows get_row_count(); 217 218 virtual int rnd_next(); 219 virtual int rnd_pos(const void *pos); 220 virtual void reset_position(void); 221 222 protected: 223 table_events_waits_history(); 224 225 public: ~table_events_waits_history()226 ~table_events_waits_history() 227 {} 228 229 private: 230 /** Table share lock. */ 231 static THR_LOCK m_table_lock; 232 233 void make_row(PFS_thread *thread, PFS_events_waits *wait); 234 235 /** Current position. */ 236 pos_events_waits_history m_pos; 237 /** Next position. */ 238 pos_events_waits_history m_next_pos; 239 }; 240 241 /** Table PERFORMANCE_SCHEMA.EVENTS_WAITS_HISTORY_LONG. */ 242 class table_events_waits_history_long : public table_events_waits_common 243 { 244 public: 245 /** Table share */ 246 static PFS_engine_table_share m_share; 247 static PFS_engine_table* create(); 248 static int delete_all_rows(); 249 static ha_rows get_row_count(); 250 251 virtual int rnd_next(); 252 virtual int rnd_pos(const void *pos); 253 virtual void reset_position(void); 254 255 protected: 256 table_events_waits_history_long(); 257 258 public: ~table_events_waits_history_long()259 ~table_events_waits_history_long() 260 {} 261 262 private: 263 /** Table share lock. */ 264 static THR_LOCK m_table_lock; 265 266 /** Current position. */ 267 PFS_simple_index m_pos; 268 /** Next position. */ 269 PFS_simple_index m_next_pos; 270 }; 271 272 /** @} */ 273 #endif 274