| 1 | /* Copyright (c) 2011, 2023, 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 | /** |
| 24 | @file storage/perfschema/table_mems_global_by_event_name.cc |
| 25 | Table MEMORY_SUMMARY_GLOBAL_BY_EVENT_NAME (implementation). |
| 26 | */ |
| 27 | |
| 28 | #include "my_global.h"cxx . . $ `<file>/include/my_global.h`/ |
| 29 | #include "my_thread.h"cxx . . $ `<file>/storage/perfschema/my_thread.h`/ |
| 30 | #include "pfs_instr_class.h"cxx . . $ `<file>/storage/perfschema/pfs_instr_class.h`/ |
| 31 | #include "pfs_column_types.h"cxx . . $ `<file>/storage/perfschema/pfs_column_types.h`/ |
| 32 | #include "pfs_column_values.h"cxx . . $ `<file>/storage/perfschema/pfs_column_values.h`/ |
| 33 | #include "table_mems_global_by_event_name.h"cxx . . $ `<file>/storage/perfschema/table_mems_global_by_event_name.h`/ |
| 34 | #include "pfs_global.h"cxx . . $ `<file>/storage/perfschema/pfs_global.h`/ |
| 35 | #include "pfs_visitor.h"cxx . . $ `<file>/storage/perfschema/pfs_visitor.h`/ |
| 36 | #include "pfs_builtin_memory.h"cxx . . $ `<file>/storage/perfschema/pfs_builtin_memory.h`/ |
| 37 | #include "pfs_memory.h"cxx . . $ `<file>/storage/perfschema/pfs_memory.h`/ |
| 38 | #include "field.h"cxx . . $ `<file>/sql/field.h`/ |
| 39 | |
| 40 | THR_LOCK table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::m_table_lockcxx . . $ table_mems_global_by_event_name#m_table_lock.; |
| 41 | |
| 42 | PFS_engine_table_share_statecxx . . $ PFS_engine_table_share_state# |
| 43 | table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::m_share_statecxx . . $ table_mems_global_by_event_name#m_share_state. = { |
| 44 | false /* m_checked */ |
| 45 | }; |
| 46 | |
| 47 | PFS_engine_table_sharecxx . . $ PFS_engine_table_share# |
| 48 | table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::m_sharecxx . . $ table_mems_global_by_event_name#m_share.= |
| 49 | { |
| 50 | { C_STRING_WITH_LENcxx . . $ `include/m_string.h:212:9`!("memory_summary_global_by_event_name") }, |
| 51 | &pfs_readonly_aclcxx . . $ pfs_readonly_acl., |
| 52 | table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::createcxx . . $ table_mems_global_by_event_name#create(314e88453c9d561a)., |
| 53 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, /* write_row */ |
| 54 | table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::delete_all_rowscxx . . $ table_mems_global_by_event_name#delete_all_rows(b126dc7c1de90089)., |
| 55 | table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::get_row_countcxx . . $ table_mems_global_by_event_name#get_row_count(73266883b0c7072b)., |
| 56 | sizeof(pos_tcxx . . $ table_mems_global_by_event_name#pos_t#), |
| 57 | &m_table_lockcxx . . $ table_mems_global_by_event_name#m_table_lock., |
| 58 | { C_STRING_WITH_LENcxx . . $ `include/m_string.h:212:9`!("CREATE TABLE memory_summary_global_by_event_name(" |
| 59 | "EVENT_NAME VARCHAR(128) not null comment 'Event name.'," |
| 60 | "COUNT_ALLOC BIGINT unsigned not null comment 'Total number of allocations to memory.'," |
| 61 | "COUNT_FREE BIGINT unsigned not null comment 'Total number of attempts to free the allocated memory.'," |
| 62 | "SUM_NUMBER_OF_BYTES_ALLOC BIGINT unsigned not null comment 'Total number of bytes allocated.'," |
| 63 | "SUM_NUMBER_OF_BYTES_FREE BIGINT unsigned not null comment 'Total number of bytes freed'," |
| 64 | "LOW_COUNT_USED BIGINT not null comment 'Lowest number of allocated blocks (lowest value of CURRENT_COUNT_USED).'," |
| 65 | "CURRENT_COUNT_USED BIGINT not null comment 'Currently allocated blocks that have not been freed (COUNT_ALLOC minus COUNT_FREE).'," |
| 66 | "HIGH_COUNT_USED BIGINT not null comment 'Highest number of allocated blocks (highest value of CURRENT_COUNT_USED).'," |
| 67 | "LOW_NUMBER_OF_BYTES_USED BIGINT not null comment 'Lowest number of bytes used.'," |
| 68 | "CURRENT_NUMBER_OF_BYTES_USED BIGINT not null comment 'Current number of bytes used (total allocated minus total freed).'," |
| 69 | "HIGH_NUMBER_OF_BYTES_USED BIGINT not null comment 'Highest number of bytes used.')")}, |
| 70 | false, /* m_perpetual */ |
| 71 | false, /* m_optional */ |
| 72 | &m_share_statecxx . . $ table_mems_global_by_event_name#m_share_state. |
| 73 | }; |
| 74 | |
| 75 | PFS_engine_tablecxx . . $ PFS_engine_table#* table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::createcxx . . $ table_mems_global_by_event_name#create(314e88453c9d561a).(void) |
| 76 | { |
| 77 | return new table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#(); |
| 78 | } |
| 79 | |
| 80 | int |
| 81 | table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::delete_all_rowscxx . . $ table_mems_global_by_event_name#delete_all_rows(b126dc7c1de90089).(void) |
| 82 | { |
| 83 | reset_memory_by_threadcxx . . $ reset_memory_by_thread(49f6e7a06ebc5aa8).(); |
| 84 | reset_memory_by_accountcxx . . $ reset_memory_by_account(49f6e7a06ebc5aa8).(); |
| 85 | reset_memory_by_usercxx . . $ reset_memory_by_user(49f6e7a06ebc5aa8).(); |
| 86 | reset_memory_by_hostcxx . . $ reset_memory_by_host(49f6e7a06ebc5aa8).(); |
| 87 | reset_memory_globalcxx . . $ reset_memory_global(49f6e7a06ebc5aa8).(); |
| 88 | return 0; |
| 89 | } |
| 90 | |
| 91 | ha_rowscxx . . $ ha_rows# |
| 92 | table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::get_row_countcxx . . $ table_mems_global_by_event_name#get_row_count(73266883b0c7072b).(void) |
| 93 | { |
| 94 | return memory_class_maxcxx . . $ memory_class_max.; |
| 95 | } |
| 96 | |
| 97 | table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#table_mems_global_by_event_name(49f6e7a06ebc5aa8).() |
| 98 | : PFS_engine_tablecxx . . $ PFS_engine_table#(&m_sharecxx . . $ table_mems_global_by_event_name#m_share., &m_poscxx . . $ table_mems_global_by_event_name#m_pos.), |
| 99 | m_row_existscxx . . $ table_mems_global_by_event_name#m_row_exists.(false), m_poscxx . . $ table_mems_global_by_event_name#m_pos.(), m_next_poscxx . . $ table_mems_global_by_event_name#m_next_pos.() |
| 100 | {} |
| 101 | |
| 102 | void table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::reset_positioncxx . . $ table_mems_global_by_event_name#reset_position(49f6e7a06ebc5aa8).(void) |
| 103 | { |
| 104 | m_poscxx . . $ table_mems_global_by_event_name#m_pos..resetcxx . . $ pos_mems_global_by_event_name#reset(49f6e7a06ebc5aa8).(); |
| 105 | m_next_poscxx . . $ table_mems_global_by_event_name#m_next_pos..resetcxx . . $ pos_mems_global_by_event_name#reset(49f6e7a06ebc5aa8).(); |
| 106 | } |
| 107 | |
| 108 | int table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::rnd_nextcxx . . $ table_mems_global_by_event_name#rnd_next(b126dc7c1de90089).(void) |
| 109 | { |
| 110 | PFS_memory_classcxx . . $ PFS_memory_class# *pfs; |
| 111 | PFS_builtin_memory_classcxx . . $ PFS_builtin_memory_class# *pfs_builtin; |
| 112 | |
| 113 | /* Do not advertise hard coded instruments when disabled. */ |
| 114 | if (! pfs_initializedcxx . . $ pfs_initialized.) |
| 115 | return HA_ERR_END_OF_FILEcxx . . $ `include/my_base.h:482:9`!; |
| 116 | |
| 117 | for (m_poscxx . . $ table_mems_global_by_event_name#m_pos..set_atcxx . . $ PFS_double_index#set_at(32342b42ae7ca4ee).(&m_next_poscxx . . $ table_mems_global_by_event_name#m_next_pos.); |
| 118 | m_poscxx . . $ table_mems_global_by_event_name#m_pos..has_more_viewcxx . . $ pos_mems_global_by_event_name#has_more_view(c9857a73d68e59ba).(); |
| 119 | m_poscxx . . $ table_mems_global_by_event_name#m_pos..next_viewcxx . . $ pos_mems_global_by_event_name#next_view(49f6e7a06ebc5aa8).()) |
| 120 | { |
| 121 | switch (m_poscxx . . $ table_mems_global_by_event_name#m_pos..m_index_1cxx . . $ PFS_double_index#m_index_1.) |
| 122 | { |
| 123 | case pos_mems_global_by_event_namecxx . . $ pos_mems_global_by_event_name#::VIEW_BUILTIN_MEMORYcxx . . $ pos_mems_global_by_event_name#VIEW_BUILTIN_MEMORY.: |
| 124 | pfs_builtin= find_builtin_memory_classcxx . . $ find_builtin_memory_class(bef414967545b807).(m_poscxx . . $ table_mems_global_by_event_name#m_pos..m_index_2cxx . . $ PFS_double_index#m_index_2.); |
| 125 | if (pfs_builtin != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 126 | { |
| 127 | make_rowcxx . . $ table_mems_global_by_event_name#make_row(75cc0d3b2fe22a81).(pfs_builtin); |
| 128 | m_next_poscxx . . $ table_mems_global_by_event_name#m_next_pos..set_aftercxx . . $ PFS_double_index#set_after(32342b42ae7ca4ee).(&m_poscxx . . $ table_mems_global_by_event_name#m_pos.); |
| 129 | return 0; |
| 130 | } |
| 131 | break; |
| 132 | case pos_mems_global_by_event_namecxx . . $ pos_mems_global_by_event_name#::VIEW_MEMORYcxx . . $ pos_mems_global_by_event_name#VIEW_MEMORY.: |
| 133 | pfs= find_memory_classcxx . . $ find_memory_class(91689fc62c460040).(m_poscxx . . $ table_mems_global_by_event_name#m_pos..m_index_2cxx . . $ PFS_double_index#m_index_2.); |
| 134 | if (pfs != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 135 | { |
| 136 | make_rowcxx . . $ table_mems_global_by_event_name#make_row(ffebf2b8481ec1ff).(pfs); |
| 137 | m_next_poscxx . . $ table_mems_global_by_event_name#m_next_pos..set_aftercxx . . $ PFS_double_index#set_after(32342b42ae7ca4ee).(&m_poscxx . . $ table_mems_global_by_event_name#m_pos.); |
| 138 | return 0; |
| 139 | } |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | return HA_ERR_END_OF_FILEcxx . . $ `include/my_base.h:482:9`!; |
| 145 | } |
| 146 | |
| 147 | int table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::rnd_poscxx . . $ table_mems_global_by_event_name#rnd_pos(aa284d429d6986c8).(const void *pos) |
| 148 | { |
| 149 | PFS_builtin_memory_classcxx . . $ PFS_builtin_memory_class# *pfs_builtin; |
| 150 | PFS_memory_classcxx . . $ PFS_memory_class# *pfs; |
| 151 | |
| 152 | /* Do not advertise hard coded instruments when disabled. */ |
| 153 | if (! pfs_initializedcxx . . $ pfs_initialized.) |
| 154 | return HA_ERR_END_OF_FILEcxx . . $ `include/my_base.h:482:9`!; |
| 155 | |
| 156 | set_positioncxx . . $ PFS_engine_table#set_position(e4289f82fef2c2f9).(pos); |
| 157 | |
| 158 | switch(m_poscxx . . $ table_mems_global_by_event_name#m_pos..m_index_1cxx . . $ PFS_double_index#m_index_1.) |
| 159 | { |
| 160 | case pos_mems_global_by_event_namecxx . . $ pos_mems_global_by_event_name#::VIEW_BUILTIN_MEMORYcxx . . $ pos_mems_global_by_event_name#VIEW_BUILTIN_MEMORY.: |
| 161 | pfs_builtin= find_builtin_memory_classcxx . . $ find_builtin_memory_class(bef414967545b807).(m_poscxx . . $ table_mems_global_by_event_name#m_pos..m_index_2cxx . . $ PFS_double_index#m_index_2.); |
| 162 | if (pfs_builtin != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 163 | { |
| 164 | make_rowcxx . . $ table_mems_global_by_event_name#make_row(75cc0d3b2fe22a81).(pfs_builtin); |
| 165 | return 0; |
| 166 | } |
| 167 | break; |
| 168 | case pos_mems_global_by_event_namecxx . . $ pos_mems_global_by_event_name#::VIEW_MEMORYcxx . . $ pos_mems_global_by_event_name#VIEW_MEMORY.: |
| 169 | pfs= find_memory_classcxx . . $ find_memory_class(91689fc62c460040).(m_poscxx . . $ table_mems_global_by_event_name#m_pos..m_index_2cxx . . $ PFS_double_index#m_index_2.); |
| 170 | if (pfs != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!) |
| 171 | { |
| 172 | make_rowcxx . . $ table_mems_global_by_event_name#make_row(ffebf2b8481ec1ff).(pfs); |
| 173 | return 0; |
| 174 | } |
| 175 | break; |
| 176 | } |
| 177 | |
| 178 | return HA_ERR_RECORD_DELETEDcxx . . $ `include/my_base.h:479:9`!; |
| 179 | } |
| 180 | |
| 181 | void table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::make_rowcxx . . $ table_mems_global_by_event_name#make_row(ffebf2b8481ec1ff).(PFS_memory_classcxx . . $ PFS_memory_class# *klass) |
| 182 | { |
| 183 | m_rowcxx . . $ table_mems_global_by_event_name#m_row..m_event_namecxx . . $ row_mems_global_by_event_name#m_event_name..make_rowcxx . . $ PFS_event_name_row#make_row(b4cc58497f13b22c).(klass); |
| 184 | |
| 185 | PFS_connection_memory_visitorcxx . . $ PFS_connection_memory_visitor# visitorcxx . . $ PFS_connection_memory_visitor#PFS_connection_memory_visitor(ffebf2b8481ec1ff).(klass); |
| 186 | |
| 187 | if (klass->is_globalcxx . . $ PFS_memory_class#is_global(50ce9a9e25b4a850).()) |
| 188 | { |
| 189 | PFS_connection_iteratorcxx . . $ PFS_connection_iterator#::visit_globalcxx . . $ PFS_connection_iterator#visit_global(7f828f9bf181cde8).(false, /* hosts */ |
| 190 | false, /* users */ |
| 191 | false, /* accounts */ |
| 192 | false, /* threads */ |
| 193 | false, /* THDs */ |
| 194 | &visitor); |
| 195 | } |
| 196 | else |
| 197 | { |
| 198 | PFS_connection_iteratorcxx . . $ PFS_connection_iterator#::visit_globalcxx . . $ PFS_connection_iterator#visit_global(7f828f9bf181cde8).(true, /* hosts */ |
| 199 | false, /* users */ |
| 200 | true, /* accounts */ |
| 201 | true, /* threads */ |
| 202 | false, /* THDs */ |
| 203 | &visitor); |
| 204 | } |
| 205 | |
| 206 | m_rowcxx . . $ table_mems_global_by_event_name#m_row..m_statcxx . . $ row_mems_global_by_event_name#m_stat..setcxx . . $ PFS_memory_stat_row#set(ce2cebe79de3bef1).(& visitor.m_statcxx . . $ PFS_connection_memory_visitor#m_stat.); |
| 207 | m_row_existscxx . . $ table_mems_global_by_event_name#m_row_exists.= true; |
| 208 | } |
| 209 | |
| 210 | void table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::make_rowcxx . . $ table_mems_global_by_event_name#make_row(75cc0d3b2fe22a81).(PFS_builtin_memory_classcxx . . $ PFS_builtin_memory_class# *klass) |
| 211 | { |
| 212 | m_rowcxx . . $ table_mems_global_by_event_name#m_row..m_event_namecxx . . $ row_mems_global_by_event_name#m_event_name..make_rowcxx . . $ PFS_event_name_row#make_row(b4cc58497f13b22c).(& klass->m_classcxx . . $ PFS_builtin_memory_class#m_class.); |
| 213 | m_rowcxx . . $ table_mems_global_by_event_name#m_row..m_statcxx . . $ row_mems_global_by_event_name#m_stat..setcxx . . $ PFS_memory_stat_row#set(ce2cebe79de3bef1).(& klass->m_statcxx . . $ PFS_builtin_memory_class#m_stat.); |
| 214 | m_row_existscxx . . $ table_mems_global_by_event_name#m_row_exists.= true; |
| 215 | } |
| 216 | |
| 217 | int table_mems_global_by_event_namecxx . . $ table_mems_global_by_event_name#::read_row_valuescxx . . $ table_mems_global_by_event_name#read_row_values(139ec8e2a7764e1).(TABLEcxx . . $ TABLE# *table, |
| 218 | unsigned char *, |
| 219 | Fieldcxx . . $ Field# **fields, |
| 220 | bool read_all) |
| 221 | { |
| 222 | Fieldcxx . . $ Field# *f; |
| 223 | |
| 224 | if (unlikelycxx . . $ `include/my_global.h:361:9`!(! m_row_exists)) |
| 225 | return HA_ERR_RECORD_DELETEDcxx . . $ `include/my_base.h:479:9`!; |
| 226 | |
| 227 | /* Set the null bits */ |
| 228 | assertcxx . . $ `<external>/4398592474888995393/assert.h:50:10`!(table->s->null_bytes == 0); |
| 229 | |
| 230 | for (; (f= *fields) ; fields++) |
| 231 | { |
| 232 | if (read_all || bitmap_is_set(table->read_setcxx . . $ TABLE#read_set., f->field_indexcxx . . $ Field#field_index.)) |
| 233 | { |
| 234 | switch(f->field_indexcxx . . $ Field#field_index.) |
| 235 | { |
| 236 | case 0: /* EVENT_NAME */ |
| 237 | m_rowcxx . . $ table_mems_global_by_event_name#m_row..m_event_namecxx . . $ row_mems_global_by_event_name#m_event_name..set_fieldcxx . . $ PFS_event_name_row#set_field(42c390a4298f5e0).(f); |
| 238 | break; |
| 239 | default: /* 1, ... HIGH_NUMBER_OF_BYTES_USED */ |
| 240 | m_rowcxx . . $ table_mems_global_by_event_name#m_row..m_statcxx . . $ row_mems_global_by_event_name#m_stat..set_fieldcxx . . $ PFS_memory_stat_row#set_field(d4d38aba05377c48).(f->field_indexcxx . . $ Field#field_index. - 1, f); |
| 241 | break; |
| 242 | } |
| 243 | } |
| 244 | } |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 |