MySQL 8.0.29
Source Code Documentation
mysql_memory.h
Go to the documentation of this file.
1/* Copyright (c) 2012, 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#ifndef MYSQL_MEMORY_H
24#define MYSQL_MEMORY_H
25
26/**
27 @file include/mysql/psi/mysql_memory.h
28 Instrumentation helpers for memory allocation.
29*/
30
31#include "my_compiler.h"
32#include "my_inttypes.h"
33
34/* HAVE_PSI_*_INTERFACE */
35#include "my_psi_config.h" // IWYU pragma: keep
36
38
39#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
40/* PSI_MEMORY_CALL() as direct call. */
41#include "pfs_memory_provider.h" // IWYU pragma: keep
42#endif
43
44#ifndef PSI_MEMORY_CALL
45#define PSI_MEMORY_CALL(M) psi_memory_service->M
46#endif
47
48/**
49 @defgroup psi_api_memory Memory Instrumentation (API)
50 @ingroup psi_api
51 @{
52*/
53
54/**
55 @def mysql_memory_register(P1, P2, P3)
56 Memory registration.
57*/
58#define mysql_memory_register(P1, P2, P3) \
59 inline_mysql_memory_register(P1, P2, P3)
60
63 const char *category, PSI_memory_info *info, int count)
64#else
65 const char *category [[maybe_unused]], void *info [[maybe_unused]],
66 int count [[maybe_unused]])
67#endif
68{
69#ifdef HAVE_PSI_MEMORY_INTERFACE
70 PSI_MEMORY_CALL(register_memory)(category, info, count);
71#endif
72}
73
74#ifdef HAVE_PSI_MEMORY_INTERFACE
75
76struct my_memory_header {
79 size_t m_size;
81};
83
84#define PSI_HEADER_SIZE 32
85
86#define PSI_MEMORY_MAGIC 1234
87
88#define PSI_MEM_CNT_BIT ((uint)1 << 31)
89#define PSI_REAL_MEM_KEY(P) ((PSI_memory_key)((P) & ~PSI_MEM_CNT_BIT))
90
91#define USER_TO_HEADER(P) ((my_memory_header *)(((char *)P) - PSI_HEADER_SIZE))
92#define HEADER_TO_USER(P) (((char *)P) + PSI_HEADER_SIZE)
93
94#define USER_TO_HEADER_UINT8_T(P) \
95 (((static_cast<uint8_t *>(P)) - PSI_HEADER_SIZE))
96
97#endif
98
99/** @} (end of group psi_api_memory) */
100
101#endif
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:48
struct PSI_thread PSI_thread
Definition: psi_thread_bits.h:81
static void inline_mysql_memory_register(const char *category, PSI_memory_info *info, int count)
Definition: mysql_memory.h:61
Header for compiler-dependent features.
Some integer typedefs for easier portability.
Defines various enable/disable and HAVE_ macros related to the performance schema instrumentation sys...
#define HAVE_PSI_MEMORY_INTERFACE
Definition: my_psi_config.h:205
static int count
Definition: myisam_ftdump.cc:42
#define PSI_MEMORY_CALL(M)
Definition: mysql_memory.h:45
Log info(cout, "NOTE")
static const char * category
Definition: sha2_password.cc:168
Performance schema instrumentation (declarations).
Performance schema instrumentation interface.
Memory instrument information.
Definition: psi_memory_bits.h:57
Definition: my_memory.cc:48
PSI_thread * m_owner
Definition: my_memory.cc:52
uint m_magic
Definition: mysql_memory.h:78
PSI_memory_key m_key
Definition: my_memory.cc:49
size_t m_size
Definition: my_memory.cc:51
unsigned int uint
Definition: uca-dump.cc:29