MySQL 26.7.0
Source Code Documentation
statistics_instance_monitor.h
Go to the documentation of this file.
1// Copyright (c) 2026, 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_SCHEDULER_STATISTICS_INSTANCE_MONITOR_H
25#define MYSQL_SCHEDULER_STATISTICS_INSTANCE_MONITOR_H
26
27#include <atomic>
28#include <chrono>
29#include <functional>
30#include <memory>
31#include <optional>
32#include <unordered_map>
38
39namespace mysql::scheduler {
40
41class Statistics_instance_monitor;
43 std::reference_wrapper<Statistics_instance_monitor>;
44
45/// @brief CSA statistics monitor, gathers statistics coming from different
46/// CSA threads
47/// Each statistic is a pair of key (statistic string) and value. This will
48/// help with backward and forward compatibility of statistics implemented
49/// in CSA servis w.r.t. statistics supported in the server
50/// Statistic update method ingests thread id, to keep a sharded statistics
51/// value until coalescing operation requested by external thread to
52/// get accumulated value (if coalescing is requested during "get" operation).
53/// For the time being, we assume only 1 channel
55 public:
58
59 void init();
60
61 /// @brief Get statistic value
62 /// @param name Name of statistic
63 /// @param thread_num The number of threads accessing statistic
64 /// @param enable Information on whether to enable this particular statistic
65 template <Statistic_allowed_type Type = long long>
66 void register_stat(const std::string &name, std::size_t thread_num = 1,
67 bool enable = true);
68 /// @brief Get accumulated statistic value
69 /// @param name Name of statistic
70 /// @return Value if statistic is found, no value otherwise
71 template <Statistic_allowed_type Type = long long>
72 std::optional<
74 find_stat(const std::string &name);
75 /// @brief Get accumulated statistic value w/o bound checking
76 /// @param name Name of statistic
77 /// @return Value if statistic is found, no value otherwise w/o bound checking
78 template <Statistic_allowed_type Type = long long>
79 typename Statistic_type_traits<Type>::type &get_stat(const std::string &name);
80
81 /// @brief Resets initialized statistics, use wisely
82 void reset();
83 /// @brief Frees registered statistics storage for this instance
84 void clear();
85
87
88 protected:
89 using Registry_type = std::unordered_map<std::string, Sharded_counter>;
91};
92
93} // namespace mysql::scheduler
94
96
97#endif // MYSQL_SCHEDULER_STATISTICS_INSTANCE_MONITOR_H
MySQL wrapper for a mutex, template which may be specialized with a specific implementation of a mute...
Definition: mutex_wrapper.h:38
CSA statistics monitor, gathers statistics coming from different CSA threads Each statistic is a pair...
Definition: statistics_instance_monitor.h:54
Statistic_type_traits< Type >::type & get_stat(const std::string &name)
Get accumulated statistic value w/o bound checking.
Definition: statistics_instance_monitor_impl.hpp:53
void register_stat(const std::string &name, std::size_t thread_num=1, bool enable=true)
Get statistic value.
Definition: statistics_instance_monitor_impl.hpp:31
std::optional< std::reference_wrapper< typename Statistic_type_traits< Type >::type > > find_stat(const std::string &name)
Get accumulated statistic value.
Definition: statistics_instance_monitor_impl.hpp:43
Registry_type m_registry
Definition: statistics_instance_monitor.h:90
void reset()
Resets initialized statistics, use wisely.
Definition: statistics_instance_monitor.cpp:34
concurrency::Mutex_key Mutex_key
Definition: statistics_instance_monitor.h:57
std::unordered_map< std::string, Sharded_counter > Registry_type
Definition: statistics_instance_monitor.h:89
void init()
Definition: statistics_instance_monitor.cpp:32
void clear()
Frees registered statistics storage for this instance.
Definition: statistics_instance_monitor.cpp:40
Mutex_wrapper Mutex
Definition: mutex_srv.h:40
PSI_mutex_key Mutex_key
Definition: mutex_srv.h:41
Definition: base_dependency_tracker.h:41
std::reference_wrapper< Statistics_instance_monitor > Statistics_instance_monitor_ref
Definition: statistics_instance_monitor.h:43
required string type
Definition: replication_group_member_actions.proto:34
Helper structure that translates types between underlying supported statistic type and concrete concu...
Definition: statistics_type_traits.h:38