MySQL 8.4.0
Source Code Documentation
psi_metric_bits.h
Go to the documentation of this file.
1/* Copyright (c) 2022, 2024, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is designed to work with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have either included with
13the program or referenced in the documentation.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License, version 2.0, for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef COMPONENTS_SERVICES_BITS_PSI_METRIC_BITS_H
25#define COMPONENTS_SERVICES_BITS_PSI_METRIC_BITS_H
26
27#include <cstddef> // size_t
28#include <cstdint> // int64_t
29
31
33 ASYNC_COUNTER, // monotonic, sum aggregation
34 ASYNC_UPDOWN_COUNTER, // non-monotonic, sum aggregation
35 ASYNC_GAUGE_COUNTER // non-monotonic, non-aggregated
36};
37
39
41
42// metric source field limits imposed by OTEL
43constexpr size_t MAX_METER_NAME_LEN = 63;
44constexpr size_t MAX_METER_DESCRIPTION_LEN = 1023;
45constexpr size_t MAX_METRIC_NAME_LEN = 63;
46constexpr size_t MAX_METRIC_UNIT_LEN = 63;
47constexpr size_t MAX_METRIC_DESCRIPTION_LEN = 1023;
48
49// common metric units as specified by OpenTelemetry
50#define METRIC_UNIT_BYTES "By"
51#define METRIC_UNIT_MILLISECONDS "ms"
52#define METRIC_UNIT_SECONDS "s"
53
54typedef void (*measurement_delivery_int64_0_callback_t)(void *delivery_context,
55 int64_t value);
56
57typedef void (*measurement_delivery_int64_1_callback_t)(void *delivery_context,
58 int64_t value,
59 const char *attr_name,
60 const char *attr_value);
61
63 void *delivery_context, int64_t value, const char **attr_name_array,
64 const char **attr_value_array, size_t size);
65
66typedef void (*measurement_delivery_double_0_callback_t)(void *delivery_context,
67 double value);
68
70 void *delivery_context, double value, const char *attr_name,
71 const char *attr_value);
72
74 void *delivery_context, double value, const char **attr_name_array,
75 const char **attr_value_array, size_t size);
76
84};
85
86/**
87 Set of callbacks within component code to receive the measured values (avoids
88 data copy overhead).
89*/
91
92/**
93 Single metric measurement callback can return multiple measurement values.
94 For example, "CPU use" metric might return values for all available CPU
95 logical cores, each value having an attribute with matching CPU core ID.
96*/
97typedef void (*measurement_callback_t)(void *measurement_context,
99 void *delivery_context);
100
101typedef unsigned int PSI_meter_key;
102typedef unsigned int PSI_metric_key;
103
104/**
105 @def PSI_METRIC_VERSION_1
106 Performance Schema Metric Interface number for version 1.
107 This version is supported.
108*/
109#define PSI_METRIC_VERSION_1 1
110
111/**
112 @def PSI_CURRENT_METRIC_VERSION
113 Performance Schema Metric Interface number for the most recent version.
114 The most current version is @c PSI_METRIC_VERSION_1
115*/
116#define PSI_CURRENT_METRIC_VERSION 1
117
118/**
119 Define a metric source, storing char pointers requires the original
120 strings to be valid for entire lifetime of a metric (global variable), or the
121 strings themselves to be string literals (hardcoded), the advantage is no
122 (de)allocation code is needed here.
123*/
125 const char *m_metric;
126 const char *m_unit;
127 const char *m_description;
130 /** Instrument flags. */
131 unsigned int m_flags;
135};
136
137/**
138 * Define a meter source, storing char pointers requires the original
139 * strings to be valid for entire lifetime of a metric (global variable), or
140 * the strings themselves to be string literals (hardcoded), the advantage is no
141 * (de)allocation code is needed here.
142 */
144 const char *m_meter;
145 const char *m_description;
146 unsigned int m_frequency;
147 /** Instrument flags. */
148 unsigned int m_flags;
150
151 // the metrics for this meter
153 unsigned int m_metrics_size;
154};
155
156/**
157 Register a batch of telemetry meters (metric groups), each with its metrics.
158
159 @param info pointer to an array of meter definitions
160 @param count array size
161 */
162typedef void (*register_meters_v1_t)(PSI_meter_info_v1 *info, size_t count);
163
164/**
165 Unregister a batch of meters and their telemetry metric sources.
166
167 @param info pointer to array of meter definitions
168 @param count array size
169*/
170typedef void (*unregister_meters_v1_t)(PSI_meter_info_v1 *info, size_t count);
171
172/**
173 Callback function to notify of changes within the set of registered meters.
174
175 @param meter meter name
176 @param change type of change related to the meter
177*/
178typedef void (*meter_registration_changes_v1_t)(const char *meter,
179 MeterNotifyType change);
180
181/**
182 Register a notification callback to track changes in the set of registered
183 meters.
184
185 @param callback pointer to notification function
186*/
189
190/**
191 Unregister a notification callback to track changes in the set of registered
192 meters.
193
194 @param callback pointer to notification function
195*/
198
199/**
200 Send a notification of changes in the set of registered meters.
201
202 @param meter meter name being changed
203 @param change change type description
204*/
205typedef void (*send_change_notification_v1_t)(const char *meter,
206 MeterNotifyType change);
207
210
213
214#endif /* COMPONENTS_SERVICES_BITS_PSI_METRIC_BITS_H */
static int count
Definition: myisam_ftdump.cc:45
size_t size(const char *const c)
Definition: base64.h:46
constexpr size_t MAX_METRIC_DESCRIPTION_LEN
Definition: psi_metric_bits.h:47
void(* measurement_delivery_double_1_callback_t)(void *delivery_context, double value, const char *attr_name, const char *attr_value)
Definition: psi_metric_bits.h:69
void(* measurement_delivery_int64_0_callback_t)(void *delivery_context, int64_t value)
Definition: psi_metric_bits.h:54
MetricOTELType
Definition: psi_metric_bits.h:32
@ ASYNC_UPDOWN_COUNTER
Definition: psi_metric_bits.h:34
@ ASYNC_COUNTER
Definition: psi_metric_bits.h:33
@ ASYNC_GAUGE_COUNTER
Definition: psi_metric_bits.h:35
unsigned int PSI_meter_key
Definition: psi_metric_bits.h:101
PSI_metric_info_v1 PSI_metric_info
Definition: psi_metric_bits.h:209
MeterNotifyType
Definition: psi_metric_bits.h:40
@ METER_REMOVED
Definition: psi_metric_bits.h:40
@ METER_UPDATE
Definition: psi_metric_bits.h:40
@ METER_ADDED
Definition: psi_metric_bits.h:40
constexpr size_t MAX_METRIC_NAME_LEN
Definition: psi_metric_bits.h:45
constexpr size_t MAX_METER_DESCRIPTION_LEN
Definition: psi_metric_bits.h:44
void(* meter_registration_changes_v1_t)(const char *meter, MeterNotifyType change)
Callback function to notify of changes within the set of registered meters.
Definition: psi_metric_bits.h:178
void(* measurement_delivery_double_0_callback_t)(void *delivery_context, double value)
Definition: psi_metric_bits.h:66
void(* unregister_meters_v1_t)(PSI_meter_info_v1 *info, size_t count)
Unregister a batch of meters and their telemetry metric sources.
Definition: psi_metric_bits.h:170
void(* measurement_delivery_double_n_callback_t)(void *delivery_context, double value, const char **attr_name_array, const char **attr_value_array, size_t size)
Definition: psi_metric_bits.h:73
constexpr size_t MAX_METER_NAME_LEN
Definition: psi_metric_bits.h:43
void(* register_meters_v1_t)(PSI_meter_info_v1 *info, size_t count)
Register a batch of telemetry meters (metric groups), each with its metrics.
Definition: psi_metric_bits.h:162
MetricNumType
Definition: psi_metric_bits.h:38
@ METRIC_INTEGER
Definition: psi_metric_bits.h:38
@ METRIC_DOUBLE
Definition: psi_metric_bits.h:38
void(* unregister_change_notification_v1_t)(meter_registration_changes_v1_t callback)
Unregister a notification callback to track changes in the set of registered meters.
Definition: psi_metric_bits.h:196
unsigned int PSI_metric_key
Definition: psi_metric_bits.h:102
PSI_meter_info_v1 PSI_meter_info
Definition: psi_metric_bits.h:212
void(* measurement_delivery_int64_1_callback_t)(void *delivery_context, int64_t value, const char *attr_name, const char *attr_value)
Definition: psi_metric_bits.h:57
void(* measurement_callback_t)(void *measurement_context, measurement_delivery_callback_t delivery, void *delivery_context)
Single metric measurement callback can return multiple measurement values.
Definition: psi_metric_bits.h:97
void(* measurement_delivery_int64_n_callback_t)(void *delivery_context, int64_t value, const char **attr_name_array, const char **attr_value_array, size_t size)
Definition: psi_metric_bits.h:62
void(* register_change_notification_v1_t)(meter_registration_changes_v1_t callback)
Register a notification callback to track changes in the set of registered meters.
Definition: psi_metric_bits.h:187
constexpr size_t MAX_METRIC_UNIT_LEN
Definition: psi_metric_bits.h:46
void(* send_change_notification_v1_t)(const char *meter, MeterNotifyType change)
Send a notification of changes in the set of registered meters.
Definition: psi_metric_bits.h:205
Define a meter source, storing char pointers requires the original strings to be valid for entire lif...
Definition: psi_metric_bits.h:143
unsigned int m_frequency
Definition: psi_metric_bits.h:146
PSI_meter_key m_key
Definition: psi_metric_bits.h:149
const char * m_description
Definition: psi_metric_bits.h:145
PSI_metric_info_v1 * m_metrics
Definition: psi_metric_bits.h:152
unsigned int m_flags
Instrument flags.
Definition: psi_metric_bits.h:148
unsigned int m_metrics_size
Definition: psi_metric_bits.h:153
const char * m_meter
Definition: psi_metric_bits.h:144
Define a metric source, storing char pointers requires the original strings to be valid for entire li...
Definition: psi_metric_bits.h:124
void * m_measurement_context
Definition: psi_metric_bits.h:134
unsigned int m_flags
Instrument flags.
Definition: psi_metric_bits.h:131
MetricOTELType m_metric_type
Definition: psi_metric_bits.h:128
const char * m_description
Definition: psi_metric_bits.h:127
PSI_metric_key m_key
Definition: psi_metric_bits.h:132
MetricNumType m_num_type
Definition: psi_metric_bits.h:129
const char * m_unit
Definition: psi_metric_bits.h:126
measurement_callback_t m_measurement_callback
Definition: psi_metric_bits.h:133
const char * m_metric
Definition: psi_metric_bits.h:125
Definition: psi_metric_bits.h:77
measurement_delivery_int64_1_callback_t value_int64_attr
Definition: psi_metric_bits.h:79
measurement_delivery_double_0_callback_t value_double
Definition: psi_metric_bits.h:81
measurement_delivery_double_n_callback_t value_double_attrs
Definition: psi_metric_bits.h:83
measurement_delivery_int64_n_callback_t value_int64_attrs
Definition: psi_metric_bits.h:80
measurement_delivery_double_1_callback_t value_double_attr
Definition: psi_metric_bits.h:82
measurement_delivery_int64_0_callback_t value_int64
Definition: psi_metric_bits.h:78