| 1 | /* Copyright (c) 2008, 2011, 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 as published by |
| 5 | the Free Software Foundation; version 2 of the License. |
| 6 | |
| 7 | This program is distributed in the hope that it will be useful, |
| 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | GNU General Public License for more details. |
| 11 | |
| 12 | You should have received a copy of the GNU General Public License |
| 13 | along with this program; if not, write to the Free Software Foundation, |
| 14 | 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */ |
| 15 | |
| 16 | /** |
| 17 | @file storage/perfschema/table_file_summary.cc |
| 18 | Table FILE_SUMMARY_BY_EVENT_NAME(implementation). |
| 19 | */ |
| 20 | |
| 21 | #include "my_global.h" |
| 22 | #include "my_pthread.h" |
| 23 | #include "pfs_instr_class.h" |
| 24 | #include "pfs_column_types.h" |
| 25 | #include "pfs_column_values.h" |
| 26 | #include "table_file_summary_by_event_name.h" |
| 27 | #include "pfs_global.h" |
| 28 | #include "pfs_visitor.h" |
| 29 | |
| 30 | THR_LOCK table_file_summary_by_event_name::m_table_lock; |
| 31 | |
| 32 | PFS_engine_table_share |
| 33 | table_file_summary_by_event_name::m_share= |
| 34 | { |
| 35 | { C_STRING_WITH_LEN("file_summary_by_event_name" ) }, |
| 36 | &pfs_truncatable_acl, |
| 37 | &table_file_summary_by_event_name::create, |
| 38 | NULL, /* write_row */ |
| 39 | table_file_summary_by_event_name::delete_all_rows, |
| 40 | NULL, /* get_row_count */ |
| 41 | 1000, /* records */ |
| 42 | sizeof(PFS_simple_index), |
| 43 | &m_table_lock, |
| 44 | { C_STRING_WITH_LEN("CREATE TABLE file_summary_by_event_name(" |
| 45 | "EVENT_NAME VARCHAR(128) not null," |
| 46 | "COUNT_STAR BIGINT unsigned not null," |
| 47 | "SUM_TIMER_WAIT BIGINT unsigned not null," |
| 48 | "MIN_TIMER_WAIT BIGINT unsigned not null," |
| 49 | "AVG_TIMER_WAIT BIGINT unsigned not null," |
| 50 | "MAX_TIMER_WAIT BIGINT unsigned not null," |
| 51 | "COUNT_READ BIGINT unsigned not null," |
| 52 | "SUM_TIMER_READ BIGINT unsigned not null," |
| 53 | "MIN_TIMER_READ BIGINT unsigned not null," |
| 54 | "AVG_TIMER_READ BIGINT unsigned not null," |
| 55 | "MAX_TIMER_READ BIGINT unsigned not null," |
| 56 | "SUM_NUMBER_OF_BYTES_READ BIGINT not null," |
| 57 | "COUNT_WRITE BIGINT unsigned not null," |
| 58 | "SUM_TIMER_WRITE BIGINT unsigned not null," |
| 59 | "MIN_TIMER_WRITE BIGINT unsigned not null," |
| 60 | "AVG_TIMER_WRITE BIGINT unsigned not null," |
| 61 | "MAX_TIMER_WRITE BIGINT unsigned not null," |
| 62 | "SUM_NUMBER_OF_BYTES_WRITE BIGINT not null," |
| 63 | "COUNT_MISC BIGINT unsigned not null," |
| 64 | "SUM_TIMER_MISC BIGINT unsigned not null," |
| 65 | "MIN_TIMER_MISC BIGINT unsigned not null," |
| 66 | "AVG_TIMER_MISC BIGINT unsigned not null," |
| 67 | "MAX_TIMER_MISC BIGINT unsigned not null)" ) } |
| 68 | }; |
| 69 | |
| 70 | PFS_engine_table* table_file_summary_by_event_name::create(void) |
| 71 | { |
| 72 | return new table_file_summary_by_event_name(); |
| 73 | } |
| 74 | |
| 75 | int table_file_summary_by_event_name::delete_all_rows(void) |
| 76 | { |
| 77 | reset_file_instance_io(); |
| 78 | reset_file_class_io(); |
| 79 | return 0; |
| 80 | } |
| 81 | |
| 82 | table_file_summary_by_event_name::table_file_summary_by_event_name() |
| 83 | : PFS_engine_table(&m_share, &m_pos), |
| 84 | m_pos(1), m_next_pos(1) |
| 85 | {} |
| 86 | |
| 87 | void table_file_summary_by_event_name::reset_position(void) |
| 88 | { |
| 89 | m_pos.m_index= 1; |
| 90 | m_next_pos.m_index= 1; |
| 91 | } |
| 92 | |
| 93 | int table_file_summary_by_event_name::rnd_next(void) |
| 94 | { |
| 95 | PFS_file_class *file_class; |
| 96 | |
| 97 | m_pos.set_at(&m_next_pos); |
| 98 | |
| 99 | file_class= find_file_class(m_pos.m_index); |
| 100 | if (file_class) |
| 101 | { |
| 102 | make_row(file_class); |
| 103 | m_next_pos.set_after(&m_pos); |
| 104 | return 0; |
| 105 | } |
| 106 | |
| 107 | return HA_ERR_END_OF_FILE; |
| 108 | } |
| 109 | |
| 110 | int table_file_summary_by_event_name::rnd_pos(const void *pos) |
| 111 | { |
| 112 | PFS_file_class *file_class; |
| 113 | |
| 114 | set_position(pos); |
| 115 | |
| 116 | file_class= find_file_class(m_pos.m_index); |
| 117 | if (file_class) |
| 118 | { |
| 119 | make_row(file_class); |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | return HA_ERR_RECORD_DELETED; |
| 124 | } |
| 125 | |
| 126 | /** |
| 127 | Build a row. |
| 128 | @param klass the file class the cursor is reading |
| 129 | */ |
| 130 | void table_file_summary_by_event_name::make_row(PFS_file_class *file_class) |
| 131 | { |
| 132 | m_row.m_event_name.make_row(file_class); |
| 133 | |
| 134 | PFS_instance_file_io_stat_visitor visitor; |
| 135 | PFS_instance_iterator::visit_file_instances(file_class, &visitor); |
| 136 | |
| 137 | time_normalizer *normalizer= time_normalizer::get(wait_timer); |
| 138 | |
| 139 | /* Collect timer and byte count stats */ |
| 140 | m_row.m_io_stat.set(normalizer, &visitor.m_file_io_stat); |
| 141 | m_row_exists= true; |
| 142 | |
| 143 | } |
| 144 | |
| 145 | int table_file_summary_by_event_name::read_row_values(TABLE *table, |
| 146 | unsigned char *, |
| 147 | Field **fields, |
| 148 | bool read_all) |
| 149 | { |
| 150 | Field *f; |
| 151 | |
| 152 | if (unlikely(!m_row_exists)) |
| 153 | return HA_ERR_RECORD_DELETED; |
| 154 | |
| 155 | /* Set the null bits */ |
| 156 | DBUG_ASSERT(table->s->null_bytes == 0); |
| 157 | |
| 158 | for (; (f= *fields) ; fields++) |
| 159 | { |
| 160 | if (read_all || bitmap_is_set(table->read_set, f->field_index)) |
| 161 | { |
| 162 | switch(f->field_index) |
| 163 | { |
| 164 | case 0: /* EVENT_NAME */ |
| 165 | m_row.m_event_name.set_field(f); |
| 166 | break; |
| 167 | case 1: /* COUNT_STAR */ |
| 168 | set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_count); |
| 169 | break; |
| 170 | case 2: /* SUM_TIMER_WAIT */ |
| 171 | set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_sum); |
| 172 | break; |
| 173 | case 3: /* MIN_TIMER_WAIT */ |
| 174 | set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_min); |
| 175 | break; |
| 176 | case 4: /* AVG_TIMER_WAIT */ |
| 177 | set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_avg); |
| 178 | break; |
| 179 | case 5: /* MAX_TIMER_WAIT */ |
| 180 | set_field_ulonglong(f, m_row.m_io_stat.m_all.m_waits.m_max); |
| 181 | break; |
| 182 | |
| 183 | case 6: /* COUNT_READ */ |
| 184 | set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_count); |
| 185 | break; |
| 186 | case 7: /* SUM_TIMER_READ */ |
| 187 | set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_sum); |
| 188 | break; |
| 189 | case 8: /* MIN_TIMER_READ */ |
| 190 | set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_min); |
| 191 | break; |
| 192 | case 9: /* AVG_TIMER_READ */ |
| 193 | set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_avg); |
| 194 | break; |
| 195 | case 10: /* MAX_TIMER_READ */ |
| 196 | set_field_ulonglong(f, m_row.m_io_stat.m_read.m_waits.m_max); |
| 197 | break; |
| 198 | case 11: /* SUM_NUMBER_OF_BYTES_READ */ |
| 199 | set_field_ulonglong(f, m_row.m_io_stat.m_read.m_bytes); |
| 200 | break; |
| 201 | |
| 202 | case 12: /* COUNT_WRITE */ |
| 203 | set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_count); |
| 204 | break; |
| 205 | case 13: /* SUM_TIMER_WRITE */ |
| 206 | set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_sum); |
| 207 | break; |
| 208 | case 14: /* MIN_TIMER_WRITE */ |
| 209 | set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_min); |
| 210 | break; |
| 211 | case 15: /* AVG_TIMER_WRITE */ |
| 212 | set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_avg); |
| 213 | break; |
| 214 | case 16: /* MAX_TIMER_WRITE */ |
| 215 | set_field_ulonglong(f, m_row.m_io_stat.m_write.m_waits.m_max); |
| 216 | break; |
| 217 | case 17: /* SUM_NUMBER_OF_BYTES_WRITE */ |
| 218 | set_field_ulonglong(f, m_row.m_io_stat.m_write.m_bytes); |
| 219 | break; |
| 220 | |
| 221 | case 18: /* COUNT_MISC */ |
| 222 | set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_count); |
| 223 | break; |
| 224 | case 19: /* SUM_TIMER_MISC */ |
| 225 | set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_sum); |
| 226 | break; |
| 227 | case 20: /* MIN_TIMER_MISC */ |
| 228 | set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_min); |
| 229 | break; |
| 230 | case 21: /* AVG_TIMER_MISC */ |
| 231 | set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_avg); |
| 232 | break; |
| 233 | case 22: /* MAX_TIMER_MISC */ |
| 234 | set_field_ulonglong(f, m_row.m_io_stat.m_misc.m_waits.m_max); |
| 235 | break; |
| 236 | |
| 237 | default: |
| 238 | DBUG_ASSERT(false); |
| 239 | break; |
| 240 | } |
| 241 | } // if |
| 242 | } // for |
| 243 | |
| 244 | return 0; |
| 245 | } |
| 246 | |