Coverage Report

Created: 2025-07-23 06:50

/src/mysql-server/include/mysql/psi/mysql_memory.h
Line
Count
Source (jump to first uncovered line)
1
/* Copyright (c) 2012, 2025, 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
#ifndef MYSQL_MEMORY_H
25
#define MYSQL_MEMORY_H
26
27
/**
28
  @file include/mysql/psi/mysql_memory.h
29
  Instrumentation helpers for memory allocation.
30
*/
31
32
#include "my_compiler.h"
33
#include "my_inttypes.h"
34
#include "template_utils.h"
35
36
/* HAVE_PSI_*_INTERFACE */
37
#include "my_psi_config.h"  // IWYU pragma: keep
38
39
#include "mysql/psi/psi_memory.h"
40
41
#if defined(MYSQL_SERVER) || defined(PFS_DIRECT_CALL)
42
/* PSI_MEMORY_CALL() as direct call. */
43
#include "pfs_memory_provider.h"  // IWYU pragma: keep
44
#endif
45
46
#ifndef PSI_MEMORY_CALL
47
455k
#define PSI_MEMORY_CALL(M) psi_memory_service->M
48
#endif
49
50
/**
51
  @defgroup psi_api_memory Memory Instrumentation (API)
52
  @ingroup psi_api
53
  @{
54
*/
55
56
/**
57
  @def mysql_memory_register(P1, P2, P3)
58
  Memory registration.
59
*/
60
#define mysql_memory_register(P1, P2, P3) \
61
0
  inline_mysql_memory_register(P1, P2, P3)
62
63
static inline void inline_mysql_memory_register(
64
#ifdef HAVE_PSI_MEMORY_INTERFACE
65
    const char *category, PSI_memory_info *info, int count)
66
#else
67
    const char *category [[maybe_unused]], void *info [[maybe_unused]],
68
    int count [[maybe_unused]])
69
#endif
70
0
{
71
0
#ifdef HAVE_PSI_MEMORY_INTERFACE
72
0
  PSI_MEMORY_CALL(register_memory)(category, info, count);
73
0
#endif
74
0
}
Unexecuted instantiation: my_init.cc:inline_mysql_memory_register(char const*, PSI_memory_info_v1*, int)
Unexecuted instantiation: my_malloc.cc:inline_mysql_memory_register(char const*, PSI_memory_info_v1*, int)
75
76
#ifdef HAVE_PSI_MEMORY_INTERFACE
77
78
struct my_memory_header {
79
  PSI_memory_key m_key;
80
  uint m_magic;
81
  size_t m_size;
82
  PSI_thread *m_owner;
83
};
84
typedef struct my_memory_header my_memory_header;
85
86
910k
#define PSI_HEADER_SIZE 32
87
88
227k
#define PSI_MEMORY_MAGIC 1234
89
90
#define PSI_MEM_CNT_BIT ((uint)1 << 31)
91
#define PSI_REAL_MEM_KEY(P) ((PSI_memory_key)((P) & ~PSI_MEM_CNT_BIT))
92
93
227k
#define USER_TO_HEADER(P) ((my_memory_header *)(((char *)P) - PSI_HEADER_SIZE))
94
227k
#define HEADER_TO_USER(P) (((char *)P) + PSI_HEADER_SIZE)
95
96
#define USER_TO_HEADER_UINT8_T(P) \
97
  (((static_cast<uint8_t *>(P)) - PSI_HEADER_SIZE))
98
99
#endif
100
101
/** @} (end of group psi_api_memory) */
102
103
#endif