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"
12 typedef std::vector
<std::string
> OSDPerfMetricSubKey
; // array of regex match
13 typedef std::vector
<OSDPerfMetricSubKey
> OSDPerfMetricKey
;
15 enum class OSDPerfMetricSubKeyType
: uint8_t {
26 struct OSDPerfMetricSubKeyDescriptor
{
27 OSDPerfMetricSubKeyType type
= static_cast<OSDPerfMetricSubKeyType
>(-1);
28 std::string regex_str
;
31 bool is_supported() const {
33 case OSDPerfMetricSubKeyType::CLIENT_ID
:
34 case OSDPerfMetricSubKeyType::CLIENT_ADDRESS
:
35 case OSDPerfMetricSubKeyType::POOL_ID
:
36 case OSDPerfMetricSubKeyType::NAMESPACE
:
37 case OSDPerfMetricSubKeyType::OSD_ID
:
38 case OSDPerfMetricSubKeyType::PG_ID
:
39 case OSDPerfMetricSubKeyType::OBJECT_NAME
:
40 case OSDPerfMetricSubKeyType::SNAP_ID
:
47 OSDPerfMetricSubKeyDescriptor() {
50 OSDPerfMetricSubKeyDescriptor(OSDPerfMetricSubKeyType type
,
51 const std::string regex
)
52 : type(type
), regex_str(regex
) {
55 bool operator<(const OSDPerfMetricSubKeyDescriptor
&other
) const {
56 if (type
< other
.type
) {
59 if (type
> other
.type
) {
62 return regex_str
< other
.regex_str
;
65 DENC(OSDPerfMetricSubKeyDescriptor
, v
, p
) {
72 WRITE_CLASS_DENC(OSDPerfMetricSubKeyDescriptor
)
74 std::ostream
& operator<<(std::ostream
& os
,
75 const OSDPerfMetricSubKeyDescriptor
&d
);
77 typedef std::vector
<OSDPerfMetricSubKeyDescriptor
> OSDPerfMetricKeyDescriptor
;
80 struct denc_traits
<OSDPerfMetricKeyDescriptor
> {
81 static constexpr bool supported
= true;
82 static constexpr bool bounded
= false;
83 static constexpr bool featured
= false;
84 static constexpr bool need_contiguous
= true;
85 static void bound_encode(const OSDPerfMetricKeyDescriptor
& v
, size_t& p
) {
86 p
+= sizeof(uint32_t);
87 const auto size
= v
.size();
94 static void encode(const OSDPerfMetricKeyDescriptor
& v
,
95 bufferlist::contiguous_appender
& p
) {
96 denc_varint(v
.size(), p
);
101 static void decode(OSDPerfMetricKeyDescriptor
& v
,
102 bufferptr::const_iterator
& p
) {
107 for (unsigned i
=0; i
< num
; ++i
) {
108 OSDPerfMetricSubKeyDescriptor d
;
110 if (!d
.is_supported()) {
115 d
.regex
= d
.regex_str
.c_str();
116 } catch (const std::regex_error
& e
) {
120 if (d
.regex
.mark_count() == 0) {
124 v
.push_back(std::move(d
));
129 typedef std::pair
<uint64_t,uint64_t> PerformanceCounter
;
130 typedef std::vector
<PerformanceCounter
> PerformanceCounters
;
132 enum class PerformanceCounterType
: uint8_t {
144 struct PerformanceCounterDescriptor
{
145 PerformanceCounterType type
= static_cast<PerformanceCounterType
>(-1);
147 bool is_supported() const {
149 case PerformanceCounterType::OPS
:
150 case PerformanceCounterType::WRITE_OPS
:
151 case PerformanceCounterType::READ_OPS
:
152 case PerformanceCounterType::BYTES
:
153 case PerformanceCounterType::WRITE_BYTES
:
154 case PerformanceCounterType::READ_BYTES
:
155 case PerformanceCounterType::LATENCY
:
156 case PerformanceCounterType::WRITE_LATENCY
:
157 case PerformanceCounterType::READ_LATENCY
:
164 PerformanceCounterDescriptor() {
167 PerformanceCounterDescriptor(PerformanceCounterType type
) : type(type
) {
170 bool operator<(const PerformanceCounterDescriptor
&other
) const {
171 return type
< other
.type
;
174 bool operator==(const PerformanceCounterDescriptor
&other
) const {
175 return type
== other
.type
;
178 bool operator!=(const PerformanceCounterDescriptor
&other
) const {
179 return type
!= other
.type
;
182 DENC(PerformanceCounterDescriptor
, v
, p
) {
188 void pack_counter(const PerformanceCounter
&c
, bufferlist
*bl
) const;
189 void unpack_counter(bufferlist::const_iterator
& bl
,
190 PerformanceCounter
*c
) const;
192 WRITE_CLASS_DENC(PerformanceCounterDescriptor
)
194 std::ostream
& operator<<(std::ostream
& os
,
195 const PerformanceCounterDescriptor
&d
);
197 typedef std::vector
<PerformanceCounterDescriptor
> PerformanceCounterDescriptors
;
200 struct denc_traits
<PerformanceCounterDescriptors
> {
201 static constexpr bool supported
= true;
202 static constexpr bool bounded
= false;
203 static constexpr bool featured
= false;
204 static constexpr bool need_contiguous
= true;
205 static void bound_encode(const PerformanceCounterDescriptors
& v
, size_t& p
) {
206 p
+= sizeof(uint32_t);
207 const auto size
= v
.size();
210 denc(v
.front(), per
);
214 static void encode(const PerformanceCounterDescriptors
& v
,
215 bufferlist::contiguous_appender
& p
) {
216 denc_varint(v
.size(), p
);
221 static void decode(PerformanceCounterDescriptors
& v
,
222 bufferptr::const_iterator
& p
) {
227 for (unsigned i
=0; i
< num
; ++i
) {
228 PerformanceCounterDescriptor d
;
230 if (d
.is_supported()) {
231 v
.push_back(std::move(d
));
237 struct OSDPerfMetricLimit
{
238 PerformanceCounterDescriptor order_by
;
239 uint64_t max_count
= 0;
241 OSDPerfMetricLimit() {
244 OSDPerfMetricLimit(const PerformanceCounterDescriptor
&order_by
,
246 : order_by(order_by
), max_count(max_count
) {
249 bool operator<(const OSDPerfMetricLimit
&other
) const {
250 if (order_by
!= other
.order_by
) {
251 return order_by
< other
.order_by
;
253 return max_count
< other
.max_count
;
256 DENC(OSDPerfMetricLimit
, v
, p
) {
259 denc(v
.max_count
, p
);
263 WRITE_CLASS_DENC(OSDPerfMetricLimit
)
265 std::ostream
& operator<<(std::ostream
& os
, const OSDPerfMetricLimit
&limit
);
267 typedef std::set
<OSDPerfMetricLimit
> OSDPerfMetricLimits
;
269 typedef int OSDPerfMetricQueryID
;
271 struct OSDPerfMetricQuery
{
272 bool operator<(const OSDPerfMetricQuery
&other
) const {
273 if (key_descriptor
< other
.key_descriptor
) {
276 if (key_descriptor
> other
.key_descriptor
) {
279 return (performance_counter_descriptors
<
280 other
.performance_counter_descriptors
);
283 OSDPerfMetricQuery() {
287 const OSDPerfMetricKeyDescriptor
&key_descriptor
,
288 const PerformanceCounterDescriptors
&performance_counter_descriptors
)
289 : key_descriptor(key_descriptor
),
290 performance_counter_descriptors(performance_counter_descriptors
) {
293 template <typename L
>
294 bool get_key(L
&& get_sub_key
, OSDPerfMetricKey
*key
) const {
295 for (auto &sub_key_descriptor
: key_descriptor
) {
296 OSDPerfMetricSubKey sub_key
;
297 if (!get_sub_key(sub_key_descriptor
, &sub_key
)) {
300 key
->push_back(sub_key
);
305 DENC(OSDPerfMetricQuery
, v
, p
) {
307 denc(v
.key_descriptor
, p
);
308 denc(v
.performance_counter_descriptors
, p
);
312 void get_performance_counter_descriptors(
313 PerformanceCounterDescriptors
*descriptors
) const {
314 *descriptors
= performance_counter_descriptors
;
317 template <typename L
>
318 void update_counters(L
&&update_counter
,
319 PerformanceCounters
*counters
) const {
320 auto it
= counters
->begin();
321 for (auto &descriptor
: performance_counter_descriptors
) {
323 if (it
== counters
->end()) {
324 counters
->push_back(PerformanceCounter());
325 it
= std::prev(counters
->end());
327 update_counter(descriptor
, &(*it
));
332 void pack_counters(const PerformanceCounters
&counters
, bufferlist
*bl
) const;
334 OSDPerfMetricKeyDescriptor key_descriptor
;
335 PerformanceCounterDescriptors performance_counter_descriptors
;
337 WRITE_CLASS_DENC(OSDPerfMetricQuery
)
339 std::ostream
& operator<<(std::ostream
& os
, const OSDPerfMetricQuery
&query
);
341 struct OSDPerfMetricReport
{
342 PerformanceCounterDescriptors performance_counter_descriptors
;
343 std::map
<OSDPerfMetricKey
, bufferlist
> group_packed_performance_counters
;
345 DENC(OSDPerfMetricReport
, v
, p
) {
347 denc(v
.performance_counter_descriptors
, p
);
348 denc(v
.group_packed_performance_counters
, p
);
352 WRITE_CLASS_DENC(OSDPerfMetricReport
)
354 #endif // OSD_PERF_METRIC_H_