blob: a80515e89649e37286cc19e115e866d7a59c0975 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
#include "models/counter.hpp"
#include "utils/utils.hpp"
double FreqCounter::rate() const {
uint64_t ms = _timer->total_duration_ms();
if(_timer->overtime()) {
ms = _timer->preset_ms();
}
return static_cast<double>(_cnt) / (ms / 60.0e3);
}
double FreqCounter::overtime_rate() const {
return static_cast<double>(_overtime_cnt) / (_timer->total_duration_ms() / 60.0e3);
}
std::string FreqCounter::display_value() const {
if(_overtime_cnt == UINT32_MAX) {
return "ERR";
}
return std::to_string(_overtime_cnt);
}
std::string FreqCounter::rate_display() const {
double rate = this->rate();
std::string rate_display_val;
format_rate(rate_display_val, rate);
if(_timer->overtime()) {
std::string rate_overtime;
format_rate(rate_overtime, overtime_rate());
rate_display_val.append(", ");
rate_display_val.append(rate_overtime);
}
return rate_display_val;
}
void FreqCounter::inc() {
if(_overtime_cnt != UINT32_MAX)
_overtime_cnt++;
if(!_timer->overtime()) {
_cnt = _overtime_cnt;
}
}
|