-
Notifications
You must be signed in to change notification settings - Fork 12
/
stats.cc
162 lines (146 loc) · 5.08 KB
/
stats.cc
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
/*
* Copyright (C) 2010 Miroslav Lichvar <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "stats.h"
#include "sysheaders.h"
Stats::Stats() {
reset();
}
Stats::~Stats() {
}
void Stats::reset() {
reset_clock_stats();
packets_in_sum2 = 0.0;
packets_out_sum2 = 0.0;
packets_in = 0;
packets_out = 0;
packets_in_time_last = 0.0;
packets_out_time_last = 0.0;
packets_in_int_sum = 0.0;
packets_out_int_sum = 0.0;
packets_in_int_min = 0.0;
packets_out_int_min = 0.0;
wakeups_int_sum = 0;
wakeups = 0;
}
void Stats::reset_clock_stats() {
offset_sum2 = 0.0;
offset_abs_sum = 0.0;
offset_sum = 0.0;
offset_abs_max = 0.0;
freq_sum2 = 0.0;
freq_abs_sum = 0.0;
freq_sum = 0.0;
freq_abs_max = 0.0;
rawfreq_sum2 = 0.0;
rawfreq_abs_sum = 0.0;
rawfreq_sum = 0.0;
rawfreq_abs_max = 0.0;
samples = 0;
}
void Stats::update_clock_stats(double offset, double freq, double rawfreq) {
offset_sum2 += offset * offset;
offset_abs_sum += fabs(offset);
offset_sum += offset;
if (offset_abs_max < fabs(offset))
offset_abs_max = fabs(offset);
freq_sum2 += freq * freq;
freq_abs_sum += fabs(freq);
freq_sum += freq;
if (freq_abs_max < fabs(freq))
freq_abs_max = fabs(freq);
rawfreq_sum2 += rawfreq * rawfreq;
rawfreq_abs_sum += fabs(rawfreq);
rawfreq_sum += rawfreq;
if (rawfreq_abs_max < fabs(rawfreq))
rawfreq_abs_max = fabs(rawfreq);
samples++;
wakeups_int_sum++;
}
void Stats::update_packet_stats(bool incoming, double time, double delay) {
if (delay < 0.0)
delay = 0.0;
if (incoming) {
packets_in++;
packets_in_sum2 += delay * delay;
if (packets_in >= 2) {
packets_in_int_sum += time - packets_in_time_last;
if (packets_in == 2 || packets_in_int_min > time - packets_in_time_last)
packets_in_int_min = time - packets_in_time_last;
}
packets_in_time_last = time;
} else {
packets_out++;
packets_out_sum2 += delay * delay;
if (packets_out >= 2) {
packets_out_int_sum += time - packets_out_time_last;
if (packets_out == 2 || packets_out_int_min > time - packets_out_time_last)
packets_out_int_min = time - packets_out_time_last;
}
packets_out_time_last = time;
}
}
void Stats::update_wakeup_stats() {
wakeups++;
}
void Stats::print(int verbosity) const {
if (verbosity <= 0)
return;
if (verbosity <= 1) {
printf("%e ", sqrt(offset_sum2 / samples));
return;
}
printf("RMS offset: \t%e\n", sqrt(offset_sum2 / samples));
printf("Maximum absolute offset: \t%e\n", offset_abs_max);
printf("Mean absolute offset: \t%e\n", offset_abs_sum / samples);
printf("Mean offset: \t%e\n", offset_sum / samples);
printf("RMS frequency: \t%e\n", sqrt(freq_sum2 / samples));
printf("Maximum absolute frequency: \t%e\n", freq_abs_max);
printf("Mean absolute frequency: \t%e\n", freq_abs_sum / samples);
printf("Mean frequency: \t%e\n", freq_sum / samples);
printf("RMS raw frequency: \t%e\n", sqrt(rawfreq_sum2 / samples));
printf("Maximum absolute raw frequency: \t%e\n", rawfreq_abs_max);
printf("Mean absolute raw frequency: \t%e\n", rawfreq_abs_sum / samples);
printf("Mean raw frequency: \t%e\n", rawfreq_sum / samples);
if (packets_in) {
printf("RMS incoming packet delay: \t%e\n", (double)sqrt(packets_in_sum2 / packets_in));
} else {
printf("RMS incoming packet delay: \tinf\n");
}
if (packets_in >= 2) {
printf("Mean incoming packet interval: \t%e\n", packets_in_int_sum / (packets_in - 1));
printf("Minimum incoming packet interval: \t%e\n", packets_in_int_min);
} else {
printf("Mean incoming packet interval: \tinf\n");
printf("Minimum incoming packet interval: \tinf\n");
}
if (packets_out) {
printf("RMS outgoing packet delay: \t%e\n", (double)sqrt(packets_out_sum2 / packets_out));
} else {
printf("RMS outgoing packet delay: \tinf\n");
}
if (packets_out >= 2) {
printf("Mean outgoing packet interval: \t%e\n", packets_out_int_sum / (packets_out - 1));
printf("Minimum outgoing packet interval: \t%e\n", packets_out_int_min);
} else {
printf("Mean outgoing packet interval: \tinf\n");
printf("Minimum outgoing packet interval: \tinf\n");
}
if (wakeups)
printf("Mean wakeup interval: \t%e\n", (double)wakeups_int_sum / wakeups);
else
printf("Mean wakeup interval: \tinf\n");
}