MySQL 9.2.0
Source Code Documentation
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
time_based_metric_interface.h
Go to the documentation of this file.
1// Copyright (c) 2024, 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 CHANGESTREAMS_APPLY_METRICS_TIME_BASED_METRIC_INTERFACE_H
25#define CHANGESTREAMS_APPLY_METRICS_TIME_BASED_METRIC_INTERFACE_H
26
27#include <scope_guard.h> // create_scope_guard
28#include <cstdint> // int64_t
29#include "mysql/utils/nodiscard.h" // NODISCARD
30
31/// @brief Abstract class for time based metrics implementations
33 public:
34 virtual ~Time_based_metric_interface() = default;
35
36 /// @brief Resets the counter and time to 0
37 virtual void reset() = 0;
38
39 /// @brief Returns the total time waited across all executions of the
40 /// start/stop methods, minus the absolute start time of the last one in case
41 /// it has not ended.
42 /// @return The total time waited, in nanoseconds.
43 virtual int64_t get_time() const = 0;
44
45 /// @brief Increment the counter.
46 ///
47 /// @note The counter is normally incremented automatically each time
48 /// time_scope is called. This function is needed only for objects where that
49 /// functionality has been disabled.
50 virtual void increment_counter() = 0;
51
52 /// @brief Returns the number of times we waited on give spot
53 /// @return the number of times waited
54 virtual int64_t get_count() const = 0;
55
56 /// Start the timer, and return an object that will stop the timer when it
57 /// is deleted.
58 [[NODISCARD]] auto time_scope() {
60 return create_scope_guard([=, this] { this->stop_timer(); });
61 }
62
63 protected:
64 /// @brief Starts the timer.
65 ///
66 /// Used internally; the public interface is @c time_scope().
67 virtual void start_timer() = 0;
68
69 /// @brief Stops the timer.
70 ///
71 /// Used internally; the public interface is @c time_scope().
72 virtual void stop_timer() = 0;
73};
74
75#endif /* CHANGESTREAMS_APPLY_METRICS_TIME_BASED_METRIC_INTERFACE_H */
Abstract class for time based metrics implementations.
Definition: time_based_metric_interface.h:32
virtual void stop_timer()=0
Stops the timer.
virtual ~Time_based_metric_interface()=default
virtual int64_t get_count() const =0
Returns the number of times we waited on give spot.
virtual void reset()=0
Resets the counter and time to 0.
virtual void start_timer()=0
Starts the timer.
virtual void increment_counter()=0
Increment the counter.
auto time_scope()
Start the timer, and return an object that will stop the timer when it is deleted.
Definition: time_based_metric_interface.h:58
virtual int64_t get_time() const =0
Returns the total time waited across all executions of the start/stop methods, minus the absolute sta...
#define NODISCARD
The function attribute [[NODISCARD]] is a replacement for [[nodiscard]] to workaround a gcc bug.
Definition: nodiscard.h:47
Scope_guard< TLambda > create_scope_guard(const TLambda rollback_lambda)
Create a scope guard object.
Definition: scope_guard.h:113