]>
git.proxmox.com Git - ceph.git/blob - ceph/src/common/perf_histogram.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2017 OVH
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
15 #include "common/perf_histogram.h"
19 void PerfHistogramCommon::dump_formatted_axis(
20 ceph::Formatter
*f
, const PerfHistogramCommon::axis_config_d
&ac
) {
21 f
->open_object_section("axis");
23 // Dump axis configuration
24 f
->dump_string("name", ac
.m_name
);
25 f
->dump_int("min", ac
.m_min
);
26 f
->dump_int("quant_size", ac
.m_quant_size
);
27 f
->dump_int("buckets", ac
.m_buckets
);
28 switch (ac
.m_scale_type
) {
30 f
->dump_string("scale_type", "linear");
33 f
->dump_string("scale_type", "log2");
36 assert(false && "Invalid scale type");
40 // Dump concrete ranges for axis buckets
41 f
->open_array_section("ranges");
42 auto ranges
= get_axis_bucket_ranges(ac
);
43 for (int i
= 0; i
< ac
.m_buckets
; ++i
) {
44 f
->open_object_section("bucket");
46 f
->dump_int("min", ranges
[i
].first
);
48 if (i
< ac
.m_buckets
- 1) {
49 f
->dump_int("max", ranges
[i
].second
);
59 int64_t get_quants(int64_t i
, PerfHistogramCommon::scale_type_d st
) {
61 case PerfHistogramCommon::SCALE_LINEAR
:
63 case PerfHistogramCommon::SCALE_LOG2
:
64 return int64_t(1) << (i
- 1);
66 assert(false && "Invalid scale type");
69 int64_t PerfHistogramCommon::get_bucket_for_axis(
70 int64_t value
, const PerfHistogramCommon::axis_config_d
&ac
) {
71 if (value
< ac
.m_min
) {
76 value
/= ac
.m_quant_size
;
78 switch (ac
.m_scale_type
) {
80 return std::min
<int64_t>(value
+ 1, ac
.m_buckets
- 1);
83 for (int64_t i
= 1; i
< ac
.m_buckets
; ++i
) {
84 if (value
< get_quants(i
, SCALE_LOG2
)) {
88 return ac
.m_buckets
- 1;
90 assert(false && "Invalid scale type");
93 std::vector
<std::pair
<int64_t, int64_t>>
94 PerfHistogramCommon::get_axis_bucket_ranges(
95 const PerfHistogramCommon::axis_config_d
&ac
) {
96 std::vector
<std::pair
<int64_t, int64_t>> ret
;
97 ret
.resize(ac
.m_buckets
);
99 // First bucket is for value < min
100 int64_t min
= ac
.m_min
;
101 for (int64_t i
= 1; i
< ac
.m_buckets
- 1; i
++) {
102 int64_t max_exclusive
=
103 ac
.m_min
+ get_quants(i
, ac
.m_scale_type
) * ac
.m_quant_size
;
107 ret
[i
].second
= max_exclusive
- 1;
109 // Shift min to next bucket
113 // Fill up first and last element, note that in case m_buckets == 1
114 // those will point to the same element, the order is important here
115 ret
.front().second
= ac
.m_min
- 1;
116 ret
.back().first
= min
;
118 ret
.front().first
= std::numeric_limits
<int64_t>::min();
119 ret
.back().second
= std::numeric_limits
<int64_t>::max();