MySQL 26.10.0
Source Code Documentation
health_monitor_metric_buffer.h
Go to the documentation of this file.
1/* Copyright (c) 2025, 2026, 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#pragma once
25
26#include <atomic>
27
29
30namespace hm {
31
32/**
33 Metric_Buffer extends the circular buffer, Stat_Buffer, with a two-way
34 read/write capability such that it can be shared between multiple
35 collectors.
36*/
37template <typename T>
38class Metric_Buffer : public Stat_Buffer<T> {
39 public:
40 Metric_Buffer() = default;
41
42 Metric_Buffer(bool no_lock, PSI_memory_key memory_key)
43 : Stat_Buffer<T>(no_lock, memory_key) {}
44
46 : Stat_Buffer<T>(rwlock_key, memory_key) {}
47
48 bool writeable() { return m_writeable.load(); }
50
51 // Write to the time series buffer, then set 'writeable' to false,
52 // indicating that the write is complete.
53 // Note that this method intentionally hides Stat_Buffer::write().
54 int write(const T &record) {
56 if (ret == 0) {
57 set_writeable(false);
58 }
59 return ret;
60 }
61
62 // Provide a means to directly convert an external type U to a time series
63 // type T, e.g. Disk_Info -> Disk_Metric. The method is enabled only if
64 // the target type T is constructable from U.
65 template <typename U>
66 auto write(const U &arg)
67 -> std::enable_if_t<std::is_constructible_v<T, U>, int> {
68 T record(arg);
69 return write(record);
70 }
71
72 private:
73 std::atomic<bool> m_writeable{false};
74};
75
76} // namespace hm
Metric_Buffer extends the circular buffer, Stat_Buffer, with a two-way read/write capability such tha...
Definition: health_monitor_metric_buffer.h:38
auto write(const U &arg) -> std::enable_if_t< std::is_constructible_v< T, U >, int >
Definition: health_monitor_metric_buffer.h:66
Metric_Buffer()=default
void set_writeable(bool writeable)
Definition: health_monitor_metric_buffer.h:49
Metric_Buffer(PSI_rwlock_key rwlock_key, PSI_memory_key memory_key)
Definition: health_monitor_metric_buffer.h:45
std::atomic< bool > m_writeable
Definition: health_monitor_metric_buffer.h:73
Metric_Buffer(bool no_lock, PSI_memory_key memory_key)
Definition: health_monitor_metric_buffer.h:42
bool writeable()
Definition: health_monitor_metric_buffer.h:48
int write(const T &record)
Definition: health_monitor_metric_buffer.h:54
Sample data buffer.
Definition: health_monitor_stat_buffer.h:43
int write(const T &record)
Write one element into the circular buffer at the current head position.
Definition: health_monitor_stat_buffer.h:178
unsigned int PSI_memory_key
Instrumented memory key.
Definition: psi_memory_bits.h:49
unsigned int PSI_rwlock_key
Instrumented rwlock key.
Definition: psi_rwlock_bits.h:44
#define T
Definition: jit_executor_value.cc:373
static int record
Definition: mysqltest.cc:195
Definition: component_command.h:29
Definition: dtoa.cc:595