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_setup_timers.cc |
18 | Table SETUP_TIMERS (implementation). |
19 | */ |
20 | |
21 | #include "my_global.h" |
22 | #include "my_pthread.h" |
23 | #include "table_setup_timers.h" |
24 | #include "pfs_column_values.h" |
25 | #include "pfs_timer.h" |
26 | |
27 | #define COUNT_SETUP_TIMERS 4 |
28 | |
29 | static row_setup_timers all_setup_timers_data[COUNT_SETUP_TIMERS]= |
30 | { |
31 | { |
32 | { C_STRING_WITH_LEN("idle" ) }, |
33 | &idle_timer |
34 | }, |
35 | { |
36 | { C_STRING_WITH_LEN("wait" ) }, |
37 | &wait_timer |
38 | }, |
39 | { |
40 | { C_STRING_WITH_LEN("stage" ) }, |
41 | &stage_timer |
42 | }, |
43 | { |
44 | { C_STRING_WITH_LEN("statement" ) }, |
45 | &statement_timer |
46 | } |
47 | }; |
48 | |
49 | THR_LOCK table_setup_timers::m_table_lock; |
50 | |
51 | PFS_engine_table_share |
52 | table_setup_timers::m_share= |
53 | { |
54 | { C_STRING_WITH_LEN("setup_timers" ) }, |
55 | &pfs_updatable_acl, |
56 | &table_setup_timers::create, |
57 | NULL, /* write_row */ |
58 | NULL, /* delete_all_rows */ |
59 | NULL, /* get_row_count */ |
60 | COUNT_SETUP_TIMERS, |
61 | sizeof(PFS_simple_index), |
62 | &m_table_lock, |
63 | { C_STRING_WITH_LEN("CREATE TABLE setup_timers(" |
64 | "NAME VARCHAR(64) not null," |
65 | "TIMER_NAME ENUM ('CYCLE', 'NANOSECOND', 'MICROSECOND', 'MILLISECOND', 'TICK') not null)" ) } |
66 | }; |
67 | |
68 | PFS_engine_table* table_setup_timers::create(void) |
69 | { |
70 | return new table_setup_timers(); |
71 | } |
72 | |
73 | table_setup_timers::table_setup_timers() |
74 | : PFS_engine_table(&m_share, &m_pos), |
75 | m_row(NULL), m_pos(0), m_next_pos(0) |
76 | {} |
77 | |
78 | void table_setup_timers::reset_position(void) |
79 | { |
80 | m_pos.m_index= 0; |
81 | m_next_pos.m_index= 0; |
82 | } |
83 | |
84 | int table_setup_timers::rnd_next(void) |
85 | { |
86 | int result; |
87 | |
88 | m_pos.set_at(&m_next_pos); |
89 | |
90 | if (m_pos.m_index < COUNT_SETUP_TIMERS) |
91 | { |
92 | m_row= &all_setup_timers_data[m_pos.m_index]; |
93 | m_next_pos.set_after(&m_pos); |
94 | result= 0; |
95 | } |
96 | else |
97 | { |
98 | m_row= NULL; |
99 | result= HA_ERR_END_OF_FILE; |
100 | } |
101 | |
102 | return result; |
103 | } |
104 | |
105 | int table_setup_timers::rnd_pos(const void *pos) |
106 | { |
107 | set_position(pos); |
108 | DBUG_ASSERT(m_pos.m_index < COUNT_SETUP_TIMERS); |
109 | m_row= &all_setup_timers_data[m_pos.m_index]; |
110 | return 0; |
111 | } |
112 | |
113 | int table_setup_timers::read_row_values(TABLE *table, |
114 | unsigned char *, |
115 | Field **fields, |
116 | bool read_all) |
117 | { |
118 | Field *f; |
119 | |
120 | DBUG_ASSERT(m_row); |
121 | |
122 | /* Set the null bits */ |
123 | DBUG_ASSERT(table->s->null_bytes == 0); |
124 | |
125 | for (; (f= *fields) ; fields++) |
126 | { |
127 | if (read_all || bitmap_is_set(table->read_set, f->field_index)) |
128 | { |
129 | switch(f->field_index) |
130 | { |
131 | case 0: /* NAME */ |
132 | set_field_varchar_utf8(f, m_row->m_name.str,(uint) m_row->m_name.length); |
133 | break; |
134 | case 1: /* TIMER_NAME */ |
135 | set_field_enum(f, *(m_row->m_timer_name_ptr)); |
136 | break; |
137 | default: |
138 | DBUG_ASSERT(false); |
139 | } |
140 | } |
141 | } |
142 | |
143 | return 0; |
144 | } |
145 | |
146 | int table_setup_timers::update_row_values(TABLE *table, |
147 | const unsigned char *, |
148 | const unsigned char *, |
149 | Field **fields) |
150 | { |
151 | Field *f; |
152 | longlong value; |
153 | |
154 | DBUG_ASSERT(m_row); |
155 | |
156 | for (; (f= *fields) ; fields++) |
157 | { |
158 | if (bitmap_is_set(table->write_set, f->field_index)) |
159 | { |
160 | switch(f->field_index) |
161 | { |
162 | case 0: /* NAME */ |
163 | return HA_ERR_WRONG_COMMAND; |
164 | case 1: /* TIMER_NAME */ |
165 | value= get_field_enum(f); |
166 | if ((value >= FIRST_TIMER_NAME) && (value <= LAST_TIMER_NAME)) |
167 | *(m_row->m_timer_name_ptr)= (enum_timer_name) value; |
168 | else |
169 | return HA_ERR_WRONG_COMMAND; |
170 | break; |
171 | default: |
172 | DBUG_ASSERT(false); |
173 | } |
174 | } |
175 | } |
176 | |
177 | return 0; |
178 | } |
179 | |
180 | |