Statistics
| Branch: | Revision:

streamers / measures.c @ 4fec81f0

History | View | Annotate | Download (9.88 KB)

1 7f591208 Csaba Kiraly
/*
2
 *  Copyright (c) 2010 Csaba Kiraly
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6 c887bcd8 Csaba Kiraly
#include <stdio.h>
7 473a00b3 Csaba Kiraly
#include <stdint.h>
8 d94fc181 Csaba Kiraly
#include <string.h>
9 473a00b3 Csaba Kiraly
#include <math.h>
10
#ifndef NAN        //NAN is missing in some old math.h versions
11
#define NAN            (0.0/0.0)
12
#endif
13
#ifndef INFINITY
14
#define INFINITY       (1.0/0.0)
15
#endif
16 c7a8895d Csaba Kiraly
#include <sys/time.h>
17 473a00b3 Csaba Kiraly
18
#include "measures.h"
19 74bf94f2 Csaba Kiraly
#include "grapes_msg_types.h"
20 473a00b3 Csaba Kiraly
21 75b2b975 Csaba Kiraly
struct timeval print_tdiff = {3600, 0};
22
struct timeval tstartdiff = {60, 0};
23 d94fc181 Csaba Kiraly
static struct timeval tstart;
24 0bc20f3a Csaba Kiraly
static struct timeval print_tstart;
25 d94fc181 Csaba Kiraly
static struct timeval tnext;
26 c7a8895d Csaba Kiraly
27 d94fc181 Csaba Kiraly
struct measures {
28
  int duplicates;
29
  int chunks;
30
  int played;
31
  uint64_t sum_reorder_delay;
32 ff5dbe89 Csaba Kiraly
33 d94fc181 Csaba Kiraly
  int chunks_received_dup, chunks_received_nodup, chunks_received_old;
34
  int sum_hopcount;
35
  uint64_t sum_receive_delay;
36 6095e14c Csaba Kiraly
37 d94fc181 Csaba Kiraly
  int chunks_sent;
38 6095e14c Csaba Kiraly
39 d94fc181 Csaba Kiraly
  uint64_t sum_neighsize;
40
  int samples_neighsize;
41 ff5dbe89 Csaba Kiraly
42 d94fc181 Csaba Kiraly
  uint64_t bytes_sent, bytes_sent_chunk, bytes_sent_sign, bytes_sent_topo;
43
  int msgs_sent, msgs_sent_chunk, msgs_sent_sign, msgs_sent_topo;
44 74bf94f2 Csaba Kiraly
45 d94fc181 Csaba Kiraly
  uint64_t bytes_recvd, bytes_recvd_chunk, bytes_recvd_sign, bytes_recvd_topo;
46
  int msgs_recvd, msgs_recvd_chunk, msgs_recvd_sign, msgs_recvd_topo;
47 74bf94f2 Csaba Kiraly
48 d94fc181 Csaba Kiraly
  uint64_t sum_offers_in_flight;
49
  int samples_offers_in_flight;
50
  double sum_queue_delay;
51
  int samples_queue_delay;
52 4c6ae584 Csaba Kiraly
53 d94fc181 Csaba Kiraly
  int offers;
54
  int accepts;
55
};
56 c4a89b29 Csaba Kiraly
57 d94fc181 Csaba Kiraly
static struct measures m;
58
59
void clean_measures()
60
{
61
  memset(&m, 0, sizeof(m));
62
}
63 4c6ae584 Csaba Kiraly
64 6095e14c Csaba Kiraly
double tdiff_sec(const struct timeval *a, const struct timeval *b)
65
{
66
  struct timeval tdiff;
67
  timersub(a, b, &tdiff);
68
  return tdiff.tv_sec + tdiff.tv_usec / 1000000.0;
69
}
70
71
void print_measure(const char *name, double value)
72
{
73 d94fc181 Csaba Kiraly
  fprintf(stderr,"abouttopublish,,,,%s,%f,,,%f\n", name, value, tdiff_sec(&tnext, &tstart));
74 6095e14c Csaba Kiraly
}
75
76 c7a8895d Csaba Kiraly
void print_measures()
77
{
78 6095e14c Csaba Kiraly
  struct timeval tnow;
79
80 d94fc181 Csaba Kiraly
  if (m.chunks) print_measure("PlayoutRatio", (double)m.played / m.chunks);
81
  if (m.chunks) print_measure("ReorderDelay(ok&lost)", (double)m.sum_reorder_delay / 1e6 / m.chunks);
82
  if (m.samples_neighsize) print_measure("NeighSize", (double)m.sum_neighsize / m.samples_neighsize);
83
  if (m.chunks_received_nodup) print_measure("OverlayDistance(intime&nodup)", (double)m.sum_hopcount / m.chunks_received_nodup);
84
  if (m.chunks_received_nodup) print_measure("ReceiveDelay(intime&nodup)", (double)m.sum_receive_delay / 1e6 / m.chunks_received_nodup);
85 6095e14c Csaba Kiraly
86
  gettimeofday(&tnow, NULL);
87 d94fc181 Csaba Kiraly
  if (timerisset(&print_tstart)) print_measure("ChunkRate", (double) m.chunks / tdiff_sec(&tnow, &print_tstart));
88
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(all)", (double) (m.chunks_received_old + m.chunks_received_nodup + m.chunks_received_dup)  / tdiff_sec(&tnow, &print_tstart));
89
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(old)", (double) m.chunks_received_old / tdiff_sec(&tnow, &print_tstart));
90
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(intime&nodup)", (double) m.chunks_received_nodup / tdiff_sec(&tnow, &print_tstart));
91
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(intime&dup)", (double) m.chunks_received_dup / tdiff_sec(&tnow, &print_tstart));
92
  if (timerisset(&print_tstart)) print_measure("ChunkSendRate", (double) m.chunks_sent / tdiff_sec(&tnow, &print_tstart));
93 dfcfa0fe Csaba Kiraly
94 74bf94f2 Csaba Kiraly
  if (timerisset(&print_tstart)) {
95 d94fc181 Csaba Kiraly
    print_measure("SendRateMsgs(all)", (double) m.msgs_sent / tdiff_sec(&tnow, &print_tstart));
96
    print_measure("SendRateMsgs(chunk)", (double) m.msgs_sent_chunk / tdiff_sec(&tnow, &print_tstart));
97
    print_measure("SendRateMsgs(sign)", (double) m.msgs_sent_sign / tdiff_sec(&tnow, &print_tstart));
98
    print_measure("SendRateMsgs(topo)", (double) m.msgs_sent_topo / tdiff_sec(&tnow, &print_tstart));
99
    print_measure("SendRateMsgs(other)", (double) (m.msgs_sent - m.msgs_sent_chunk - m.msgs_sent_sign - m.msgs_sent_topo) / tdiff_sec(&tnow, &print_tstart));
100
101
    print_measure("SendRateBytes(all)", (double) m.bytes_sent / tdiff_sec(&tnow, &print_tstart));
102
    print_measure("SendRateBytes(chunk)", (double) m.bytes_sent_chunk / tdiff_sec(&tnow, &print_tstart));
103
    print_measure("SendRateBytes(sign)", (double) m.bytes_sent_sign / tdiff_sec(&tnow, &print_tstart));
104
    print_measure("SendRateBytes(topo)", (double) m.bytes_sent_topo / tdiff_sec(&tnow, &print_tstart));
105
    print_measure("SendRateBytes(other)", (double) (m.bytes_sent - m.bytes_sent_chunk - m.bytes_sent_sign - m.bytes_sent_topo) / tdiff_sec(&tnow, &print_tstart));
106
107
    print_measure("RecvRateMsgs(all)", (double) m.msgs_recvd / tdiff_sec(&tnow, &print_tstart));
108
    print_measure("RecvRateMsgs(chunk)", (double) m.msgs_recvd_chunk / tdiff_sec(&tnow, &print_tstart));
109
    print_measure("RecvRateMsgs(sign)", (double) m.msgs_recvd_sign / tdiff_sec(&tnow, &print_tstart));
110
    print_measure("RecvRateMsgs(topo)", (double) m.msgs_recvd_topo / tdiff_sec(&tnow, &print_tstart));
111
    print_measure("RecvRateMsgs(other)", (double) (m.msgs_recvd - m.msgs_recvd_chunk - m.msgs_recvd_sign - m.msgs_recvd_topo) / tdiff_sec(&tnow, &print_tstart));
112
113
    print_measure("RecvRateBytes(all)", (double) m.bytes_recvd / tdiff_sec(&tnow, &print_tstart));
114
    print_measure("RecvRateBytes(chunk)", (double) m.bytes_recvd_chunk / tdiff_sec(&tnow, &print_tstart));
115
    print_measure("RecvRateBytes(sign)", (double) m.bytes_recvd_sign / tdiff_sec(&tnow, &print_tstart));
116
    print_measure("RecvRateBytes(topo)", (double) m.bytes_recvd_topo / tdiff_sec(&tnow, &print_tstart));
117
    print_measure("RecvRateBytes(other)", (double) (m.bytes_recvd - m.bytes_recvd_chunk - m.bytes_recvd_sign - m.bytes_recvd_topo) / tdiff_sec(&tnow, &print_tstart));
118 74bf94f2 Csaba Kiraly
  }
119
120 d94fc181 Csaba Kiraly
  if (m.chunks_received_old + m.chunks_received_nodup + m.chunks_received_dup) print_measure("ReceiveRatio(intime&nodup-vs-all)", (double)m.chunks_received_nodup / (m.chunks_received_old + m.chunks_received_nodup + m.chunks_received_dup));
121 4c6ae584 Csaba Kiraly
122 d94fc181 Csaba Kiraly
  if (m.samples_offers_in_flight) print_measure("OffersInFlight", (double)m.sum_offers_in_flight / m.samples_offers_in_flight);
123
  if (m.samples_queue_delay) print_measure("QueueDelay", m.sum_queue_delay / m.samples_queue_delay);
124 4c6ae584 Csaba Kiraly
125 c4a89b29 Csaba Kiraly
  if (timerisset(&print_tstart)) {
126 d94fc181 Csaba Kiraly
    print_measure("OfferRate", (double) m.offers / tdiff_sec(&tnow, &print_tstart));
127
    print_measure("AcceptRate", (double) m.accepts / tdiff_sec(&tnow, &print_tstart));
128 c4a89b29 Csaba Kiraly
  }
129 d94fc181 Csaba Kiraly
  if (m.offers) print_measure("OfferAcceptRatio", (double)m.accepts / m.offers);
130 c7a8895d Csaba Kiraly
}
131
132 0bc20f3a Csaba Kiraly
bool print_every()
133 c7a8895d Csaba Kiraly
{
134 0bc20f3a Csaba Kiraly
  static bool startup = true;
135 c7a8895d Csaba Kiraly
  struct timeval tnow;
136
137
  gettimeofday(&tnow, NULL);
138 0bc20f3a Csaba Kiraly
  if (startup) {
139 d94fc181 Csaba Kiraly
    if (!timerisset(&tstart)) {
140
      timeradd(&tnow, &tstartdiff, &tstart);
141
      print_tstart = tstart;
142 0bc20f3a Csaba Kiraly
    }
143 d94fc181 Csaba Kiraly
    if (timercmp(&tnow, &tstart, <)) {
144 0bc20f3a Csaba Kiraly
      return false;
145
    } else {
146
      startup = false;
147
    }
148
  }
149
150 c7a8895d Csaba Kiraly
  if (!timerisset(&tnext)) {
151 d94fc181 Csaba Kiraly
    timeradd(&tstart, &print_tdiff, &tnext);
152 c7a8895d Csaba Kiraly
  }
153
  if (!timercmp(&tnow, &tnext, <)) {
154
    print_measures();
155 d94fc181 Csaba Kiraly
    clean_measures();
156
    print_tstart = tnext;
157 c7a8895d Csaba Kiraly
    timeradd(&tnext, &print_tdiff, &tnext);
158
  }
159 0bc20f3a Csaba Kiraly
  return true;
160 c7a8895d Csaba Kiraly
}
161
162 473a00b3 Csaba Kiraly
/*
163
 * Register duplicate arrival
164
*/
165
void reg_chunk_duplicate()
166
{
167 0bc20f3a Csaba Kiraly
  if (!print_every()) return;
168 c887bcd8 Csaba Kiraly
169 d94fc181 Csaba Kiraly
  m.duplicates++;
170 473a00b3 Csaba Kiraly
}
171
172
/*
173
 * Register playout/loss of a chunk before playout
174
*/
175
void reg_chunk_playout(int id, bool b, uint64_t timestamp)
176
{
177 3fb3b834 Csaba Kiraly
  struct timeval tnow;
178
179 0bc20f3a Csaba Kiraly
  if (!print_every()) return;
180 c7a8895d Csaba Kiraly
181 d94fc181 Csaba Kiraly
  m.played += b ? 1 : 0;
182
  m.chunks++;
183 3fb3b834 Csaba Kiraly
  gettimeofday(&tnow, NULL);
184 d94fc181 Csaba Kiraly
  m.sum_reorder_delay += (tnow.tv_usec + tnow.tv_sec * 1000000ULL) - timestamp;
185 473a00b3 Csaba Kiraly
}
186
187
/*
188
 * Register actual neghbourhood size
189
*/
190
void reg_neigh_size(int s)
191
{
192 0bc20f3a Csaba Kiraly
  if (!print_every()) return;
193 c887bcd8 Csaba Kiraly
194 d94fc181 Csaba Kiraly
  m.sum_neighsize += s;
195
  m.samples_neighsize++;
196 473a00b3 Csaba Kiraly
}
197
198
/*
199
 * Register chunk receive event
200
*/
201 14e5c21e Csaba Kiraly
void reg_chunk_receive(int id, uint64_t timestamp, int hopcount, bool old, bool dup)
202 473a00b3 Csaba Kiraly
{
203 3fb3b834 Csaba Kiraly
  struct timeval tnow;
204
205 6095e14c Csaba Kiraly
  if (!print_every()) return;
206 3bbf8272 Csaba Kiraly
207 dfcfa0fe Csaba Kiraly
  if (old) {
208 d94fc181 Csaba Kiraly
    m.chunks_received_old++;
209 dfcfa0fe Csaba Kiraly
  } else {
210
    if (dup) { //duplicate detection works only for in-time arrival
211 d94fc181 Csaba Kiraly
      m.chunks_received_dup++;
212 dfcfa0fe Csaba Kiraly
    } else {
213 d94fc181 Csaba Kiraly
      m.chunks_received_nodup++;
214
      m.sum_hopcount += hopcount;
215 dfcfa0fe Csaba Kiraly
      gettimeofday(&tnow, NULL);
216 d94fc181 Csaba Kiraly
      m.sum_receive_delay += (tnow.tv_usec + tnow.tv_sec * 1000000ULL) - timestamp;
217 dfcfa0fe Csaba Kiraly
    }
218
  }
219 473a00b3 Csaba Kiraly
}
220
221
/*
222
 * Register chunk send event
223
*/
224
void reg_chunk_send(int id)
225
{
226 6095e14c Csaba Kiraly
  if (!print_every()) return;
227 3bbf8272 Csaba Kiraly
228 d94fc181 Csaba Kiraly
  m.chunks_sent++;
229 473a00b3 Csaba Kiraly
}
230
231
/*
232
 * Register chunk accept evemt
233
*/
234
void reg_offer_accept(bool b)
235
{
236 4fec81f0 Csaba Kiraly
  if (!print_every()) return;
237
238 d94fc181 Csaba Kiraly
  m.offers++;
239
  if (b) m.accepts++;
240 473a00b3 Csaba Kiraly
}
241
242
/*
243 74bf94f2 Csaba Kiraly
 * messages sent (bytes vounted at message content level)
244
*/
245
void reg_message_send(int size, uint8_t type)
246
{
247
  if (!print_every()) return;
248
249 d94fc181 Csaba Kiraly
  m.bytes_sent += size;
250
  m.msgs_sent++;
251 74bf94f2 Csaba Kiraly
252
  switch (type) {
253
   case MSG_TYPE_CHUNK:
254 d94fc181 Csaba Kiraly
     m.bytes_sent_chunk+= size;
255
     m.msgs_sent_chunk++;
256 74bf94f2 Csaba Kiraly
     break;
257
   case MSG_TYPE_SIGNALLING:
258 d94fc181 Csaba Kiraly
     m.bytes_sent_sign+= size;
259
     m.msgs_sent_sign++;
260 74bf94f2 Csaba Kiraly
     break;
261
   case MSG_TYPE_TOPOLOGY:
262
   case MSG_TYPE_TMAN:
263 d94fc181 Csaba Kiraly
     m.bytes_sent_topo+= size;
264
     m.msgs_sent_topo++;
265 74bf94f2 Csaba Kiraly
     break;
266
   default:
267
     break;
268
  }
269
}
270
271
/*
272
 * messages sent (bytes vounted at message content level)
273
*/
274
void reg_message_recv(int size, uint8_t type)
275
{
276
  if (!print_every()) return;
277
278 d94fc181 Csaba Kiraly
  m.bytes_recvd += size;
279
  m.msgs_recvd++;
280 74bf94f2 Csaba Kiraly
281
  switch (type) {
282
   case MSG_TYPE_CHUNK:
283 d94fc181 Csaba Kiraly
     m.bytes_recvd_chunk+= size;
284
     m.msgs_recvd_chunk++;
285 74bf94f2 Csaba Kiraly
     break;
286
   case MSG_TYPE_SIGNALLING:
287 d94fc181 Csaba Kiraly
     m.bytes_recvd_sign+= size;
288
     m.msgs_recvd_sign++;
289 74bf94f2 Csaba Kiraly
     break;
290
   case MSG_TYPE_TOPOLOGY:
291
   case MSG_TYPE_TMAN:
292 d94fc181 Csaba Kiraly
     m.bytes_recvd_topo+= size;
293
     m.msgs_recvd_topo++;
294 74bf94f2 Csaba Kiraly
     break;
295
   default:
296
     break;
297
  }
298
}
299
300
/*
301 4c6ae584 Csaba Kiraly
 * Register the number of offers in flight
302
*/
303
void reg_offers_in_flight(int running_offers_threads)
304
{
305
  if (!print_every()) return;
306
307 d94fc181 Csaba Kiraly
  m.sum_offers_in_flight += running_offers_threads;
308
  m.samples_offers_in_flight++;
309 4c6ae584 Csaba Kiraly
}
310
311
/*
312
 * Register the sample for RTT
313
*/
314
void reg_queue_delay(double last_queue_delay)
315
{
316
  if (!print_every()) return;
317
318 d94fc181 Csaba Kiraly
  m.sum_queue_delay += last_queue_delay;
319
  m.samples_queue_delay++;
320 4c6ae584 Csaba Kiraly
}
321
322
/*
323 473a00b3 Csaba Kiraly
 * Initialize peer level measurements
324
*/
325
void init_measures()
326
{
327
}
328
329
/*
330 a8a31ce0 Csaba Kiraly
 * End peer level measurements
331
*/
332
void end_measures()
333
{
334
  print_measures();
335
}
336
337
/*
338 473a00b3 Csaba Kiraly
 * Initialize p2p measurements towards a peer
339
*/
340
void add_measures(struct nodeID *id)
341
{
342
}
343
344
/*
345
 * Delete p2p measurements towards a peer
346
*/
347
void delete_measures(struct nodeID *id)
348
{
349
}