MySQL 5.6.14 Source Code Document
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
pfs_events_stages.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_stages.h"
30 #include "pfs_atomic.h"
31 #include "m_string.h"
32 
33 ulong events_stages_history_long_size= 0;
40 
47 
52 int init_events_stages_history_long(uint events_stages_history_long_sizing)
53 {
54  events_stages_history_long_size= events_stages_history_long_sizing;
57 
58  if (events_stages_history_long_size == 0)
59  return 0;
60 
61  events_stages_history_long_array=
62  PFS_MALLOC_ARRAY(events_stages_history_long_size, PFS_events_stages,
63  MYF(MY_ZEROFILL));
64 
65  return (events_stages_history_long_array ? 0 : 1);
66 }
67 
70 {
71  pfs_free(events_stages_history_long_array);
72  events_stages_history_long_array= NULL;
73 }
74 
75 static inline void copy_events_stages(PFS_events_stages *dest,
76  const PFS_events_stages *source)
77 {
78  memcpy(dest, source, sizeof(PFS_events_stages));
79 }
80 
87 {
88  if (unlikely(events_stages_history_per_thread == 0))
89  return;
90 
91  DBUG_ASSERT(thread->m_stages_history != NULL);
92 
93  uint index= thread->m_stages_history_index;
94 
95  /*
96  A concurrent thread executing TRUNCATE TABLE EVENTS_STAGES_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_stages_history will filter this out.
102  */
103  copy_events_stages(&thread->m_stages_history[index], stage);
104 
105  index++;
107  {
108  index= 0;
109  thread->m_stages_history_full= true;
110  }
111  thread->m_stages_history_index= index;
112 }
113 
119 {
120  if (unlikely(events_stages_history_long_size == 0))
121  return;
122 
123  DBUG_ASSERT(events_stages_history_long_array != NULL);
124 
126 
127  index= index % events_stages_history_long_size;
128  if (index == 0)
130 
131  /* See related comment in insert_events_stages_history. */
132  copy_events_stages(&events_stages_history_long_array[index], stage);
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_thread->m_stage_current.m_class= NULL;
144  }
145 }
146 
149 {
150  PFS_thread *pfs_thread= thread_array;
151  PFS_thread *pfs_thread_last= thread_array + thread_max;
152 
153  for ( ; pfs_thread < pfs_thread_last; pfs_thread++)
154  {
155  PFS_events_stages *pfs= pfs_thread->m_stages_history;
157 
158  pfs_thread->m_stages_history_index= 0;
159  pfs_thread->m_stages_history_full= false;
160  for ( ; pfs < pfs_last; pfs++)
161  pfs->m_class= NULL;
162  }
163 }
164 
167 {
170 
172  PFS_events_stages *pfs_last= pfs + events_stages_history_long_size;
173  for ( ; pfs < pfs_last; pfs++)
174  pfs->m_class= NULL;
175 }
176 
179 {
180  PFS_thread *thread= thread_array;
181  PFS_thread *thread_last= thread_array + thread_max;
182  PFS_account *account;
183  PFS_user *user;
184  PFS_host *host;
185 
186  for ( ; thread < thread_last; thread++)
187  {
188  if (thread->m_lock.is_populated())
189  {
190  account= sanitize_account(thread->m_account);
191  user= sanitize_user(thread->m_user);
192  host= sanitize_host(thread->m_host);
193  aggregate_thread_stages(thread, account, user, host);
194  }
195  }
196 }
197 
200 {
201  PFS_account *pfs= account_array;
202  PFS_account *pfs_last= account_array + account_max;
203  PFS_user *user;
204  PFS_host *host;
205 
206  for ( ; pfs < pfs_last; pfs++)
207  {
208  if (pfs->m_lock.is_populated())
209  {
210  user= sanitize_user(pfs->m_user);
211  host= sanitize_host(pfs->m_host);
212  pfs->aggregate_stages(user, host);
213  }
214  }
215 }
216 
219 {
220  PFS_user *pfs= user_array;
221  PFS_user *pfs_last= user_array + user_max;
222 
223  for ( ; pfs < pfs_last; pfs++)
224  {
225  if (pfs->m_lock.is_populated())
226  pfs->aggregate_stages();
227  }
228 }
229 
232 {
233  PFS_host *pfs= host_array;
234  PFS_host *pfs_last= host_array + host_max;
235 
236  for ( ; pfs < pfs_last; pfs++)
237  {
238  if (pfs->m_lock.is_populated())
239  pfs->aggregate_stages();
240  }
241 }
242 
245 {
246  PFS_stage_stat *stat= global_instr_class_stages_array;
247  PFS_stage_stat *stat_last= global_instr_class_stages_array + stage_class_max;
248 
249  for ( ; stat < stat_last; stat++)
250  stat->reset();
251 }
252