MySQL 8.0.40
Source Code Documentation
pfs_user.h
Go to the documentation of this file.
1/* Copyright (c) 2010, 2024, 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 designed to work 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 either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 */
24
25#ifndef PFS_USER_H
26#define PFS_USER_H
27
28/**
29 @file storage/perfschema/pfs_user.h
30 Performance schema user (declarations).
31*/
32
33#include <sys/types.h>
34#include <atomic>
35
36#include "lf.h"
37#include "my_inttypes.h"
38#include "mysql_com.h"
43
44struct PFS_global_param;
48struct PFS_thread;
49struct PFS_account;
50
51/**
52 @addtogroup performance_schema_buffers
53 @{
54*/
55
56/** Hash key for a user. */
58 /** User name. */
60};
61
62/** Per user statistics. */
64 public:
65 inline void init_refcount() { m_refcount.store(1); }
66
67 inline int get_refcount() { return m_refcount.load(); }
68
69 inline void inc_refcount() { ++m_refcount; }
70
71 inline void dec_refcount() { --m_refcount; }
72
73 void aggregate(bool alive);
74 void aggregate_waits();
75 void aggregate_stages();
76 void aggregate_statements();
77 void aggregate_transactions();
78 void aggregate_errors();
79 void aggregate_memory(bool alive);
80 void aggregate_status();
81 void aggregate_stats();
82 void release();
83
84 /** Reset all memory statistics. */
85 void rebase_memory_stats();
86
87 void carry_memory_stat_alloc_delta(PFS_memory_stat_alloc_delta *delta,
88 uint index);
89 void carry_memory_stat_free_delta(PFS_memory_stat_free_delta *delta,
90 uint index);
91
93 m_has_memory_stats = false;
94 m_instr_class_memory_stats = array;
95 }
96
98 if (!m_has_memory_stats) {
99 return nullptr;
100 }
101 return m_instr_class_memory_stats;
102 }
103
105 if (!m_has_memory_stats) {
106 rebase_memory_stats();
107 m_has_memory_stats = true;
108 }
109 return m_instr_class_memory_stats;
110 }
111
112 /** Internal lock. */
115
117 m_disconnected_count = 0;
118 m_max_controlled_memory = 0;
119 m_max_total_memory = 0;
120 }
121
122 void aggregate_stats_from(PFS_account *pfs);
123 void aggregate_disconnect(ulonglong controlled_memory,
124 ulonglong total_memory);
125
129
130 private:
131 std::atomic<int> m_refcount;
132
133 /**
134 Per user memory aggregated statistics.
135 This member holds the data for the table
136 PERFORMANCE_SCHEMA.MEMORY_SUMMARY_BY_USER_BY_EVENT_NAME.
137 Immutable, safe to use without internal lock.
138 */
140};
141
142int init_user(const PFS_global_param *param);
143void cleanup_user();
144int init_user_hash(const PFS_global_param *param);
145void cleanup_user_hash();
146
148
150void purge_all_user();
151
152/* For show status. */
153
154extern LF_HASH user_hash;
155
156/** @} */
157#endif
int init_user_hash(const PFS_global_param *param)
Initialize the user hash.
Definition: pfs_user.cc:122
void cleanup_user_hash()
Cleanup the user hash.
Definition: pfs_user.cc:133
void purge_all_user()
Purge non connected users, reset stats of connected users.
Definition: pfs_user.cc:363
void cleanup_user()
Cleanup all the user buffers.
Definition: pfs_user.cc:66
LF_HASH user_hash
Definition: pfs_user.cc:49
int init_user(const PFS_global_param *param)
Initialize the user buffers.
Definition: pfs_user.cc:57
PFS_user * find_or_create_user(PFS_thread *thread, const PFS_user_name *user)
Definition: pfs_user.cc:154
PFS_user * sanitize_user(PFS_user *unsafe)
Definition: pfs_user.cc:322
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
Common definition between mysql server & client.
char * user
Definition: mysqladmin.cc:60
Performance schema connection slice (declarations).
Miscellaneous global dependencies (declarations).
#define PFS_ALIGNED
Definition: pfs_global.h:57
Performance schema internal locks (declarations).
Object names (declarations).
static const LEX_CSTRING pfs
Definition: sql_show_processlist.cc:66
Definition: lf.h:185
Per account statistics.
Definition: pfs_account.h:67
A connection slice, an arbitrary grouping of several connections.
Definition: pfs_con_slice.h:54
Performance schema global sizing parameters.
Definition: pfs_server.h:113
Definition: pfs_stat.h:937
Definition: pfs_stat.h:883
Definition: pfs_stat.h:888
Instrumented thread implementation.
Definition: pfs_instr.h:373
Hash key for a user.
Definition: pfs_user.h:57
PFS_user_name m_user_name
User name.
Definition: pfs_user.h:59
Definition: pfs_name.h:470
Per user statistics.
Definition: pfs_user.h:63
const PFS_memory_shared_stat * read_instr_class_memory_stats() const
Definition: pfs_user.h:97
std::atomic< int > m_refcount
Definition: pfs_user.h:131
int get_refcount()
Definition: pfs_user.h:67
PFS_memory_shared_stat * m_instr_class_memory_stats
Per user memory aggregated statistics.
Definition: pfs_user.h:139
PFS_memory_shared_stat * write_instr_class_memory_stats()
Definition: pfs_user.h:104
void set_instr_class_memory_stats(PFS_memory_shared_stat *array)
Definition: pfs_user.h:92
ulonglong m_disconnected_count
Definition: pfs_user.h:126
pfs_lock m_lock
Internal lock.
Definition: pfs_user.h:113
void dec_refcount()
Definition: pfs_user.h:71
PFS_user_key m_key
Definition: pfs_user.h:114
ulonglong m_max_total_memory
Definition: pfs_user.h:128
ulonglong m_max_controlled_memory
Definition: pfs_user.h:127
void init_refcount()
Definition: pfs_user.h:65
void inc_refcount()
Definition: pfs_user.h:69
void reset_connections_stats()
Definition: pfs_user.h:116
A 'lock' protecting performance schema internal buffers.
Definition: pfs_lock.h:154
unsigned int uint
Definition: uca9-dump.cc:75
static void alive(server *s)
Definition: xcom_transport.cc:161