|
1 |
| -/* Copyright (c) 2015, 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/pfs_status.cc |
18 |
| - Status variables statistics (implementation). |
19 |
| -*/ |
20 |
| - |
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_status.h" |
30 |
| -#include "pfs_atomic.h" |
31 |
| -#include "pfs_buffer_container.h" |
32 |
| - |
33 |
| -#include "sql_show.h" /* reset_status_vars */ |
34 |
| - |
35 |
| -PFS_status_stats::PFS_status_stats() |
36 |
| -{ |
37 |
| - reset(); |
38 |
| -} |
39 |
| - |
40 |
| -void PFS_status_stats::reset() |
41 |
| -{ |
42 |
| - m_has_stats= false; |
43 |
| - memset(&m_stats, 0, sizeof(m_stats)); |
44 |
| -} |
45 |
| - |
46 |
| -void PFS_status_stats::aggregate(const PFS_status_stats *from) |
47 |
| -{ |
48 |
| - if (from->m_has_stats) |
49 |
| - { |
50 |
| - m_has_stats= true; |
51 |
| - for (int i= 0; i < COUNT_GLOBAL_STATUS_VARS; i++) |
52 |
| - { |
53 |
| - m_stats[i] += from->m_stats[i]; |
54 |
| - } |
55 |
| - } |
56 |
| -} |
57 |
| - |
58 |
| -void PFS_status_stats::aggregate_from(const STATUS_VAR *from) |
59 |
| -{ |
60 |
| - ulonglong *from_var= (ulonglong*) from; |
61 |
| - |
62 |
| - m_has_stats= true; |
63 |
| - for (int i= 0; |
64 |
| - i < COUNT_GLOBAL_STATUS_VARS; |
65 |
| - i++, from_var++) |
66 |
| - { |
67 |
| - m_stats[i] += *from_var; |
68 |
| - } |
69 |
| -} |
70 |
| - |
71 |
| -void PFS_status_stats::aggregate_to(STATUS_VAR *to) |
72 |
| -{ |
73 |
| - if (m_has_stats) |
74 |
| - { |
75 |
| - ulonglong *to_var= (ulonglong*) to; |
76 |
| - |
77 |
| - for (int i= 0; |
78 |
| - i < COUNT_GLOBAL_STATUS_VARS; |
79 |
| - i++, to_var++) |
80 |
| - { |
81 |
| - *to_var += m_stats[i]; |
82 |
| - } |
83 |
| - } |
84 |
| -} |
85 |
| - |
86 |
| -static void fct_reset_status_by_thread(PFS_thread *thread) |
87 |
| -{ |
88 |
| - PFS_account *account; |
89 |
| - PFS_user *user; |
90 |
| - PFS_host *host; |
91 |
| - |
92 |
| - if (thread->m_lock.is_populated()) |
93 |
| - { |
94 |
| - account= sanitize_account(thread->m_account); |
95 |
| - user= sanitize_user(thread->m_user); |
96 |
| - host= sanitize_host(thread->m_host); |
97 |
| - aggregate_thread_status(thread, account, user, host); |
98 |
| - } |
99 |
| -} |
100 |
| - |
101 |
| -/** Reset table STATUS_BY_THREAD data. */ |
102 |
| -void reset_status_by_thread() |
103 |
| -{ |
104 |
| - global_thread_container.apply_all(fct_reset_status_by_thread); |
105 |
| -} |
106 |
| - |
107 |
| -static void fct_reset_status_by_account(PFS_account *account) |
108 |
| -{ |
109 |
| - PFS_user *user; |
110 |
| - PFS_host *host; |
111 |
| - |
112 |
| - if (account->m_lock.is_populated()) |
113 |
| - { |
114 |
| - user= sanitize_user(account->m_user); |
115 |
| - host= sanitize_host(account->m_host); |
116 |
| - account->aggregate_status(user, host); |
117 |
| - } |
118 |
| -} |
119 |
| - |
120 |
| -/** Reset table STATUS_BY_ACCOUNT data. */ |
121 |
| -void reset_status_by_account() |
122 |
| -{ |
123 |
| - global_account_container.apply_all(fct_reset_status_by_account); |
124 |
| -} |
125 |
| - |
126 |
| -static void fct_reset_status_by_user(PFS_user *user) |
127 |
| -{ |
128 |
| - if (user->m_lock.is_populated()) |
129 |
| - user->aggregate_status(); |
130 |
| -} |
131 |
| - |
132 |
| -/** Reset table STATUS_BY_USER data. */ |
133 |
| -void reset_status_by_user() |
134 |
| -{ |
135 |
| - global_user_container.apply_all(fct_reset_status_by_user); |
136 |
| -} |
137 |
| - |
138 |
| -static void fct_reset_status_by_host(PFS_host *host) |
139 |
| -{ |
140 |
| - if (host->m_lock.is_populated()) |
141 |
| - host->aggregate_status(); |
142 |
| -} |
143 |
| - |
144 |
| -/** Reset table STATUS_BY_HOST data. */ |
145 |
| -void reset_status_by_host() |
146 |
| -{ |
147 |
| - global_host_container.apply_all(fct_reset_status_by_host); |
148 |
| -} |
149 |
| - |
150 |
| -/** Reset table GLOBAL_STATUS data. */ |
151 |
| -void reset_global_status() |
152 |
| -{ |
153 |
| - /* |
154 |
| - Do not memset global_status_var, |
155 |
| - NO_FLUSH counters need to be preserved |
156 |
| - */ |
157 |
| - reset_status_vars(); |
158 |
| -} |
159 |
| - |
| 1 | +/* Copyright (c) 2015, 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/pfs_status.cc |
| 18 | + Status variables statistics (implementation). |
| 19 | +*/ |
| 20 | + |
| 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_status.h" |
| 30 | +#include "pfs_atomic.h" |
| 31 | +#include "pfs_buffer_container.h" |
| 32 | + |
| 33 | +#include "sql_show.h" /* reset_status_vars */ |
| 34 | + |
| 35 | +PFS_status_stats::PFS_status_stats() |
| 36 | +{ |
| 37 | + reset(); |
| 38 | +} |
| 39 | + |
| 40 | +void PFS_status_stats::reset() |
| 41 | +{ |
| 42 | + m_has_stats= false; |
| 43 | + memset(&m_stats, 0, sizeof(m_stats)); |
| 44 | +} |
| 45 | + |
| 46 | +void PFS_status_stats::aggregate(const PFS_status_stats *from) |
| 47 | +{ |
| 48 | + if (from->m_has_stats) |
| 49 | + { |
| 50 | + m_has_stats= true; |
| 51 | + for (int i= 0; i < COUNT_GLOBAL_STATUS_VARS; i++) |
| 52 | + { |
| 53 | + m_stats[i] += from->m_stats[i]; |
| 54 | + } |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +void PFS_status_stats::aggregate_from(const STATUS_VAR *from) |
| 59 | +{ |
| 60 | + ulonglong *from_var= (ulonglong*) from; |
| 61 | + |
| 62 | + m_has_stats= true; |
| 63 | + for (int i= 0; |
| 64 | + i < COUNT_GLOBAL_STATUS_VARS; |
| 65 | + i++, from_var++) |
| 66 | + { |
| 67 | + m_stats[i] += *from_var; |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +void PFS_status_stats::aggregate_to(STATUS_VAR *to) |
| 72 | +{ |
| 73 | + if (m_has_stats) |
| 74 | + { |
| 75 | + ulonglong *to_var= (ulonglong*) to; |
| 76 | + |
| 77 | + for (int i= 0; |
| 78 | + i < COUNT_GLOBAL_STATUS_VARS; |
| 79 | + i++, to_var++) |
| 80 | + { |
| 81 | + *to_var += m_stats[i]; |
| 82 | + } |
| 83 | + } |
| 84 | +} |
| 85 | + |
| 86 | +static void fct_reset_status_by_thread(PFS_thread *thread) |
| 87 | +{ |
| 88 | + PFS_account *account; |
| 89 | + PFS_user *user; |
| 90 | + PFS_host *host; |
| 91 | + |
| 92 | + if (thread->m_lock.is_populated()) |
| 93 | + { |
| 94 | + account= sanitize_account(thread->m_account); |
| 95 | + user= sanitize_user(thread->m_user); |
| 96 | + host= sanitize_host(thread->m_host); |
| 97 | + aggregate_thread_status(thread, account, user, host); |
| 98 | + } |
| 99 | +} |
| 100 | + |
| 101 | +/** Reset table STATUS_BY_THREAD data. */ |
| 102 | +void reset_status_by_thread() |
| 103 | +{ |
| 104 | + global_thread_container.apply_all(fct_reset_status_by_thread); |
| 105 | +} |
| 106 | + |
| 107 | +static void fct_reset_status_by_account(PFS_account *account) |
| 108 | +{ |
| 109 | + PFS_user *user; |
| 110 | + PFS_host *host; |
| 111 | + |
| 112 | + if (account->m_lock.is_populated()) |
| 113 | + { |
| 114 | + user= sanitize_user(account->m_user); |
| 115 | + host= sanitize_host(account->m_host); |
| 116 | + account->aggregate_status(user, host); |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +/** Reset table STATUS_BY_ACCOUNT data. */ |
| 121 | +void reset_status_by_account() |
| 122 | +{ |
| 123 | + global_account_container.apply_all(fct_reset_status_by_account); |
| 124 | +} |
| 125 | + |
| 126 | +static void fct_reset_status_by_user(PFS_user *user) |
| 127 | +{ |
| 128 | + if (user->m_lock.is_populated()) |
| 129 | + user->aggregate_status(); |
| 130 | +} |
| 131 | + |
| 132 | +/** Reset table STATUS_BY_USER data. */ |
| 133 | +void reset_status_by_user() |
| 134 | +{ |
| 135 | + global_user_container.apply_all(fct_reset_status_by_user); |
| 136 | +} |
| 137 | + |
| 138 | +static void fct_reset_status_by_host(PFS_host *host) |
| 139 | +{ |
| 140 | + if (host->m_lock.is_populated()) |
| 141 | + host->aggregate_status(); |
| 142 | +} |
| 143 | + |
| 144 | +/** Reset table STATUS_BY_HOST data. */ |
| 145 | +void reset_status_by_host() |
| 146 | +{ |
| 147 | + global_host_container.apply_all(fct_reset_status_by_host); |
| 148 | +} |
| 149 | + |
| 150 | +/** Reset table GLOBAL_STATUS data. */ |
| 151 | +void reset_global_status() |
| 152 | +{ |
| 153 | + /* |
| 154 | + Do not memset global_status_var, |
| 155 | + NO_FLUSH counters need to be preserved |
| 156 | + */ |
| 157 | + reset_status_vars(); |
| 158 | +} |
| 159 | + |
0 commit comments