SLikeNet 0.1.3

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RakNetStatistics.cpp
Go to the documentation of this file.
1 /*
2 * Original work: Copyright (c) 2014, Oculus VR, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * RakNet License.txt file in the licenses directory of this source tree. An additional grant
7 * of patent rights can be found in the RakNet Patents.txt file in the same directory.
8 *
9 *
10 * Modified work: Copyright (c) 2016-2018, SLikeSoft UG (haftungsbeschränkt)
11 *
12 * This source code was modified by SLikeSoft. Modifications are licensed under the MIT-style
13 * license found in the license.txt file in the root directory of this source tree.
14 */
15
18
19
20
21 #include "slikenet/statistics.h"
22 #include <stdio.h> // sprintf
23 #include "slikenet/GetTime.h"
24 #include "slikenet/string.h"
25 #include "slikenet/linux_adapter.h"
26 #include "slikenet/osx_adapter.h"
27
28 using namespace SLNet;
29
30 // Verbosity level currently supports 0 (low), 1 (medium), 2 (high)
31 // Buffer must be hold enough to hold the output string. See the source to get an idea of how many bytes will be output
32 void RAK_DLL_EXPORT SLNet::StatisticsToString(RakNetStatistics *s, char *buffer, int verbosityLevel)
33 {
34 if (s == 0)
35 {
36 #pragma warning(push)
37 #pragma warning(disable:4996)
38 sprintf(buffer, "stats is a NULL pointer in statsToString\n");
39 #pragma warning(pop)
40 return;
41 }
42
43 if (verbosityLevel == 0)
44 {
45 #pragma warning(push)
46 #pragma warning(disable:4996)
47 sprintf(buffer,
48 "Bytes per second sent %" PRINTF_64_BIT_MODIFIER "u\n"
49 "Bytes per second received %" PRINTF_64_BIT_MODIFIER "u\n"
50 "Current packetloss %.1f%%\n",
51 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_SENT],
52 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_RECEIVED],
53 s->packetlossLastSecond*100.0f
54 );
55 #pragma warning(pop)
56 }
57 else if (verbosityLevel == 1)
58 {
59 #pragma warning(push)
60 #pragma warning(disable:4996)
61 sprintf(buffer,
62 "Actual bytes per second sent %" PRINTF_64_BIT_MODIFIER "u\n"
63 "Actual bytes per second received %" PRINTF_64_BIT_MODIFIER "u\n"
64 "Message bytes per second pushed %" PRINTF_64_BIT_MODIFIER "u\n"
65 "Total actual bytes sent %" PRINTF_64_BIT_MODIFIER "u\n"
66 "Total actual bytes received %" PRINTF_64_BIT_MODIFIER "u\n"
67 "Total message bytes pushed %" PRINTF_64_BIT_MODIFIER "u\n"
68 "Current packetloss %.1f%%\n"
69 "Average packetloss %.1f%%\n"
70 "Elapsed connection time in seconds %" PRINTF_64_BIT_MODIFIER "u\n",
71 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_SENT],
72 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_RECEIVED],
73 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_PUSHED],
74 (long long unsigned int) s->runningTotal[ACTUAL_BYTES_SENT],
75 (long long unsigned int) s->runningTotal[ACTUAL_BYTES_RECEIVED],
76 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_PUSHED],
77 s->packetlossLastSecond*100.0f,
78 s->packetlossTotal*100.0f,
79 (long long unsigned int) (uint64_t)((SLNet::GetTimeUS() - s->connectionStartTime) / 1000000)
80 );
81 #pragma warning(pop)
82
83 if (s->BPSLimitByCongestionControl != 0)
84 {
85 char buff2[128];
86 sprintf_s(buff2,
87 "Send capacity %" PRINTF_64_BIT_MODIFIER "u bytes per second (%.0f%%)\n",
88 (long long unsigned int) s->BPSLimitByCongestionControl,
89 100.0f * s->valueOverLastSecond[ACTUAL_BYTES_SENT] / s->BPSLimitByCongestionControl
90 );
91 #pragma warning(push)
92 #pragma warning(disable:4996)
93 strcat(buffer, buff2);
94 #pragma warning(pop)
95 }
96 if (s->BPSLimitByOutgoingBandwidthLimit != 0)
97 {
98 char buff2[128];
99 sprintf_s(buff2,
100 "Send limit %" PRINTF_64_BIT_MODIFIER "u (%.0f%%)\n",
101 (long long unsigned int) s->BPSLimitByOutgoingBandwidthLimit,
102 100.0f * s->valueOverLastSecond[ACTUAL_BYTES_SENT] / s->BPSLimitByOutgoingBandwidthLimit
103 );
104 #pragma warning(push)
105 #pragma warning(disable:4996)
106 strcat(buffer, buff2);
107 #pragma warning(pop)
108 }
109 }
110 else
111 {
112 #pragma warning(push)
113 #pragma warning(disable:4996)
114 sprintf(buffer,
115 "Actual bytes per second sent %" PRINTF_64_BIT_MODIFIER "u\n"
116 "Actual bytes per second received %" PRINTF_64_BIT_MODIFIER "u\n"
117 "Message bytes per second sent %" PRINTF_64_BIT_MODIFIER "u\n"
118 "Message bytes per second resent %" PRINTF_64_BIT_MODIFIER "u\n"
119 "Message bytes per second pushed %" PRINTF_64_BIT_MODIFIER "u\n"
120 "Message bytes per second returned %" PRINTF_64_BIT_MODIFIER "u\n"
121 "Message bytes per second ignored %" PRINTF_64_BIT_MODIFIER "u\n"
122 "Total bytes sent %" PRINTF_64_BIT_MODIFIER "u\n"
123 "Total bytes received %" PRINTF_64_BIT_MODIFIER "u\n"
124 "Total message bytes sent %" PRINTF_64_BIT_MODIFIER "u\n"
125 "Total message bytes resent %" PRINTF_64_BIT_MODIFIER "u\n"
126 "Total message bytes pushed %" PRINTF_64_BIT_MODIFIER "u\n"
127 "Total message bytes returned %" PRINTF_64_BIT_MODIFIER "u\n"
128 "Total message bytes ignored %" PRINTF_64_BIT_MODIFIER "u\n"
129 "Messages in send buffer, by priority %i,%i,%i,%i\n"
130 "Bytes in send buffer, by priority %i,%i,%i,%i\n"
131 "Messages in resend buffer %i\n"
132 "Bytes in resend buffer %" PRINTF_64_BIT_MODIFIER "u\n"
133 "Current packetloss %.1f%%\n"
134 "Average packetloss %.1f%%\n"
135 "Elapsed connection time in seconds %" PRINTF_64_BIT_MODIFIER "u\n",
136 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_SENT],
137 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_RECEIVED],
138 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_SENT],
139 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_RESENT],
140 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_PUSHED],
141 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_RECEIVED_PROCESSED],
142 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_RECEIVED_IGNORED],
143 (long long unsigned int) s->runningTotal[ACTUAL_BYTES_SENT],
144 (long long unsigned int) s->runningTotal[ACTUAL_BYTES_RECEIVED],
145 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_SENT],
146 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_RESENT],
147 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_PUSHED],
148 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_RECEIVED_PROCESSED],
149 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_RECEIVED_IGNORED],
150 s->messageInSendBuffer[IMMEDIATE_PRIORITY], s->messageInSendBuffer[HIGH_PRIORITY], s->messageInSendBuffer[MEDIUM_PRIORITY], s->messageInSendBuffer[LOW_PRIORITY],
151 (unsigned int)s->bytesInSendBuffer[IMMEDIATE_PRIORITY], (unsigned int)s->bytesInSendBuffer[HIGH_PRIORITY], (unsigned int)s->bytesInSendBuffer[MEDIUM_PRIORITY], (unsigned int)s->bytesInSendBuffer[LOW_PRIORITY],
152 s->messagesInResendBuffer,
153 (long long unsigned int) s->bytesInResendBuffer,
154 s->packetlossLastSecond*100.0f,
155 s->packetlossTotal*100.0f,
156 (long long unsigned int) (uint64_t)((SLNet::GetTimeUS() - s->connectionStartTime) / 1000000)
157 );
158 #pragma warning(pop)
159
160 if (s->BPSLimitByCongestionControl != 0)
161 {
162 char buff2[128];
163 sprintf_s(buff2,
164 "Send capacity %" PRINTF_64_BIT_MODIFIER "u bytes per second (%.0f%%)\n",
165 (long long unsigned int) s->BPSLimitByCongestionControl,
166 100.0f * s->valueOverLastSecond[ACTUAL_BYTES_SENT] / s->BPSLimitByCongestionControl
167 );
168 #pragma warning(push)
169 #pragma warning(disable:4996)
170 strcat(buffer, buff2);
171 #pragma warning(pop)
172 }
173 if (s->BPSLimitByOutgoingBandwidthLimit != 0)
174 {
175 char buff2[128];
176 sprintf_s(buff2,
177 "Send limit %" PRINTF_64_BIT_MODIFIER "u (%.0f%%)\n",
178 (long long unsigned int) s->BPSLimitByOutgoingBandwidthLimit,
179 100.0f * s->valueOverLastSecond[ACTUAL_BYTES_SENT] / s->BPSLimitByOutgoingBandwidthLimit
180 );
181 #pragma warning(push)
182 #pragma warning(disable:4996)
183 strcat(buffer, buff2);
184 #pragma warning(pop)
185 }
186 }
187 }
188 void RAK_DLL_EXPORT SLNet::StatisticsToString( RakNetStatistics *s, char *buffer, size_t bufferLength, int verbosityLevel )
189 {
190 if ( s == 0 )
191 {
192 sprintf_s( buffer, bufferLength, "stats is a NULL pointer in statsToString\n" );
193 return ;
194 }
195
196 if (verbosityLevel==0)
197 {
198 sprintf_s(buffer, bufferLength,
199 "Bytes per second sent %" PRINTF_64_BIT_MODIFIER "u\n"
200 "Bytes per second received %" PRINTF_64_BIT_MODIFIER "u\n"
201 "Current packetloss %.1f%%\n",
202 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_SENT],
203 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_RECEIVED],
204 s->packetlossLastSecond*100.0f
205 );
206 }
207 else if (verbosityLevel==1)
208 {
209 sprintf_s(buffer, bufferLength,
210 "Actual bytes per second sent %" PRINTF_64_BIT_MODIFIER "u\n"
211 "Actual bytes per second received %" PRINTF_64_BIT_MODIFIER "u\n"
212 "Message bytes per second pushed %" PRINTF_64_BIT_MODIFIER "u\n"
213 "Total actual bytes sent %" PRINTF_64_BIT_MODIFIER "u\n"
214 "Total actual bytes received %" PRINTF_64_BIT_MODIFIER "u\n"
215 "Total message bytes pushed %" PRINTF_64_BIT_MODIFIER "u\n"
216 "Current packetloss %.1f%%\n"
217 "Average packetloss %.1f%%\n"
218 "Elapsed connection time in seconds %" PRINTF_64_BIT_MODIFIER "u\n",
219 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_SENT],
220 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_RECEIVED],
221 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_PUSHED],
222 (long long unsigned int) s->runningTotal[ACTUAL_BYTES_SENT],
223 (long long unsigned int) s->runningTotal[ACTUAL_BYTES_RECEIVED],
224 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_PUSHED],
225 s->packetlossLastSecond*100.0f,
226 s->packetlossTotal*100.0f,
227 (long long unsigned int) (uint64_t)((SLNet::GetTimeUS()-s->connectionStartTime)/1000000)
228 );
229
230 if (s->BPSLimitByCongestionControl!=0)
231 {
232 char buff2[128];
233 sprintf_s(buff2,
234 "Send capacity %" PRINTF_64_BIT_MODIFIER "u bytes per second (%.0f%%)\n",
235 (long long unsigned int) s->BPSLimitByCongestionControl,
236 100.0f * s->valueOverLastSecond[ACTUAL_BYTES_SENT] / s->BPSLimitByCongestionControl
237 );
238 strcat_s(buffer,bufferLength,buff2);
239 }
240 if (s->BPSLimitByOutgoingBandwidthLimit!=0)
241 {
242 char buff2[128];
243 sprintf_s(buff2,
244 "Send limit %" PRINTF_64_BIT_MODIFIER "u (%.0f%%)\n",
245 (long long unsigned int) s->BPSLimitByOutgoingBandwidthLimit,
246 100.0f * s->valueOverLastSecond[ACTUAL_BYTES_SENT] / s->BPSLimitByOutgoingBandwidthLimit
247 );
248 strcat_s(buffer,bufferLength,buff2);
249 }
250 }
251 else
252 {
253 sprintf_s(buffer, bufferLength,
254 "Actual bytes per second sent %" PRINTF_64_BIT_MODIFIER "u\n"
255 "Actual bytes per second received %" PRINTF_64_BIT_MODIFIER "u\n"
256 "Message bytes per second sent %" PRINTF_64_BIT_MODIFIER "u\n"
257 "Message bytes per second resent %" PRINTF_64_BIT_MODIFIER "u\n"
258 "Message bytes per second pushed %" PRINTF_64_BIT_MODIFIER "u\n"
259 "Message bytes per second returned %" PRINTF_64_BIT_MODIFIER "u\n"
260 "Message bytes per second ignored %" PRINTF_64_BIT_MODIFIER "u\n"
261 "Total bytes sent %" PRINTF_64_BIT_MODIFIER "u\n"
262 "Total bytes received %" PRINTF_64_BIT_MODIFIER "u\n"
263 "Total message bytes sent %" PRINTF_64_BIT_MODIFIER "u\n"
264 "Total message bytes resent %" PRINTF_64_BIT_MODIFIER "u\n"
265 "Total message bytes pushed %" PRINTF_64_BIT_MODIFIER "u\n"
266 "Total message bytes returned %" PRINTF_64_BIT_MODIFIER "u\n"
267 "Total message bytes ignored %" PRINTF_64_BIT_MODIFIER "u\n"
268 "Messages in send buffer, by priority %i,%i,%i,%i\n"
269 "Bytes in send buffer, by priority %i,%i,%i,%i\n"
270 "Messages in resend buffer %i\n"
271 "Bytes in resend buffer %" PRINTF_64_BIT_MODIFIER "u\n"
272 "Current packetloss %.1f%%\n"
273 "Average packetloss %.1f%%\n"
274 "Elapsed connection time in seconds %" PRINTF_64_BIT_MODIFIER "u\n",
275 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_SENT],
276 (long long unsigned int) s->valueOverLastSecond[ACTUAL_BYTES_RECEIVED],
277 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_SENT],
278 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_RESENT],
279 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_PUSHED],
280 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_RECEIVED_PROCESSED],
281 (long long unsigned int) s->valueOverLastSecond[USER_MESSAGE_BYTES_RECEIVED_IGNORED],
282 (long long unsigned int) s->runningTotal[ACTUAL_BYTES_SENT],
283 (long long unsigned int) s->runningTotal[ACTUAL_BYTES_RECEIVED],
284 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_SENT],
285 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_RESENT],
286 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_PUSHED],
287 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_RECEIVED_PROCESSED],
288 (long long unsigned int) s->runningTotal[USER_MESSAGE_BYTES_RECEIVED_IGNORED],
289 s->messageInSendBuffer[IMMEDIATE_PRIORITY],s->messageInSendBuffer[HIGH_PRIORITY],s->messageInSendBuffer[MEDIUM_PRIORITY],s->messageInSendBuffer[LOW_PRIORITY],
290 (unsigned int) s->bytesInSendBuffer[IMMEDIATE_PRIORITY],(unsigned int) s->bytesInSendBuffer[HIGH_PRIORITY],(unsigned int) s->bytesInSendBuffer[MEDIUM_PRIORITY],(unsigned int) s->bytesInSendBuffer[LOW_PRIORITY],
291 s->messagesInResendBuffer,
292 (long long unsigned int) s->bytesInResendBuffer,
293 s->packetlossLastSecond*100.0f,
294 s->packetlossTotal*100.0f,
295 (long long unsigned int) (uint64_t)((SLNet::GetTimeUS()-s->connectionStartTime)/1000000)
296 );
297
298 if (s->BPSLimitByCongestionControl!=0)
299 {
300 char buff2[128];
301 sprintf_s(buff2,
302 "Send capacity %" PRINTF_64_BIT_MODIFIER "u bytes per second (%.0f%%)\n",
303 (long long unsigned int) s->BPSLimitByCongestionControl,
304 100.0f * s->valueOverLastSecond[ACTUAL_BYTES_SENT] / s->BPSLimitByCongestionControl
305 );
306 strcat_s(buffer,bufferLength,buff2);
307 }
308 if (s->BPSLimitByOutgoingBandwidthLimit!=0)
309 {
310 char buff2[128];
311 sprintf_s(buff2,
312 "Send limit %" PRINTF_64_BIT_MODIFIER "u (%.0f%%)\n",
313 (long long unsigned int) s->BPSLimitByOutgoingBandwidthLimit,
314 100.0f * s->valueOverLastSecond[ACTUAL_BYTES_SENT] / s->BPSLimitByOutgoingBandwidthLimit
315 );
316 strcat_s(buffer,bufferLength,buff2);
317 }
318 }
319 }