13 #ifndef __PROCESS_TIMESERIES_HPP__ 14 #define __PROCESS_TIMESERIES_HPP__ 55 size_t _capacity = TIME_SERIES_CAPACITY)
58 capacity(
std::
max((size_t) 3, _capacity)) {}
76 if (!values.empty() && time < values.rbegin()->first) {
86 std::vector<Value>
get(
91 if (start.isSome() && stop.
isSome() && start.get() > stop.
get()) {
92 return std::vector<Value>();
95 typename std::map<Time, T>::const_iterator
lower = values.lower_bound(
98 typename std::map<Time, T>::const_iterator
upper = values.upper_bound(
101 std::vector<Value> values;
102 while (lower != upper) {
103 values.push_back(
Value(lower->first, lower->second));
115 return Value(values.rbegin()->first, values.rbegin()->second);
118 bool empty()
const {
return values.empty(); }
127 typename std::map<Time, T>::iterator upper_bound =
128 values.upper_bound(expired);
131 if (values.size() <= 1 || upper_bound == values.end()) {
163 if (index.isSome() && upper_bound->first < next->first) {
164 size_t size = values.size();
165 values.erase(values.begin(), upper_bound);
166 index = index.get() - (size - values.size());
169 values.erase(values.begin(), upper_bound);
215 while (values.size() > capacity) {
218 if (index.isNone() || index.get() > values.size() / 2) {
220 next = values.begin();
225 next = values.erase(next);
227 index = index.get() + 1;
237 std::map<Time, T> values;
243 typename std::map<Time, T>::iterator next;
249 #endif // __PROCESS_TIMESERIES_HPP__ Definition: option.hpp:29
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:130
TimeSeries(const Duration &_window=TIME_SERIES_WINDOW, size_t _capacity=TIME_SERIES_CAPACITY)
Definition: timeseries.hpp:54
Definition: type_utils.hpp:619
void expired(const std::shared_ptr< lambda::CallableOnce< Future< T >(const Future< T > &)>> &f, const std::shared_ptr< Latch > &latch, const std::shared_ptr< Promise< T >> &promise, const std::shared_ptr< Option< Timer >> &timer, const Future< T > &future)
Definition: future.hpp:1521
Value(const Time &_time, const T &_data)
Definition: timeseries.hpp:62
Definition: duration.hpp:32
Try< Nothing > start(const std::string &name)
Starts the slice with the given name (via 'systemctl start <name>').
bool isSome() const
Definition: option.hpp:116
constexpr Duration TIME_SERIES_WINDOW
Definition: timeseries.hpp:30
void truncate()
Definition: timeseries.hpp:124
Option< T > max(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:214
bool empty() const
Definition: timeseries.hpp:118
const T & get() const &
Definition: option.hpp:119
Option< Value > latest() const
Definition: timeseries.hpp:109
Time time
Definition: timeseries.hpp:65
std::string upper(const std::string &s)
Definition: strings.hpp:437
Definition: executor.hpp:48
static Time max()
Definition: time.hpp:88
Definition: timeseries.hpp:60
T data
Definition: timeseries.hpp:66
static Time now()
The current clock time for either the current process that makes this call or the global clock time i...
constexpr size_t TIME_SERIES_CAPACITY
Definition: timeseries.hpp:31
std::string lower(const std::string &s)
Definition: strings.hpp:429
Definition: duration.hpp:263
static Time epoch()
Definition: time.hpp:87
Definition: timeseries.hpp:52