MySQL 8.3.0
Source Code Documentation
pfs_user.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_USER_H
25#define PFS_USER_H
26
27/**
28 @file storage/perfschema/pfs_user.h
29 Performance schema user (declarations).
30*/
31
32#include <sys/types.h>
33#include <atomic>
34
35#include "lf.h"
36#include "my_inttypes.h"
37#include "mysql_com.h"
42
43struct PFS_global_param;
47struct PFS_thread;
48struct PFS_account;
49
50/**
51 @addtogroup performance_schema_buffers
52 @{
53*/
54
55/** Hash key for a user. */
57 /** User name. */
59};
60
61/** Per user statistics. */
63 public:
64 inline void init_refcount() { m_refcount.store(1); }
65
66 inline int get_refcount() { return m_refcount.load(); }
67
68 inline void inc_refcount() { ++m_refcount; }
69
70 inline void dec_refcount() { --m_refcount; }
71
72 void aggregate(bool alive);
73 void aggregate_waits();
74 void aggregate_stages();
75 void aggregate_statements();
76 void aggregate_transactions();
77 void aggregate_errors();
78 void aggregate_memory(bool alive);
79 void aggregate_status();
80 void aggregate_stats();
81 void release();
82
83 /** Reset all memory statistics. */
84 void rebase_memory_stats();
85
86 void carry_memory_stat_alloc_delta(PFS_memory_stat_alloc_delta *delta,
87 uint index);
88 void carry_memory_stat_free_delta(PFS_memory_stat_free_delta *delta,
89 uint index);
90
92 m_has_memory_stats = false;
93 m_instr_class_memory_stats = array;
94 }
95
97 if (!m_has_memory_stats) {
98 return nullptr;
99 }
100 return m_instr_class_memory_stats;
101 }
102
104 if (!m_has_memory_stats) {
105 rebase_memory_stats();
106 m_has_memory_stats = true;
107 }
108 return m_instr_class_memory_stats;
109 }
110
111 /** Internal lock. */
114
116 m_disconnected_count = 0;
117 m_max_controlled_memory = 0;
118 m_max_total_memory = 0;
119 }
120
121 void aggregate_stats_from(PFS_account *pfs);
122 void aggregate_disconnect(ulonglong controlled_memory,
123 ulonglong total_memory);
124
128
129 private:
130 std::atomic<int> m_refcount;
131
132 /**
133 Per user memory aggregated statistics.
134 This member holds the data for the table
135 PERFORMANCE_SCHEMA.MEMORY_SUMMARY_BY_USER_BY_EVENT_NAME.
136 Immutable, safe to use without internal lock.
137 */
139};
140
141int init_user(const PFS_global_param *param);
142void cleanup_user();
143int init_user_hash(const PFS_global_param *param);
144void cleanup_user_hash();
145
147
149void purge_all_user();
150
151/* For show status. */
152
153extern LF_HASH user_hash;
154
155/** @} */
156#endif
int init_user_hash(const PFS_global_param *param)
Initialize the user hash.
Definition: pfs_user.cc:121
void cleanup_user_hash()
Cleanup the user hash.
Definition: pfs_user.cc:132
void purge_all_user()
Purge non connected users, reset stats of connected users.
Definition: pfs_user.cc:362
void cleanup_user()
Cleanup all the user buffers.
Definition: pfs_user.cc:65
LF_HASH user_hash
Definition: pfs_user.cc:48
int init_user(const PFS_global_param *param)
Initialize the user buffers.
Definition: pfs_user.cc:56
PFS_user * find_or_create_user(PFS_thread *thread, const PFS_user_name *user)
Definition: pfs_user.cc:153
PFS_user * sanitize_user(PFS_user *unsafe)
Definition: pfs_user.cc:321
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
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).
static const LEX_CSTRING pfs
Definition: sql_show_processlist.cc:65
Definition: lf.h:186
Per account statistics.
Definition: pfs_account.h:66
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_stat.h:936
Definition: pfs_stat.h:882
Definition: pfs_stat.h:887
Instrumented thread implementation.
Definition: pfs_instr.h:374
Hash key for a user.
Definition: pfs_user.h:56
PFS_user_name m_user_name
User name.
Definition: pfs_user.h:58
Definition: pfs_name.h:471
Per user statistics.
Definition: pfs_user.h:62
const PFS_memory_shared_stat * read_instr_class_memory_stats() const
Definition: pfs_user.h:96
std::atomic< int > m_refcount
Definition: pfs_user.h:130
int get_refcount()
Definition: pfs_user.h:66
PFS_memory_shared_stat * m_instr_class_memory_stats
Per user memory aggregated statistics.
Definition: pfs_user.h:138
PFS_memory_shared_stat * write_instr_class_memory_stats()
Definition: pfs_user.h:103
void set_instr_class_memory_stats(PFS_memory_shared_stat *array)
Definition: pfs_user.h:91
ulonglong m_disconnected_count
Definition: pfs_user.h:125
pfs_lock m_lock
Internal lock.
Definition: pfs_user.h:112
void dec_refcount()
Definition: pfs_user.h:70
PFS_user_key m_key
Definition: pfs_user.h:113
ulonglong m_max_total_memory
Definition: pfs_user.h:127
ulonglong m_max_controlled_memory
Definition: pfs_user.h:126
void init_refcount()
Definition: pfs_user.h:64
void inc_refcount()
Definition: pfs_user.h:68
void reset_connections_stats()
Definition: pfs_user.h:115
A 'lock' protecting performance schema internal buffers.
Definition: pfs_lock.h:153
static void alive(server *s)
Definition: xcom_transport.cc:172