mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-22 07:42:16 +00:00
52 lines
1.9 KiB
C++
52 lines
1.9 KiB
C++
/*
|
|
* Copyright (C) 2020-present ScyllaDB
|
|
*
|
|
* Modified by ScyllaDB
|
|
*/
|
|
|
|
/*
|
|
* SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.1
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <seastar/core/metrics_types.hh>
|
|
#include "seastarx.hh"
|
|
#include "estimated_histogram.hh"
|
|
#include "histogram.hh"
|
|
|
|
template<uint64_t Min, uint64_t Max, size_t Precision>
|
|
seastar::metrics::histogram to_metrics_histogram(const utils::approx_exponential_histogram<Min, Max, Precision>& hist) {
|
|
seastar::metrics::histogram res;
|
|
static constexpr uint64_t SCALED_MIN = utils::approx_exponential_histogram<Min, Max, Precision>::SCALED_MIN;
|
|
static constexpr size_t MIN_ID = log2ceil(SCALED_MIN) * Precision + 1;
|
|
static constexpr size_t Schema = log2floor(Precision);
|
|
res.buckets.reserve(hist.size() - 1);
|
|
uint64_t cummulative_count = 0;
|
|
|
|
res.native_histogram = seastar::metrics::native_histogram_info{Schema, MIN_ID};
|
|
for (size_t i = 0; i < hist.NUM_BUCKETS - 1; i++) {
|
|
double upper_bound = hist.get_bucket_lower_limit(i + 1);
|
|
cummulative_count += hist.get(i);
|
|
if (!res.buckets.empty() && res.buckets.back().upper_bound == upper_bound) {
|
|
res.buckets.back().count = cummulative_count;
|
|
} else {
|
|
res.buckets.push_back(seastar::metrics::histogram_bucket{cummulative_count, upper_bound});
|
|
}
|
|
}
|
|
// The count serves as the infinite bucket
|
|
res.sample_count = cummulative_count + hist.get(hist.NUM_BUCKETS - 1);
|
|
res.sample_sum = hist.sum();
|
|
return res;
|
|
}
|
|
|
|
/*!
|
|
* \brief get a metrics summary from timed_rate_moving_average_with_summary
|
|
*
|
|
* timed_rate_moving_average_with_summary contains a summary. This function
|
|
* copy it to a metric summary.
|
|
* A metric summary is a histogram where each bucket holds some quantile.
|
|
*/
|
|
seastar::metrics::histogram to_metrics_summary(const utils::summary_calculator& summary) noexcept;
|