1 /* Copyright (c) 2010, 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 21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ 22 23 #ifndef PFS_CON_SLICE_H 24 #define PFS_CON_SLICE_H 25 26 /** 27 @file storage/perfschema/pfs_con_slice.h 28 Performance schema connection slice (declarations). 29 */ 30 31 #include "sql_class.h" 32 #include "pfs_lock.h" 33 #include "lf.h" 34 #include "pfs_status.h" 35 36 struct PFS_single_stat; 37 struct PFS_stage_stat; 38 struct PFS_statement_stat; 39 struct PFS_transaction_stat; 40 struct PFS_memory_stat; 41 class PFS_opaque_container_page; 42 43 /** 44 @addtogroup Performance_schema_buffers 45 @{ 46 */ 47 48 /** 49 A connection slice, an arbitrary grouping of several connections. 50 This structure holds statistics for grouping of connections. 51 */ 52 struct PFS_connection_slice 53 { 54 /** Reset all statistics. */ reset_statsPFS_connection_slice55 inline void reset_stats() 56 { 57 m_has_waits_stats= false; 58 m_has_stages_stats= false; 59 m_has_statements_stats= false; 60 m_has_transactions_stats= false; 61 m_has_memory_stats= false; 62 reset_status_stats(); 63 } 64 65 /** Reset all wait statistics. */ 66 void reset_waits_stats(); 67 /** Reset all stages statistics. */ 68 void reset_stages_stats(); 69 /** Reset all statements statistics. */ 70 void reset_statements_stats(); 71 /** Reset all transactions statistics. */ 72 void reset_transactions_stats(); 73 /** Reset all memory statistics. */ 74 void rebase_memory_stats(); 75 /** Reset all status variable statistics. */ reset_status_statsPFS_connection_slice76 void reset_status_stats() 77 { 78 m_status_stats.reset(); 79 } 80 set_instr_class_waits_statsPFS_connection_slice81 void set_instr_class_waits_stats(PFS_single_stat *array) 82 { 83 m_has_waits_stats= false; 84 m_instr_class_waits_stats= array; 85 } 86 read_instr_class_waits_statsPFS_connection_slice87 const PFS_single_stat* read_instr_class_waits_stats() const 88 { 89 if (! m_has_waits_stats) 90 return NULL; 91 return m_instr_class_waits_stats; 92 } 93 write_instr_class_waits_statsPFS_connection_slice94 PFS_single_stat* write_instr_class_waits_stats() 95 { 96 if (! m_has_waits_stats) 97 { 98 reset_waits_stats(); 99 m_has_waits_stats= true; 100 } 101 return m_instr_class_waits_stats; 102 } 103 set_instr_class_stages_statsPFS_connection_slice104 void set_instr_class_stages_stats(PFS_stage_stat *array) 105 { 106 m_has_stages_stats= false; 107 m_instr_class_stages_stats= array; 108 } 109 read_instr_class_stages_statsPFS_connection_slice110 const PFS_stage_stat* read_instr_class_stages_stats() const 111 { 112 if (! m_has_stages_stats) 113 return NULL; 114 return m_instr_class_stages_stats; 115 } 116 write_instr_class_stages_statsPFS_connection_slice117 PFS_stage_stat* write_instr_class_stages_stats() 118 { 119 if (! m_has_stages_stats) 120 { 121 reset_stages_stats(); 122 m_has_stages_stats= true; 123 } 124 return m_instr_class_stages_stats; 125 } 126 set_instr_class_statements_statsPFS_connection_slice127 void set_instr_class_statements_stats(PFS_statement_stat *array) 128 { 129 m_has_statements_stats= false; 130 m_instr_class_statements_stats= array; 131 } 132 read_instr_class_statements_statsPFS_connection_slice133 const PFS_statement_stat* read_instr_class_statements_stats() const 134 { 135 if (! m_has_statements_stats) 136 return NULL; 137 return m_instr_class_statements_stats; 138 } 139 write_instr_class_statements_statsPFS_connection_slice140 PFS_statement_stat* write_instr_class_statements_stats() 141 { 142 if (! m_has_statements_stats) 143 { 144 reset_statements_stats(); 145 m_has_statements_stats= true; 146 } 147 return m_instr_class_statements_stats; 148 } 149 set_instr_class_transactions_statsPFS_connection_slice150 void set_instr_class_transactions_stats(PFS_transaction_stat *array) 151 { 152 m_has_transactions_stats= false; 153 m_instr_class_transactions_stats= array; 154 } 155 read_instr_class_transactions_statsPFS_connection_slice156 const PFS_transaction_stat* read_instr_class_transactions_stats() const 157 { 158 if (! m_has_transactions_stats) 159 return NULL; 160 return m_instr_class_transactions_stats; 161 } 162 write_instr_class_transactions_statsPFS_connection_slice163 PFS_transaction_stat* write_instr_class_transactions_stats() 164 { 165 if (! m_has_transactions_stats) 166 { 167 reset_transactions_stats(); 168 m_has_transactions_stats= true; 169 } 170 return m_instr_class_transactions_stats; 171 } 172 set_instr_class_memory_statsPFS_connection_slice173 void set_instr_class_memory_stats(PFS_memory_stat *array) 174 { 175 m_has_memory_stats= false; 176 m_instr_class_memory_stats= array; 177 } 178 read_instr_class_memory_statsPFS_connection_slice179 const PFS_memory_stat* read_instr_class_memory_stats() const 180 { 181 if (! m_has_memory_stats) 182 return NULL; 183 return m_instr_class_memory_stats; 184 } 185 write_instr_class_memory_statsPFS_connection_slice186 PFS_memory_stat* write_instr_class_memory_stats() 187 { 188 if (! m_has_memory_stats) 189 { 190 rebase_memory_stats(); 191 m_has_memory_stats= true; 192 } 193 return m_instr_class_memory_stats; 194 } 195 196 private: 197 bool m_has_waits_stats; 198 bool m_has_stages_stats; 199 bool m_has_statements_stats; 200 bool m_has_transactions_stats; 201 bool m_has_memory_stats; 202 203 /** 204 Per connection slice waits aggregated statistics. 205 This member holds the data for the table 206 PERFORMANCE_SCHEMA.EVENTS_WAITS_SUMMARY_BY_*_BY_EVENT_NAME. 207 Immutable, safe to use without internal lock. 208 */ 209 PFS_single_stat *m_instr_class_waits_stats; 210 211 /** 212 Per connection slice stages aggregated statistics. 213 This member holds the data for the table 214 PERFORMANCE_SCHEMA.EVENTS_STAGES_SUMMARY_BY_*_BY_EVENT_NAME. 215 Immutable, safe to use without internal lock. 216 */ 217 PFS_stage_stat *m_instr_class_stages_stats; 218 219 /** 220 Per connection slice statements aggregated statistics. 221 This member holds the data for the table 222 PERFORMANCE_SCHEMA.EVENTS_STATEMENTS_SUMMARY_BY_*_BY_EVENT_NAME. 223 Immutable, safe to use without internal lock. 224 */ 225 PFS_statement_stat *m_instr_class_statements_stats; 226 227 /** 228 Per connection slice transactions aggregated statistics. 229 This member holds the data for the table 230 PERFORMANCE_SCHEMA.EVENTS_TRANSACTIONS_SUMMARY_BY_*_BY_EVENT_NAME. 231 Immutable, safe to use without internal lock. 232 */ 233 PFS_transaction_stat *m_instr_class_transactions_stats; 234 235 /** 236 Per connection slice memory aggregated statistics. 237 This member holds the data for the table 238 PERFORMANCE_SCHEMA.MEMORY_SUMMARY_BY_*_BY_EVENT_NAME. 239 Immutable, safe to use without internal lock. 240 */ 241 PFS_memory_stat *m_instr_class_memory_stats; 242 243 public: 244 aggregate_status_statsPFS_connection_slice245 void aggregate_status_stats(const STATUS_VAR *status_vars) 246 { 247 m_status_stats.aggregate_from(status_vars); 248 } 249 250 /** 251 Aggregated status variables. 252 */ 253 PFS_status_stats m_status_stats; 254 255 /** Container page. */ 256 PFS_opaque_container_page *m_page; 257 }; 258 259 /** @} */ 260 #endif 261 262