MySQL 8.0.29
Source Code Documentation
pfs_account.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2022, 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(void) { m_refcount.store(1); }
69
70 inline int get_refcount(void) { return m_refcount.load(); }
71
72 inline void inc_refcount(void) { ++m_refcount; }
73
74 inline void dec_refcount(void) { --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(void);
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
128 private:
129 std::atomic<int> m_refcount;
130
131 /**
132 Per account memory aggregated statistics.
133 This member holds the data for the table
134 PERFORMANCE_SCHEMA.MEMORY_SUMMARY_BY_ACCOUNT_BY_EVENT_NAME.
135 Immutable, safe to use without internal lock.
136 */
138};
139
140int init_account(const PFS_global_param *param);
141void cleanup_account(void);
142int init_account_hash(const PFS_global_param *param);
143void cleanup_account_hash(void);
144
146 const PFS_user_name *user,
147 const PFS_host_name *host);
148
150void purge_all_account(void);
151
153
154/* For show status. */
155
156extern LF_HASH account_hash;
157
158/** @} */
159#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
void cleanup_account(void)
Cleanup all the account buffers.
Definition: pfs_account.cc:68
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
int init_account_hash(const PFS_global_param *param)
Initialize the user hash.
Definition: pfs_account.cc:129
void purge_all_account(void)
Purge non connected accounts, reset stats of connected account.
Definition: pfs_account.cc:743
PFS_account * sanitize_account(PFS_account *unsafe)
Definition: pfs_account.cc:690
void update_accounts_derived_flags(PFS_thread *thread)
Definition: pfs_account.cc:775
void cleanup_account_hash(void)
Cleanup the user hash.
Definition: pfs_account.cc:141
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:59
const char * host
Definition: mysqladmin.cc:58
Performance schema connection slice (declarations).
Miscellaneous global dependencies (declarations).
#define PFS_ALIGNED
Definition: pfs_global.h:54
Performance schema internal locks (declarations).
Object names (declarations).
Definition: lf.h:184
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
void inc_refcount(void)
Definition: pfs_account.h:72
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:137
void dec_refcount(void)
Definition: pfs_account.h:74
ulonglong m_disconnected_count
Definition: pfs_account.h:126
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:129
int get_refcount(void)
Definition: pfs_account.h:70
PFS_account_key m_key
Definition: pfs_account.h:117
bool m_history
True if this account has history enabled, per rules in table SETUP_ACTORS.
Definition: pfs_account.h:122
void init_refcount(void)
Definition: pfs_account.h:68
A connection slice, an arbitrary grouping of several connections.
Definition: pfs_con_slice.h:53
Performance schema global sizing parameters.
Definition: pfs_server.h:112
Definition: pfs_name.h:241
Per host statistics.
Definition: pfs_host.h:62
Definition: pfs_stat.h:919
Definition: pfs_stat.h:865
Definition: pfs_stat.h:870
Instrumented thread implementation.
Definition: pfs_instr.h:372
Definition: pfs_name.h:220
Per user statistics.
Definition: pfs_user.h:61
A 'lock' protecting performance schema internal buffers.
Definition: pfs_lock.h:151
unsigned int uint
Definition: uca-dump.cc:29
static void alive(server *s)
Definition: xcom_transport.cc:159