1 /* Copyright (c) 2010, 2020, Oracle and/or its affiliates. All rights reserved. 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 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef TABLE_ETS_BY_THREAD_BY_EVENT_NAME_H 24 #define TABLE_ETS_BY_THREAD_BY_EVENT_NAME_H 25 26 /** 27 @file storage/perfschema/table_ets_by_thread_by_event_name.h 28 Table EVENTS_TRANSACTIONS_SUMMARY_BY_THREAD_BY_EVENT_NAME (declarations). 29 */ 30 31 #include <sys/types.h> 32 33 #include "my_base.h" 34 #include "my_inttypes.h" 35 #include "storage/perfschema/pfs_engine_table.h" 36 #include "storage/perfschema/table_helper.h" 37 38 class Field; 39 class Plugin_table; 40 struct PFS_thread; 41 struct PFS_transaction_class; 42 struct TABLE; 43 struct THR_LOCK; 44 45 /** 46 @addtogroup performance_schema_tables 47 @{ 48 */ 49 50 class PFS_index_ets_by_thread_by_event_name : public PFS_engine_index { 51 public: PFS_index_ets_by_thread_by_event_name()52 PFS_index_ets_by_thread_by_event_name() 53 : PFS_engine_index(&m_key_1, &m_key_2), 54 m_key_1("THREAD_ID"), 55 m_key_2("EVENT_NAME") {} 56 ~PFS_index_ets_by_thread_by_event_name()57 ~PFS_index_ets_by_thread_by_event_name() {} 58 59 bool match(PFS_thread *pfs); 60 bool match(PFS_transaction_class *klass); 61 62 private: 63 PFS_key_thread_id m_key_1; 64 PFS_key_event_name m_key_2; 65 }; 66 67 /** 68 A row of table 69 PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_SUMMARY_BY_THREAD_BY_EVENT_NAME. 70 */ 71 struct row_ets_by_thread_by_event_name { 72 /** Column THREAD_ID. */ 73 ulonglong m_thread_internal_id; 74 /** Column EVENT_NAME. */ 75 PFS_event_name_row m_event_name; 76 /** 77 Columns COUNT_STAR, SUM/MIN/AVG/MAX_TIMER_WAIT, 78 COUNT_READ_WRITE, SUM/MIN/AVG/MAX_TIMER_READ_WRITE, 79 COUNT_READ_ONLY, SUM/MIN/AVG/MAX_TIMER_READ_ONLY 80 */ 81 PFS_transaction_stat_row m_stat; 82 }; 83 84 /** 85 Position of a cursor on 86 PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_SUMMARY_BY_THREAD_BY_EVENT_NAME. 87 Index 1 on thread (0 based). 88 Index 2 on transaction class (1 based). 89 */ 90 struct pos_ets_by_thread_by_event_name : public PFS_double_index, 91 public PFS_instrument_view_constants { pos_ets_by_thread_by_event_namepos_ets_by_thread_by_event_name92 pos_ets_by_thread_by_event_name() : PFS_double_index(0, 1) {} 93 resetpos_ets_by_thread_by_event_name94 inline void reset(void) { 95 m_index_1 = 0; 96 m_index_2 = 1; 97 } 98 next_threadpos_ets_by_thread_by_event_name99 inline void next_thread(void) { 100 m_index_1++; 101 m_index_2 = 1; 102 } 103 next_transactionpos_ets_by_thread_by_event_name104 inline void next_transaction(void) { m_index_2++; } 105 }; 106 107 /** Table 108 * PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_SUMMARY_BY_THREAD_BY_EVENT_NAME. */ 109 class table_ets_by_thread_by_event_name : public PFS_engine_table { 110 public: 111 /** Table share */ 112 static PFS_engine_table_share m_share; 113 static PFS_engine_table *create(PFS_engine_table_share *); 114 static int delete_all_rows(); 115 static ha_rows get_row_count(); 116 117 virtual void reset_position(void); 118 119 virtual int rnd_init(bool scan); 120 virtual int rnd_next(); 121 virtual int rnd_pos(const void *pos); 122 123 virtual int index_init(uint idx, bool sorted); 124 virtual int index_next(); 125 126 protected: 127 virtual int read_row_values(TABLE *table, unsigned char *buf, Field **fields, 128 bool read_all); 129 130 table_ets_by_thread_by_event_name(); 131 132 public: ~table_ets_by_thread_by_event_name()133 ~table_ets_by_thread_by_event_name() {} 134 135 protected: 136 int make_row(PFS_thread *thread, PFS_transaction_class *klass); 137 138 private: 139 /** Table share lock. */ 140 static THR_LOCK m_table_lock; 141 /** Table definition. */ 142 static Plugin_table m_table_def; 143 144 /** Current row. */ 145 row_ets_by_thread_by_event_name m_row; 146 /** Current position. */ 147 pos_ets_by_thread_by_event_name m_pos; 148 /** Next position. */ 149 pos_ets_by_thread_by_event_name m_next_pos; 150 151 PFS_index_ets_by_thread_by_event_name *m_opened_index; 152 }; 153 154 /** @} */ 155 #endif 156