Statistics
| Branch: | Revision:

streamers / measures.c @ 4fec81f0

History | View | Annotate | Download (9.88 KB)

1
/*
2
 *  Copyright (c) 2010 Csaba Kiraly
3
 *
4
 *  This is free software; see gpl-3.0.txt
5
 */
6
#include <stdio.h>
7
#include <stdint.h>
8
#include <string.h>
9
#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
#include <sys/time.h>
17

    
18
#include "measures.h"
19
#include "grapes_msg_types.h"
20

    
21
struct timeval print_tdiff = {3600, 0};
22
struct timeval tstartdiff = {60, 0};
23
static struct timeval tstart;
24
static struct timeval print_tstart;
25
static struct timeval tnext;
26

    
27
struct measures {
28
  int duplicates;
29
  int chunks;
30
  int played;
31
  uint64_t sum_reorder_delay;
32

    
33
  int chunks_received_dup, chunks_received_nodup, chunks_received_old;
34
  int sum_hopcount;
35
  uint64_t sum_receive_delay;
36

    
37
  int chunks_sent;
38

    
39
  uint64_t sum_neighsize;
40
  int samples_neighsize;
41

    
42
  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

    
45
  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

    
48
  uint64_t sum_offers_in_flight;
49
  int samples_offers_in_flight;
50
  double sum_queue_delay;
51
  int samples_queue_delay;
52

    
53
  int offers;
54
  int accepts;
55
};
56

    
57
static struct measures m;
58

    
59
void clean_measures()
60
{
61
  memset(&m, 0, sizeof(m));
62
}
63

    
64
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
  fprintf(stderr,"abouttopublish,,,,%s,%f,,,%f\n", name, value, tdiff_sec(&tnext, &tstart));
74
}
75

    
76
void print_measures()
77
{
78
  struct timeval tnow;
79

    
80
  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

    
86
  gettimeofday(&tnow, NULL);
87
  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

    
94
  if (timerisset(&print_tstart)) {
95
    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
  }
119

    
120
  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

    
122
  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

    
125
  if (timerisset(&print_tstart)) {
126
    print_measure("OfferRate", (double) m.offers / tdiff_sec(&tnow, &print_tstart));
127
    print_measure("AcceptRate", (double) m.accepts / tdiff_sec(&tnow, &print_tstart));
128
  }
129
  if (m.offers) print_measure("OfferAcceptRatio", (double)m.accepts / m.offers);
130
}
131

    
132
bool print_every()
133
{
134
  static bool startup = true;
135
  struct timeval tnow;
136

    
137
  gettimeofday(&tnow, NULL);
138
  if (startup) {
139
    if (!timerisset(&tstart)) {
140
      timeradd(&tnow, &tstartdiff, &tstart);
141
      print_tstart = tstart;
142
    }
143
    if (timercmp(&tnow, &tstart, <)) {
144
      return false;
145
    } else {
146
      startup = false;
147
    }
148
  }
149

    
150
  if (!timerisset(&tnext)) {
151
    timeradd(&tstart, &print_tdiff, &tnext);
152
  }
153
  if (!timercmp(&tnow, &tnext, <)) {
154
    print_measures();
155
    clean_measures();
156
    print_tstart = tnext;
157
    timeradd(&tnext, &print_tdiff, &tnext);
158
  }
159
  return true;
160
}
161

    
162
/*
163
 * Register duplicate arrival
164
*/
165
void reg_chunk_duplicate()
166
{
167
  if (!print_every()) return;
168

    
169
  m.duplicates++;
170
}
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
  struct timeval tnow;
178

    
179
  if (!print_every()) return;
180

    
181
  m.played += b ? 1 : 0;
182
  m.chunks++;
183
  gettimeofday(&tnow, NULL);
184
  m.sum_reorder_delay += (tnow.tv_usec + tnow.tv_sec * 1000000ULL) - timestamp;
185
}
186

    
187
/*
188
 * Register actual neghbourhood size
189
*/
190
void reg_neigh_size(int s)
191
{
192
  if (!print_every()) return;
193

    
194
  m.sum_neighsize += s;
195
  m.samples_neighsize++;
196
}
197

    
198
/*
199
 * Register chunk receive event
200
*/
201
void reg_chunk_receive(int id, uint64_t timestamp, int hopcount, bool old, bool dup)
202
{
203
  struct timeval tnow;
204

    
205
  if (!print_every()) return;
206

    
207
  if (old) {
208
    m.chunks_received_old++;
209
  } else {
210
    if (dup) { //duplicate detection works only for in-time arrival
211
      m.chunks_received_dup++;
212
    } else {
213
      m.chunks_received_nodup++;
214
      m.sum_hopcount += hopcount;
215
      gettimeofday(&tnow, NULL);
216
      m.sum_receive_delay += (tnow.tv_usec + tnow.tv_sec * 1000000ULL) - timestamp;
217
    }
218
  }
219
}
220

    
221
/*
222
 * Register chunk send event
223
*/
224
void reg_chunk_send(int id)
225
{
226
  if (!print_every()) return;
227

    
228
  m.chunks_sent++;
229
}
230

    
231
/*
232
 * Register chunk accept evemt
233
*/
234
void reg_offer_accept(bool b)
235
{
236
  if (!print_every()) return;
237

    
238
  m.offers++;
239
  if (b) m.accepts++;
240
}
241

    
242
/*
243
 * 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
  m.bytes_sent += size;
250
  m.msgs_sent++;
251

    
252
  switch (type) {
253
   case MSG_TYPE_CHUNK:
254
     m.bytes_sent_chunk+= size;
255
     m.msgs_sent_chunk++;
256
     break;
257
   case MSG_TYPE_SIGNALLING:
258
     m.bytes_sent_sign+= size;
259
     m.msgs_sent_sign++;
260
     break;
261
   case MSG_TYPE_TOPOLOGY:
262
   case MSG_TYPE_TMAN:
263
     m.bytes_sent_topo+= size;
264
     m.msgs_sent_topo++;
265
     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
  m.bytes_recvd += size;
279
  m.msgs_recvd++;
280

    
281
  switch (type) {
282
   case MSG_TYPE_CHUNK:
283
     m.bytes_recvd_chunk+= size;
284
     m.msgs_recvd_chunk++;
285
     break;
286
   case MSG_TYPE_SIGNALLING:
287
     m.bytes_recvd_sign+= size;
288
     m.msgs_recvd_sign++;
289
     break;
290
   case MSG_TYPE_TOPOLOGY:
291
   case MSG_TYPE_TMAN:
292
     m.bytes_recvd_topo+= size;
293
     m.msgs_recvd_topo++;
294
     break;
295
   default:
296
     break;
297
  }
298
}
299

    
300
/*
301
 * 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
  m.sum_offers_in_flight += running_offers_threads;
308
  m.samples_offers_in_flight++;
309
}
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
  m.sum_queue_delay += last_queue_delay;
319
  m.samples_queue_delay++;
320
}
321

    
322
/*
323
 * Initialize peer level measurements
324
*/
325
void init_measures()
326
{
327
}
328

    
329
/*
330
 * End peer level measurements
331
*/
332
void end_measures()
333
{
334
  print_measures();
335
}
336

    
337
/*
338
 * 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
}