psi_memory.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. /* Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
  2. This program is free software; you can redistribute it and/or modify
  3. it under the terms of the GNU General Public License, version 2.0,
  4. as published by the Free Software Foundation.
  5. This program is also distributed with certain software (including
  6. but not limited to OpenSSL) that is licensed under separate terms,
  7. as designated in a particular file or component or in included license
  8. documentation. The authors of MySQL hereby grant you an additional
  9. permission to link the program and your derivative works with the
  10. separately licensed software that they have included with MySQL.
  11. Without limiting anything contained in the foregoing, this file,
  12. which is part of C Driver for MySQL (Connector/C), is also subject to the
  13. Universal FOSS Exception, version 1.0, a copy of which can be found at
  14. http://oss.oracle.com/licenses/universal-foss-exception.
  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. You should have received a copy of the GNU General Public License
  20. along with this program; if not, write to the Free Software Foundation,
  21. 51 Franklin Street, Suite 500, Boston, MA 02110-1335 USA */
  22. #ifndef MYSQL_PSI_MEMORY_H
  23. #define MYSQL_PSI_MEMORY_H
  24. #include "psi_base.h"
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. /**
  29. @file mysql/psi/psi_memory.h
  30. Performance schema instrumentation interface.
  31. @defgroup Instrumentation_interface Instrumentation Interface
  32. @ingroup Performance_schema
  33. @{
  34. */
  35. #ifdef HAVE_PSI_INTERFACE
  36. #ifndef DISABLE_ALL_PSI
  37. #ifndef DISABLE_PSI_MEMORY
  38. #define HAVE_PSI_MEMORY_INTERFACE
  39. #endif /* DISABLE_PSI_MEMORY */
  40. #endif /* DISABLE_ALL_PSI */
  41. #endif /* HAVE_PSI_INTERFACE */
  42. struct PSI_thread;
  43. /**
  44. Instrumented memory key.
  45. To instrument memory, a memory key must be obtained using @c register_memory.
  46. Using a zero key always disable the instrumentation.
  47. */
  48. typedef unsigned int PSI_memory_key;
  49. #ifdef HAVE_PSI_1
  50. /**
  51. @defgroup Group_PSI_v1 Application Binary Interface, version 1
  52. @ingroup Instrumentation_interface
  53. @{
  54. */
  55. /**
  56. Memory instrument information.
  57. @since PSI_VERSION_1
  58. This structure is used to register instrumented memory.
  59. */
  60. struct PSI_memory_info_v1
  61. {
  62. /** Pointer to the key assigned to the registered memory. */
  63. PSI_memory_key *m_key;
  64. /** The name of the memory instrument to register. */
  65. const char *m_name;
  66. /**
  67. The flags of the socket instrument to register.
  68. @sa PSI_FLAG_GLOBAL
  69. */
  70. int m_flags;
  71. };
  72. typedef struct PSI_memory_info_v1 PSI_memory_info_v1;
  73. /**
  74. Memory registration API.
  75. @param category a category name (typically a plugin name)
  76. @param info an array of memory info to register
  77. @param count the size of the info array
  78. */
  79. typedef void (*register_memory_v1_t)
  80. (const char *category, struct PSI_memory_info_v1 *info, int count);
  81. /**
  82. Instrument memory allocation.
  83. @param key the memory instrument key
  84. @param size the size of memory allocated
  85. @param[out] owner the memory owner
  86. @return the effective memory instrument key
  87. */
  88. typedef PSI_memory_key (*memory_alloc_v1_t)
  89. (PSI_memory_key key, size_t size, struct PSI_thread ** owner);
  90. /**
  91. Instrument memory re allocation.
  92. @param key the memory instrument key
  93. @param old_size the size of memory previously allocated
  94. @param new_size the size of memory re allocated
  95. @param[in, out] owner the memory owner
  96. @return the effective memory instrument key
  97. */
  98. typedef PSI_memory_key (*memory_realloc_v1_t)
  99. (PSI_memory_key key, size_t old_size, size_t new_size, struct PSI_thread ** owner);
  100. /**
  101. Instrument memory claim.
  102. @param key the memory instrument key
  103. @param size the size of memory allocated
  104. @param[in, out] owner the memory owner
  105. @return the effective memory instrument key
  106. */
  107. typedef PSI_memory_key (*memory_claim_v1_t)
  108. (PSI_memory_key key, size_t size, struct PSI_thread ** owner);
  109. /**
  110. Instrument memory free.
  111. @param key the memory instrument key
  112. @param size the size of memory allocated
  113. @param owner the memory owner
  114. */
  115. typedef void (*memory_free_v1_t)
  116. (PSI_memory_key key, size_t size, struct PSI_thread * owner);
  117. /** @} (end of group Group_PSI_v1) */
  118. #endif /* HAVE_PSI_1 */
  119. #ifdef HAVE_PSI_2
  120. struct PSI_memory_info_v2
  121. {
  122. int placeholder;
  123. };
  124. #endif /* HAVE_PSI_2 */
  125. #ifdef USE_PSI_1
  126. typedef struct PSI_memory_info_v1 PSI_memory_info;
  127. #endif
  128. #ifdef USE_PSI_2
  129. typedef struct PSI_memory_info_v2 PSI_memory_info;
  130. #endif
  131. /** @} (end of group Instrumentation_interface) */
  132. #ifdef __cplusplus
  133. }
  134. #endif
  135. #endif /* MYSQL_PSI_MEMORY_H */