13 #ifndef __PROCESS_TIMESERIES_HPP__
14 #define __PROCESS_TIMESERIES_HPP__
63 capacity(std::
max((size_t) 3, _capacity)) {}
81 if (!values.empty() &&
time < values.rbegin()->first) {
91 std::vector<Value>
get(
96 if (
start.isSome() && stop.isSome() &&
start.get() > stop.get()) {
97 return std::vector<Value>();
100 typename std::map<Time, T>::const_iterator
lower = values.lower_bound(
103 typename std::map<Time, T>::const_iterator
upper = values.upper_bound(
104 stop.isSome() ? stop.get() :
Time::max());
106 std::vector<Value> values;
107 while (lower != upper) {
108 values.push_back(
Value(lower->first, lower->second));
120 return Value(values.rbegin()->first, values.rbegin()->second);
123 bool empty()
const {
return values.empty(); }
132 typename std::map<Time, T>::iterator upper_bound =
133 values.upper_bound(expired);
136 if (values.size() <= 1 || upper_bound == values.end()) {
168 if (index.
isSome() && upper_bound->first < next->first) {
169 size_t size = values.size();
170 values.erase(values.begin(), upper_bound);
171 index = index.
get() - (size - values.size());
174 values.erase(values.begin(), upper_bound);
220 while (values.size() > capacity) {
223 if (index.
isNone() || index.
get() > values.size() / 2) {
225 next = values.begin();
230 next = values.erase(next);
232 index = index.
get() + 1;
242 std::map<Time, T> values;
248 typename std::map<Time, T>::iterator next;
254 #endif // __PROCESS_TIMESERIES_HPP__
Definition: option.hpp:28
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:100
TimeSeries(const Duration &_window=TIME_SERIES_WINDOW, size_t _capacity=TIME_SERIES_CAPACITY)
Definition: timeseries.hpp:59
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:1537
void set(const T &value, const Time &time=Clock::now())
Definition: timeseries.hpp:74
Value(const Time &_time, const T &_data)
Definition: timeseries.hpp:67
Definition: duration.hpp:32
const Duration TIME_SERIES_WINDOW
Try< Nothing > start(const std::string &name)
Starts the slice with the given name (via 'systemctl start <name>').
bool isSome() const
Definition: option.hpp:115
void truncate()
Definition: timeseries.hpp:129
Option< T > max(const Option< T > &left, const Option< T > &right)
Definition: option.hpp:199
bool empty() const
Definition: timeseries.hpp:123
const T & get() const &
Definition: option.hpp:118
Option< Value > latest() const
Definition: timeseries.hpp:114
Time time
Definition: timeseries.hpp:70
std::string upper(const std::string &s)
Definition: strings.hpp:420
Result< Process > process(pid_t pid)
Definition: freebsd.hpp:30
static Time max()
Definition: time.hpp:88
Definition: timeseries.hpp:65
T data
Definition: timeseries.hpp:71
static Time now()
The current clock time for either the current process that makes this call or the global clock time i...
bool isNone() const
Definition: option.hpp:116
std::string lower(const std::string &s)
Definition: strings.hpp:412
Try< std::vector< Value > > time(const std::string &hierarchy, const std::string &cgroup)
static Time epoch()
Definition: time.hpp:87
Definition: timeseries.hpp:57
const size_t TIME_SERIES_CAPACITY