CUBRID Engine  latest
monitor_registration.cpp
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.cpp - implementation of cubrid monitor and statistic registration
21 //
22 
23 #include "monitor_registration.hpp"
24 
25 #include <string>
26 #include <vector>
27 
28 namespace cubmonitor
29 {
30 
32  // registration
34 
36  : m_statistics_count (0)
37  , m_fetch_func ()
38  {
39  //
40  }
41 
43  // monitor
47  , m_all_names ()
48  , m_registrations ()
49  {
50 
51  }
52 
53  std::size_t
55  {
57  }
58 
59  std::size_t
61  {
62  return m_registrations.size ();
63  }
64 
65  const std::string &
66  monitor::get_statistic_name (std::size_t index) const
67  {
68  return m_all_names[index];
69  }
70 
71  std::size_t
73  {
74  return get_statistics_count () * sizeof (statistic_value);
75  }
76 
77  std::size_t
79  {
80  return get_registered_count () * sizeof (registration);
81  }
82 
85  {
87  }
88 
89  void
91  {
92  statistic_value *stats_iterp = destination;
93  for (auto it : m_registrations)
94  {
95  it.m_fetch_func (stats_iterp, mode);
96  stats_iterp += it.m_statistics_count;
97  }
98  }
99 
100  void
102  {
103  fetch_statistics (destination, FETCH_GLOBAL);
104  }
105 
106  void
108  {
110  {
111  // no transaction sheet, nothing to fetch
112  return;
113  }
115  }
116 
117  void
119  {
121  }
122 
123  void
125  {
126  m_registrations.emplace_back ();
127  registration &last = m_registrations.back ();
128 
129  last.m_statistics_count = count;
131 
132  last.m_fetch_func = fetch_func;
133  }
134 
135  void
136  monitor::register_statistics (std::size_t statistics_count, const fetch_function &fetch_global,
137  const std::vector<std::string> &names)
138  {
139  if (statistics_count != names.size ())
140  {
141  // names/statistics count miss-match
142  assert (false);
143  return;
144  }
145  add_registration (statistics_count, fetch_global);
146  m_all_names.insert (m_all_names.end (), names.cbegin (), names.cend ());
147 
148  check_name_count ();
149  }
150 
152  // global monitor
154 
155  static monitor Monitor;
156 
158  {
159  return Monitor;
160  }
161 
162 } // namespace cubmonitor
std::size_t get_statistics_count(void) const
std::size_t get_statistic_values_memsize(void) const
static const transaction_sheet INVALID_TRANSACTION_SHEET
static monitor Monitor
void add_registration(std::size_t count, const fetch_function &fetch_f)
const fetch_mode FETCH_GLOBAL
statistic_value * allocate_statistics_buffer(void) const
static transaction_sheet get_sheet(void)
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 T_FETCH_FUNC fetch_func[]
Definition: cas_execute.c:364
#define assert(x)
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)
const fetch_mode FETCH_TRANSACTION_SHEET
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