CUBRID Engine  latest
monitor_registration.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2008 Search Solution Corporation
3  * Copyright 2016 CUBRID Corporation
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */
18 
19 //
20 // monitor_registration.hpp - interface for cubrid monitor and statistic registration
21 //
22 // this interface defines the cubrid statistics monitor and how to register statistics.
23 //
24 // all statistics that should be inspected by cubrid statdump tool should be registered to performance monitoring.
25 // to register a statistic, one must provide:
26 //
27 // 1. statistic name
28 // 2. a way to fetch its value (bound function)
29 // 3. TODO: other statistic properties.
30 //
31 // TODO: currently, we only provide registering for single statistics. we will have to extend to fully cover
32 // performance monitoring requirements.
33 //
34 // Extensions
35 //
36 // - extending statistic properties
37 // - registering group of statistics
38 //
39 
40 #if !defined _MONITOR_REGISTRATION_HPP_
41 #define _MONITOR_REGISTRATION_HPP_
42 
43 #include "monitor_definition.hpp"
44 #include "monitor_transaction.hpp"
45 
46 #include <functional>
47 #include <string>
48 #include <vector>
49 
50 namespace cubmonitor
51 {
52  //
53  // monitor - centralize statistics and fetch all their values on request
54  //
55  // monitor can register single or group of statistics by saving meta-information for the group and its statistics.
56  // info per group (registration):
57  //
58  // 1. function to fetch statistics
59  // 2. statistics count
60  //
61  // info per statistic:
62  //
63  // 1. name
64  //
65  class monitor
66  {
67  public:
68  // function format to fetch registered statistics. one such function is bound for each registration and should
69  // fetch all registered statistics
70  //
71  using fetch_function = std::function<void (statistic_value *, fetch_mode)>;
72 
73  monitor ();
74 
75  // register a statistics by providing fetch function
76  void register_statistics (std::size_t statistics_count, const fetch_function &fetch_f,
77  const std::vector<std::string> &names);
78 
79  template <class S>
80  void register_statistics (const S &statistics, std::vector<std::string> &names);
81 
82  // getters
83  // get the total count of registered statistics
84  std::size_t get_statistics_count (void) const;
85  std::size_t get_registered_count (void) const;
86  // get name
87  const std::string &get_statistic_name (std::size_t index) const;
88  // memory size
89  std::size_t get_statistic_values_memsize (void) const;
90  std::size_t get_registrations_memsize (void) const;
91 
92  // allocate a buffer to hold values for all statistics
94  // fetch global statistics to buffer
95  void fetch_global_statistics (statistic_value *destination) const;
96  // fetch current transaction statistics to buffer
97  void fetch_transaction_statistics (statistic_value *destination) const;
98  // fetch complete set of statistics based on mode - global or transaction sheet
99  void fetch_statistics (statistic_value *destination, fetch_mode mode) const;
100 
101  private:
102 
103  // internal structure to hold information on registered statistics
105  {
106  std::size_t m_statistics_count;
108 
109  registration (void);
110 
111  // todo: add here more meta-information on each registration
112  };
113 
114  // add one registration; there can be multiple statistics fetched using a single function
115  void add_registration (std::size_t count, const fetch_function &fetch_f);
116  // debug function to verify the number of statistics match the number of names
117  void check_name_count (void) const;
118 
119  // total number of statistics
121  // vector with statistic names
122  std::vector<std::string> m_all_names;
123  // registrations
124  std::vector<registration> m_registrations;
125  };
126 
127  monitor &get_global_monitor (void);
128 
130  // implementation
132 
133  template <class S>
134  void
135  monitor::register_statistics (const S &statistics, std::vector<std::string> &names)
136  {
137  fetch_function fetch_f = [&] (statistic_value * destination, fetch_mode mode)
138  {
139  statistics.fetch (destination, mode);
140  };
141  register_statistics (statistics.get_statistics_count (), fetch_f, names);
142  }
143 
144 } // namespace cubmonitor
145 
146 #endif // _MONITOR_REGISTRATION_HPP_
std::size_t get_statistics_count(void) const
std::size_t get_statistic_values_memsize(void) const
void add_registration(std::size_t count, const fetch_function &fetch_f)
statistic_value * allocate_statistics_buffer(void) const
std::uint64_t statistic_value
std::size_t get_registered_count(void) const
std::vector< registration > m_registrations
void fetch_transaction_statistics(statistic_value *destination) const
std::vector< std::string > m_all_names
std::function< void(statistic_value *, fetch_mode)> fetch_function
static enum scanner_mode mode
void check_name_count(void) const
void fetch_global_statistics(statistic_value *destination) const
void fetch_statistics(statistic_value *destination, fetch_mode mode) const
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
const std::string & get_statistic_name(std::size_t index) const
monitor & get_global_monitor(void)
void register_statistics(std::size_t statistics_count, const fetch_function &fetch_f, const std::vector< std::string > &names)
std::size_t get_registrations_memsize(void) const