MySQL 8.2.0
Source Code Documentation
pfs_account.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2023, Oracle and/or its affiliates.
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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is also distributed with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have included with MySQL.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License, version 2.0, for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 */
23
24#ifndef PFS_ACCOUNT_H
25#define PFS_ACCOUNT_H
26
27/**
28 @file storage/perfschema/pfs_account.h
29 Performance schema account (declarations).
30*/
31
32#include <sys/types.h>
33#include <atomic>
34
35#include "lf.h"
36#include "my_hostname.h" /* HOSTNAME_LENGTH */
37#include "my_inttypes.h"
38#include "mysql_com.h" /* USERNAME_LENGTH */
43
44struct PFS_global_param;
45struct PFS_user;
46struct PFS_host;
47struct PFS_thread;
51
52/**
53 @addtogroup performance_schema_buffers
54 @{
55*/
56
57/** Hash key for an account. */
59 /** User name. */
61 /** Host name. */
63};
64
65/** Per account statistics. */
67 public:
68 inline void init_refcount() { m_refcount.store(1); }
69
70 inline int get_refcount() { return m_refcount.load(); }
71
72 inline void inc_refcount() { ++m_refcount; }
73
74 inline void dec_refcount() { --m_refcount; }
75
76 void aggregate(bool alive, PFS_user *safe_user, PFS_host *safe_host);
77 void aggregate_waits(PFS_user *safe_user, PFS_host *safe_host);
78 void aggregate_stages(PFS_user *safe_user, PFS_host *safe_host);
79 void aggregate_statements(PFS_user *safe_user, PFS_host *safe_host);
80 void aggregate_transactions(PFS_user *safe_user, PFS_host *safe_host);
81 void aggregate_errors(PFS_user *safe_user, PFS_host *safe_host);
82 void aggregate_memory(bool alive, PFS_user *safe_user, PFS_host *safe_host);
83 void aggregate_status(PFS_user *safe_user, PFS_host *safe_host);
84 void aggregate_stats(PFS_user *safe_user, PFS_host *safe_host);
85 void release();
86
87 /** Reset all memory statistics. */
88 void rebase_memory_stats();
89
90 void carry_memory_stat_alloc_delta(PFS_memory_stat_alloc_delta *delta,
91 uint index);
92 void carry_memory_stat_free_delta(PFS_memory_stat_free_delta *delta,
93 uint index);
94
96 m_has_memory_stats = false;
97 m_instr_class_memory_stats = array;
98 }
99
101 if (!m_has_memory_stats) {
102 return nullptr;
103 }
104 return m_instr_class_memory_stats;
105 }
106
108 if (!m_has_memory_stats) {
109 rebase_memory_stats();
110 m_has_memory_stats = true;
111 }
112 return m_instr_class_memory_stats;
113 }
114
115 /** Internal lock. */
118 /** True if this account is enabled, per rules in table SETUP_ACTORS. */
120 /** True if this account has history enabled, per rules in table SETUP_ACTORS.
121 */
125
127 m_disconnected_count = 0;
128 m_max_controlled_memory = 0;
129 m_max_total_memory = 0;
130 }
131
132 void aggregate_disconnect(ulonglong controlled_memory,
133 ulonglong total_memory);
134
138
139 private:
140 std::atomic<int> m_refcount;
141
142 /**
143 Per account memory aggregated statistics.
144 This member holds the data for the table
145 PERFORMANCE_SCHEMA.MEMORY_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME.
146 Immutable, safe to use without internal lock.
147 */
149};
150
151int init_account(const PFS_global_param *param);
152void cleanup_account();
153int init_account_hash(const PFS_global_param *param);
155
157 const PFS_user_name *user,
158 const PFS_host_name *host);
159
161void purge_all_account();
162
164
165/* For show status. */
166
167extern LF_HASH account_hash;
168
169/** @} */
170#endif
PFS_account * find_or_create_account(PFS_thread *thread, const PFS_user_name *user, const PFS_host_name *host)
Definition: pfs_account.cc:164
LF_HASH account_hash
Definition: pfs_account.cc:51
int init_account(const PFS_global_param *param)
Initialize the user buffers.
Definition: pfs_account.cc:59
void cleanup_account()
Cleanup all the account buffers.
Definition: pfs_account.cc:68
void cleanup_account_hash()
Cleanup the user hash.
Definition: pfs_account.cc:141
int init_account_hash(const PFS_global_param *param)
Initialize the user hash.
Definition: pfs_account.cc:129
void purge_all_account()
Purge non connected accounts, reset stats of connected account.
Definition: pfs_account.cc:719
PFS_account * sanitize_account(PFS_account *unsafe)
Definition: pfs_account.cc:666
void update_accounts_derived_flags(PFS_thread *thread)
Definition: pfs_account.cc:751
Common definition used by mysys, performance schema and server & client.
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:55
Common definition between mysql server & client.
char * user
Definition: mysqladmin.cc:64
const char * host
Definition: mysqladmin.cc:63
Performance schema connection slice (declarations).
Miscellaneous global dependencies (declarations).
#define PFS_ALIGNED
Definition: pfs_global.h:56
Performance schema internal locks (declarations).
Object names (declarations).
Definition: lf.h:186
Hash key for an account.
Definition: pfs_account.h:58
PFS_user_name m_user_name
User name.
Definition: pfs_account.h:60
PFS_host_name m_host_name
Host name.
Definition: pfs_account.h:62
Per account statistics.
Definition: pfs_account.h:66
pfs_lock m_lock
Internal lock.
Definition: pfs_account.h:116
ulonglong m_max_controlled_memory
Definition: pfs_account.h:136
ulonglong m_max_total_memory
Definition: pfs_account.h:137
bool m_enabled
True if this account is enabled, per rules in table SETUP_ACTORS.
Definition: pfs_account.h:119
PFS_user * m_user
Definition: pfs_account.h:123
const PFS_memory_shared_stat * read_instr_class_memory_stats() const
Definition: pfs_account.h:100
void set_instr_class_memory_stats(PFS_memory_shared_stat *array)
Definition: pfs_account.h:95
PFS_memory_shared_stat * m_instr_class_memory_stats
Per account memory aggregated statistics.
Definition: pfs_account.h:148
void dec_refcount()
Definition: pfs_account.h:74
void init_refcount()
Definition: pfs_account.h:68
ulonglong m_disconnected_count
Definition: pfs_account.h:135
int get_refcount()
Definition: pfs_account.h:70
PFS_host * m_host
Definition: pfs_account.h:124
PFS_memory_shared_stat * write_instr_class_memory_stats()
Definition: pfs_account.h:107
std::atomic< int > m_refcount
Definition: pfs_account.h:140
PFS_account_key m_key
Definition: pfs_account.h:117
void inc_refcount()
Definition: pfs_account.h:72
bool m_history
True if this account has history enabled, per rules in table SETUP_ACTORS.
Definition: pfs_account.h:122
void reset_connections_stats()
Definition: pfs_account.h:126
A connection slice, an arbitrary grouping of several connections.
Definition: pfs_con_slice.h:53
Performance schema global sizing parameters.
Definition: pfs_server.h:118
Definition: pfs_name.h:245
Per host statistics.
Definition: pfs_host.h:63
Definition: pfs_stat.h:936
Definition: pfs_stat.h:882
Definition: pfs_stat.h:887
Instrumented thread implementation.
Definition: pfs_instr.h:374
Definition: pfs_name.h:224
Per user statistics.
Definition: pfs_user.h:62
A 'lock' protecting performance schema internal buffers.
Definition: pfs_lock.h:153
static void alive(server *s)
Definition: xcom_transport.cc:159