13 #ifndef __PROCESS_STATISTICS_HPP__ 14 #define __PROCESS_STATISTICS_HPP__ 16 #include <glog/logging.h> 20 #include <type_traits> 45 std::vector<typename TimeSeries<T>::Value> values_ = timeseries.
get();
47 std::vector<T> values;
48 values.reserve(values_.size());
51 values.push_back(value.
data);
54 return from(std::move(values));
65 typename =
typename std::enable_if<
67 typename std::iterator_traits<It>::value_type,
70 typename std::iterator_traits<It>::iterator_category,
71 std::forward_iterator_tag>::value>
::type>
75 std::vector<T> values;
76 values.reserve(std::distance(first, last));
78 std::copy(first, last, std::back_inserter(values));
80 return from(std::move(values));
103 if (values.size() < 2) {
107 std::sort(values.begin(), values.end());
111 statistics.count = values.size();
113 statistics.min = values.front();
114 statistics.max = values.back();
116 statistics.p25 = percentile(values, 0.25);
117 statistics.p50 = percentile(values, 0.5);
118 statistics.p75 = percentile(values, 0.75);
119 statistics.p90 = percentile(values, 0.90);
120 statistics.p95 = percentile(values, 0.95);
121 statistics.p99 = percentile(values, 0.99);
122 statistics.p999 = percentile(values, 0.999);
123 statistics.p9999 = percentile(values, 0.9999);
132 static T percentile(
const std::vector<T>& values,
double percentile)
134 CHECK_GE(values.size(), 2u);
136 if (percentile <= 0.0) {
137 return values.front();
140 if (percentile >= 1.0) {
141 return values.back();
145 const double position = percentile * (values.size() - 1);
146 const size_t index =
static_cast<size_t>(floor(position));
147 const double delta = position -
index;
150 CHECK_LT(index, values.size() - 1);
152 return values[
index] + (values[index + 1] - values[
index]) * delta;
158 #endif // __PROCESS_STATISTICS_HPP__ size_t count
Definition: statistics.hpp:83
T max
Definition: statistics.hpp:86
Definition: option.hpp:29
T p75
Definition: statistics.hpp:91
Result< hashmap< std::string, uint64_t > > statistics(const std::string &link)
Result< int > index(const std::string &link)
T p95
Definition: statistics.hpp:93
std::vector< Value > get(const Option< Time > &start=None(), const Option< Time > &stop=None()) const
Definition: timeseries.hpp:86
T p9999
Definition: statistics.hpp:96
static Option< Statistics< T > > from(const TimeSeries< T > ×eries)
Definition: statistics.hpp:43
T min
Definition: statistics.hpp:85
T p50
Definition: statistics.hpp:90
Definition: executor.hpp:48
Definition: timeseries.hpp:60
T data
Definition: timeseries.hpp:66
T p25
Definition: statistics.hpp:89
Try< uint32_t > type(const std::string &path)
T p99
Definition: statistics.hpp:94
T p90
Definition: statistics.hpp:92
T p999
Definition: statistics.hpp:95
T copy(const T &t)
Definition: utils.hpp:21
Definition: statistics.hpp:32
Definition: timeseries.hpp:52
static Option< Statistics< T > > from(It first, It last)
Definition: statistics.hpp:72