MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pfs_events_statements.cc
Go to the documentation of this file.
1 /* Copyright (c) 2010, 2013, 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 
21 #include "my_global.h"
22 #include "my_sys.h"
23 #include "pfs_global.h"
24 #include "pfs_instr_class.h"
25 #include "pfs_instr.h"
26 #include "pfs_account.h"
27 #include "pfs_host.h"
28 #include "pfs_user.h"
29 #include "pfs_events_statements.h"
30 #include "pfs_atomic.h"
31 #include "m_string.h"
32 
33 ulong events_statements_history_long_size= 0;
40 
47 
52 int init_events_statements_history_long(uint events_statements_history_long_sizing)
53 {
54  events_statements_history_long_size= events_statements_history_long_sizing;
57 
58  if (events_statements_history_long_size == 0)
59  return 0;
60 
61  events_statements_history_long_array=
62  PFS_MALLOC_ARRAY(events_statements_history_long_size, PFS_events_statements,
63  MYF(MY_ZEROFILL));
64 
65  return (events_statements_history_long_array ? 0 : 1);
66 }
67 
70 {
71  pfs_free(events_statements_history_long_array);
72  events_statements_history_long_array= NULL;
73 }
74 
75 static inline void copy_events_statements(PFS_events_statements *dest,
76  const PFS_events_statements *source)
77 {
78  memcpy(dest, source, sizeof(PFS_events_statements));
79 }
80 
87 {
88  if (unlikely(events_statements_history_per_thread == 0))
89  return;
90 
91  DBUG_ASSERT(thread->m_statements_history != NULL);
92 
93  uint index= thread->m_statements_history_index;
94 
95  /*
96  A concurrent thread executing TRUNCATE TABLE EVENTS_STATEMENTS_CURRENT
97  could alter the data that this thread is inserting,
98  causing a potential race condition.
99  We are not testing for this and insert a possibly empty record,
100  to make this thread (the writer) faster.
101  This is ok, the readers of m_statements_history will filter this out.
102  */
103  copy_events_statements(&thread->m_statements_history[index], statement);
104 
105  index++;
107  {
108  index= 0;
109  thread->m_statements_history_full= true;
110  }
112 }
113 
119 {
120  if (unlikely(events_statements_history_long_size == 0))
121  return ;
122 
123  DBUG_ASSERT(events_statements_history_long_array != NULL);
124 
126 
127  index= index % events_statements_history_long_size;
128  if (index == 0)
130 
131  /* See related comment in insert_events_statements_history. */
132  copy_events_statements(&events_statements_history_long_array[index], statement);
133 }
134 
137 {
138  PFS_thread *pfs_thread= thread_array;
139  PFS_thread *pfs_thread_last= thread_array + thread_max;
140 
141  for ( ; pfs_thread < pfs_thread_last; pfs_thread++)
142  {
143  PFS_events_statements *pfs_stmt= & pfs_thread->m_statement_stack[0];
144  PFS_events_statements *pfs_stmt_last= pfs_stmt + statement_stack_max;
145 
146  for ( ; pfs_stmt < pfs_stmt_last; pfs_stmt++)
147  pfs_stmt->m_class= NULL;
148  }
149 }
150 
153 {
154  PFS_thread *pfs_thread= thread_array;
155  PFS_thread *pfs_thread_last= thread_array + thread_max;
156 
157  for ( ; pfs_thread < pfs_thread_last; pfs_thread++)
158  {
161 
162  pfs_thread->m_statements_history_index= 0;
163  pfs_thread->m_statements_history_full= false;
164  for ( ; pfs < pfs_last; pfs++)
165  pfs->m_class= NULL;
166  }
167 }
168 
171 {
174 
176  PFS_events_statements *pfs_last= pfs + events_statements_history_long_size;
177  for ( ; pfs < pfs_last; pfs++)
178  pfs->m_class= NULL;
179 }
180 
183 {
184  PFS_thread *thread= thread_array;
185  PFS_thread *thread_last= thread_array + thread_max;
186  PFS_account *account;
187  PFS_user *user;
188  PFS_host *host;
189 
190  for ( ; thread < thread_last; thread++)
191  {
192  if (thread->m_lock.is_populated())
193  {
194  account= sanitize_account(thread->m_account);
195  user= sanitize_user(thread->m_user);
196  host= sanitize_host(thread->m_host);
197  aggregate_thread_statements(thread, account, user, host);
198  }
199  }
200 }
201 
204 {
205  PFS_account *pfs= account_array;
206  PFS_account *pfs_last= account_array + account_max;
207  PFS_user *user;
208  PFS_host *host;
209 
210  for ( ; pfs < pfs_last; pfs++)
211  {
212  if (pfs->m_lock.is_populated())
213  {
214  user= sanitize_user(pfs->m_user);
215  host= sanitize_host(pfs->m_host);
216  pfs->aggregate_statements(user, host);
217  }
218  }
219 }
220 
223 {
224  PFS_user *pfs= user_array;
225  PFS_user *pfs_last= user_array + user_max;
226 
227  for ( ; pfs < pfs_last; pfs++)
228  {
229  if (pfs->m_lock.is_populated())
230  pfs->aggregate_statements();
231  }
232 }
233 
236 {
237  PFS_host *pfs= host_array;
238  PFS_host *pfs_last= host_array + host_max;
239 
240  for ( ; pfs < pfs_last; pfs++)
241  {
242  if (pfs->m_lock.is_populated())
243  pfs->aggregate_statements();
244  }
245 }
246 
249 {
250  PFS_statement_stat *stat= global_instr_class_statements_array;
251  PFS_statement_stat *stat_last= global_instr_class_statements_array + statement_class_max;
252 
253  for ( ; stat < stat_last; stat++)
254  stat->reset();
255 }
256