CUBRID Engine  latest
monitor_statistic.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_statistic.cpp - implementation for monitoring statistics
21 //
22 
23 #include "monitor_statistic.hpp"
24 
25 #include <cassert>
26 #include <cstring>
27 
28 namespace cubmonitor
29 {
31  // statistic_value <-> statistic rep casts
33 
36  {
37  return static_cast<statistic_value> (rep);
38  }
39 
42  {
43  return static_cast<amount_rep> (value);
44  }
45 
48  {
49  statistic_value stat_val;
50  static_assert (sizeof (rep) == sizeof (stat_val), "floating_rep and statistic_value must be same size");
51  std::memcpy (&stat_val, &rep, sizeof (stat_val));
52  return stat_val;
53  }
54 
57  {
58  floating_rep float_val;
59  static_assert (sizeof (float_val) == sizeof (value), "floating_rep and statistic_value must be same size");
60  std::memcpy (&float_val, &value, sizeof (floating_rep));
61  return float_val;
62  }
63 
66  {
67  // nanoseconds to microseconds
68  return static_cast<statistic_value> (std::chrono::duration_cast<std::chrono::microseconds> (rep).count ());
69  }
70 
71  time_rep
73  {
74  // microseconds to nanoseconds
75  // careful: time_rep_cast (statistic_value_cast (stat)) != stat
76  return std::chrono::duration_cast<time_rep> (std::chrono::microseconds (value));
77  }
78 
80  // fully specialized constructors for max/min
82 
83  template <>
85  : primitive<amount_rep> (std::numeric_limits<amount_rep>::min ())
86  {
87  //
88  }
89 
90  template <>
92  : primitive<floating_rep> (std::numeric_limits<floating_rep>::min ())
93  {
94  //
95  }
96 
97  template <>
100  {
101  //
102  }
103 
104  template <>
106  : atomic_primitive<amount_rep> (std::numeric_limits<amount_rep>::min ())
107  {
108  //
109  }
110 
111  template <>
113  : atomic_primitive<floating_rep> (std::numeric_limits<floating_rep>::min ())
114  {
115  //
116  }
117 
118  template <>
121  {
122  //
123  }
124 
125  template <>
127  : primitive<amount_rep> (std::numeric_limits<amount_rep>::max ())
128  {
129  //
130  }
131 
132  template <>
134  : primitive<floating_rep> (std::numeric_limits<floating_rep>::max ())
135  {
136  //
137  }
138 
139  template <>
141  : primitive<time_rep> (time_rep::max ())
142  {
143  //
144  }
145 
146  template <>
148  : atomic_primitive<amount_rep> (std::numeric_limits<amount_rep>::max ())
149  {
150  //
151  }
152 
153  template <>
155  : atomic_primitive<floating_rep> (std::numeric_limits<floating_rep>::max ())
156  {
157  //
158  }
159 
160  template <>
163  {
164  //
165  }
166 
167  template <>
168  void
170  {
171  this->m_value.fetch_add (value.count ());
172  }
173 } // namespace cubmonitor
std::uint64_t statistic_value
#define min(a, b)
floating_rep floating_rep_cast(statistic_value value)
int count(int &result, const cub_regex_object &reg, const std::string &src, const int position, const INTL_CODESET codeset)
#define max(a, b)
amount_rep amount_rep_cast(statistic_value value)
statistic_value statistic_value_cast(const amount_rep &rep)
time_rep time_rep_cast(statistic_value value)
std::uint64_t amount_rep