1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef OSD_PERF_METRIC_H_
5 #define OSD_PERF_METRIC_H_
7 #include "include/denc.h"
8 #include "include/stringify.h"
10 #include "mgr/Types.h"
14 typedef std::vector
<std::string
> OSDPerfMetricSubKey
; // array of regex match
15 typedef std::vector
<OSDPerfMetricSubKey
> OSDPerfMetricKey
;
17 enum class OSDPerfMetricSubKeyType
: uint8_t {
28 struct OSDPerfMetricSubKeyDescriptor
{
29 OSDPerfMetricSubKeyType type
= static_cast<OSDPerfMetricSubKeyType
>(-1);
30 std::string regex_str
;
33 bool is_supported() const {
35 case OSDPerfMetricSubKeyType::CLIENT_ID
:
36 case OSDPerfMetricSubKeyType::CLIENT_ADDRESS
:
37 case OSDPerfMetricSubKeyType::POOL_ID
:
38 case OSDPerfMetricSubKeyType::NAMESPACE
:
39 case OSDPerfMetricSubKeyType::OSD_ID
:
40 case OSDPerfMetricSubKeyType::PG_ID
:
41 case OSDPerfMetricSubKeyType::OBJECT_NAME
:
42 case OSDPerfMetricSubKeyType::SNAP_ID
:
49 OSDPerfMetricSubKeyDescriptor() {
52 OSDPerfMetricSubKeyDescriptor(OSDPerfMetricSubKeyType type
,
53 const std::string regex
)
54 : type(type
), regex_str(regex
) {
57 bool operator<(const OSDPerfMetricSubKeyDescriptor
&other
) const {
58 if (type
< other
.type
) {
61 if (type
> other
.type
) {
64 return regex_str
< other
.regex_str
;
67 DENC(OSDPerfMetricSubKeyDescriptor
, v
, p
) {
74 WRITE_CLASS_DENC(OSDPerfMetricSubKeyDescriptor
)
76 std::ostream
& operator<<(std::ostream
& os
,
77 const OSDPerfMetricSubKeyDescriptor
&d
);
79 typedef std::vector
<OSDPerfMetricSubKeyDescriptor
> OSDPerfMetricKeyDescriptor
;
82 struct denc_traits
<OSDPerfMetricKeyDescriptor
> {
83 static constexpr bool supported
= true;
84 static constexpr bool bounded
= false;
85 static constexpr bool featured
= false;
86 static constexpr bool need_contiguous
= true;
87 static void bound_encode(const OSDPerfMetricKeyDescriptor
& v
, size_t& p
) {
88 p
+= sizeof(uint32_t);
89 const auto size
= v
.size();
96 static void encode(const OSDPerfMetricKeyDescriptor
& v
,
97 ceph::buffer::list::contiguous_appender
& p
) {
98 denc_varint(v
.size(), p
);
103 static void decode(OSDPerfMetricKeyDescriptor
& v
,
104 ceph::buffer::ptr::const_iterator
& p
) {
109 for (unsigned i
=0; i
< num
; ++i
) {
110 OSDPerfMetricSubKeyDescriptor d
;
112 if (!d
.is_supported()) {
117 d
.regex
= d
.regex_str
.c_str();
118 } catch (const std::regex_error
& e
) {
122 if (d
.regex
.mark_count() == 0) {
126 v
.push_back(std::move(d
));
131 enum class PerformanceCounterType
: uint8_t {
143 struct PerformanceCounterDescriptor
{
144 PerformanceCounterType type
= static_cast<PerformanceCounterType
>(-1);
146 bool is_supported() const {
148 case PerformanceCounterType::OPS
:
149 case PerformanceCounterType::WRITE_OPS
:
150 case PerformanceCounterType::READ_OPS
:
151 case PerformanceCounterType::BYTES
:
152 case PerformanceCounterType::WRITE_BYTES
:
153 case PerformanceCounterType::READ_BYTES
:
154 case PerformanceCounterType::LATENCY
:
155 case PerformanceCounterType::WRITE_LATENCY
:
156 case PerformanceCounterType::READ_LATENCY
:
163 PerformanceCounterDescriptor() {
166 PerformanceCounterDescriptor(PerformanceCounterType type
) : type(type
) {
169 bool operator<(const PerformanceCounterDescriptor
&other
) const {
170 return type
< other
.type
;
173 bool operator==(const PerformanceCounterDescriptor
&other
) const {
174 return type
== other
.type
;
177 bool operator!=(const PerformanceCounterDescriptor
&other
) const {
178 return type
!= other
.type
;
181 DENC(PerformanceCounterDescriptor
, v
, p
) {
187 void pack_counter(const PerformanceCounter
&c
, ceph::buffer::list
*bl
) const;
188 void unpack_counter(ceph::buffer::list::const_iterator
& bl
,
189 PerformanceCounter
*c
) const;
191 WRITE_CLASS_DENC(PerformanceCounterDescriptor
)
193 std::ostream
& operator<<(std::ostream
& os
,
194 const PerformanceCounterDescriptor
&d
);
196 typedef std::vector
<PerformanceCounterDescriptor
> PerformanceCounterDescriptors
;
199 struct denc_traits
<PerformanceCounterDescriptors
> {
200 static constexpr bool supported
= true;
201 static constexpr bool bounded
= false;
202 static constexpr bool featured
= false;
203 static constexpr bool need_contiguous
= true;
204 static void bound_encode(const PerformanceCounterDescriptors
& v
, size_t& p
) {
205 p
+= sizeof(uint32_t);
206 const auto size
= v
.size();
209 denc(v
.front(), per
);
213 static void encode(const PerformanceCounterDescriptors
& v
,
214 ceph::buffer::list::contiguous_appender
& p
) {
215 denc_varint(v
.size(), p
);
220 static void decode(PerformanceCounterDescriptors
& v
,
221 ceph::buffer::ptr::const_iterator
& p
) {
226 for (unsigned i
=0; i
< num
; ++i
) {
227 PerformanceCounterDescriptor d
;
229 if (d
.is_supported()) {
230 v
.push_back(std::move(d
));
236 struct OSDPerfMetricLimit
{
237 PerformanceCounterDescriptor order_by
;
238 uint64_t max_count
= 0;
240 OSDPerfMetricLimit() {
243 OSDPerfMetricLimit(const PerformanceCounterDescriptor
&order_by
,
245 : order_by(order_by
), max_count(max_count
) {
248 bool operator<(const OSDPerfMetricLimit
&other
) const {
249 if (order_by
!= other
.order_by
) {
250 return order_by
< other
.order_by
;
252 return max_count
< other
.max_count
;
255 DENC(OSDPerfMetricLimit
, v
, p
) {
258 denc(v
.max_count
, p
);
262 WRITE_CLASS_DENC(OSDPerfMetricLimit
)
264 std::ostream
& operator<<(std::ostream
& os
, const OSDPerfMetricLimit
&limit
);
266 typedef std::set
<OSDPerfMetricLimit
> OSDPerfMetricLimits
;
268 struct OSDPerfMetricQuery
{
269 bool operator<(const OSDPerfMetricQuery
&other
) const {
270 if (key_descriptor
< other
.key_descriptor
) {
273 if (key_descriptor
> other
.key_descriptor
) {
276 return (performance_counter_descriptors
<
277 other
.performance_counter_descriptors
);
280 OSDPerfMetricQuery() {
284 const OSDPerfMetricKeyDescriptor
&key_descriptor
,
285 const PerformanceCounterDescriptors
&performance_counter_descriptors
)
286 : key_descriptor(key_descriptor
),
287 performance_counter_descriptors(performance_counter_descriptors
) {
290 template <typename L
>
291 bool get_key(L
&& get_sub_key
, OSDPerfMetricKey
*key
) const {
292 for (auto &sub_key_descriptor
: key_descriptor
) {
293 OSDPerfMetricSubKey sub_key
;
294 if (!get_sub_key(sub_key_descriptor
, &sub_key
)) {
297 key
->push_back(sub_key
);
302 DENC(OSDPerfMetricQuery
, v
, p
) {
304 denc(v
.key_descriptor
, p
);
305 denc(v
.performance_counter_descriptors
, p
);
309 void get_performance_counter_descriptors(
310 PerformanceCounterDescriptors
*descriptors
) const {
311 *descriptors
= performance_counter_descriptors
;
314 template <typename L
>
315 void update_counters(L
&&update_counter
,
316 PerformanceCounters
*counters
) const {
317 auto it
= counters
->begin();
318 for (auto &descriptor
: performance_counter_descriptors
) {
320 if (it
== counters
->end()) {
321 counters
->push_back(PerformanceCounter());
322 it
= std::prev(counters
->end());
324 update_counter(descriptor
, &(*it
));
329 void pack_counters(const PerformanceCounters
&counters
, ceph::buffer::list
*bl
) const;
331 OSDPerfMetricKeyDescriptor key_descriptor
;
332 PerformanceCounterDescriptors performance_counter_descriptors
;
334 WRITE_CLASS_DENC(OSDPerfMetricQuery
)
336 struct OSDPerfCollector
: PerfCollector
{
337 std::map
<OSDPerfMetricKey
, PerformanceCounters
> counters
;
339 OSDPerfCollector(MetricQueryID query_id
)
340 : PerfCollector(query_id
) {
344 std::ostream
& operator<<(std::ostream
& os
, const OSDPerfMetricQuery
&query
);
346 struct OSDPerfMetricReport
{
347 PerformanceCounterDescriptors performance_counter_descriptors
;
348 std::map
<OSDPerfMetricKey
, ceph::buffer::list
> group_packed_performance_counters
;
350 DENC(OSDPerfMetricReport
, v
, p
) {
352 denc(v
.performance_counter_descriptors
, p
);
353 denc(v
.group_packed_performance_counters
, p
);
357 WRITE_CLASS_DENC(OSDPerfMetricReport
)
359 #endif // OSD_PERF_METRIC_H_