Statistics
| Branch: | Revision:

streamers / measures.c @ 3bb247c8

History | View | Annotate | Download (9.32 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
  double timespan;
80

    
81
  gettimeofday(&tnow, NULL);
82
  timespan = tdiff_sec(&tnow, &print_tstart);
83

    
84
  if (m.chunks) print_measure("PlayoutRatio", (double)m.played / m.chunks);
85
  if (m.chunks) print_measure("ReorderDelay(ok&lost)", (double)m.sum_reorder_delay / 1e6 / m.chunks);
86
  if (m.samples_neighsize) print_measure("NeighSize", (double)m.sum_neighsize / m.samples_neighsize);
87
  if (m.chunks_received_nodup) print_measure("OverlayDistance(intime&nodup)", (double)m.sum_hopcount / m.chunks_received_nodup);
88
  if (m.chunks_received_nodup) print_measure("ReceiveDelay(intime&nodup)", (double)m.sum_receive_delay / 1e6 / m.chunks_received_nodup);
89

    
90
  if (timerisset(&print_tstart)) print_measure("ChunkRate", (double) m.chunks / timespan);
91
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(all)", (double) (m.chunks_received_old + m.chunks_received_nodup + m.chunks_received_dup)  / timespan);
92
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(old)", (double) m.chunks_received_old / timespan);
93
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(intime&nodup)", (double) m.chunks_received_nodup / timespan);
94
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(intime&dup)", (double) m.chunks_received_dup / timespan);
95
  if (timerisset(&print_tstart)) print_measure("ChunkSendRate", (double) m.chunks_sent / timespan);
96

    
97
  if (timerisset(&print_tstart)) {
98
    print_measure("SendRateMsgs(all)", (double) m.msgs_sent / timespan);
99
    print_measure("SendRateMsgs(chunk)", (double) m.msgs_sent_chunk / timespan);
100
    print_measure("SendRateMsgs(sign)", (double) m.msgs_sent_sign / timespan);
101
    print_measure("SendRateMsgs(topo)", (double) m.msgs_sent_topo / timespan);
102
    print_measure("SendRateMsgs(other)", (double) (m.msgs_sent - m.msgs_sent_chunk - m.msgs_sent_sign - m.msgs_sent_topo) / timespan);
103

    
104
    print_measure("SendRateBytes(all)", (double) m.bytes_sent / timespan);
105
    print_measure("SendRateBytes(chunk)", (double) m.bytes_sent_chunk / timespan);
106
    print_measure("SendRateBytes(sign)", (double) m.bytes_sent_sign / timespan);
107
    print_measure("SendRateBytes(topo)", (double) m.bytes_sent_topo / timespan);
108
    print_measure("SendRateBytes(other)", (double) (m.bytes_sent - m.bytes_sent_chunk - m.bytes_sent_sign - m.bytes_sent_topo) / timespan);
109

    
110
    print_measure("RecvRateMsgs(all)", (double) m.msgs_recvd / timespan);
111
    print_measure("RecvRateMsgs(chunk)", (double) m.msgs_recvd_chunk / timespan);
112
    print_measure("RecvRateMsgs(sign)", (double) m.msgs_recvd_sign / timespan);
113
    print_measure("RecvRateMsgs(topo)", (double) m.msgs_recvd_topo / timespan);
114
    print_measure("RecvRateMsgs(other)", (double) (m.msgs_recvd - m.msgs_recvd_chunk - m.msgs_recvd_sign - m.msgs_recvd_topo) / timespan);
115

    
116
    print_measure("RecvRateBytes(all)", (double) m.bytes_recvd / timespan);
117
    print_measure("RecvRateBytes(chunk)", (double) m.bytes_recvd_chunk / timespan);
118
    print_measure("RecvRateBytes(sign)", (double) m.bytes_recvd_sign / timespan);
119
    print_measure("RecvRateBytes(topo)", (double) m.bytes_recvd_topo / timespan);
120
    print_measure("RecvRateBytes(other)", (double) (m.bytes_recvd - m.bytes_recvd_chunk - m.bytes_recvd_sign - m.bytes_recvd_topo) / timespan);
121
  }
122

    
123
  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));
124

    
125
  if (m.samples_offers_in_flight) print_measure("OffersInFlight", (double)m.sum_offers_in_flight / m.samples_offers_in_flight);
126
  if (m.samples_queue_delay) print_measure("QueueDelay", m.sum_queue_delay / m.samples_queue_delay);
127

    
128
  if (timerisset(&print_tstart)) {
129
    print_measure("OfferRate", (double) m.offers / timespan);
130
    print_measure("AcceptRate", (double) m.accepts / timespan);
131
  }
132
  if (m.offers) print_measure("OfferAcceptRatio", (double)m.accepts / m.offers);
133
}
134

    
135
bool print_every()
136
{
137
  static bool startup = true;
138
  struct timeval tnow;
139

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

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

    
165
/*
166
 * Register duplicate arrival
167
*/
168
void reg_chunk_duplicate()
169
{
170
  if (!print_every()) return;
171

    
172
  m.duplicates++;
173
}
174

    
175
/*
176
 * Register playout/loss of a chunk before playout
177
*/
178
void reg_chunk_playout(int id, bool b, uint64_t timestamp)
179
{
180
  struct timeval tnow;
181

    
182
  if (!print_every()) return;
183

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

    
190
/*
191
 * Register actual neghbourhood size
192
*/
193
void reg_neigh_size(int s)
194
{
195
  if (!print_every()) return;
196

    
197
  m.sum_neighsize += s;
198
  m.samples_neighsize++;
199
}
200

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

    
208
  if (!print_every()) return;
209

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

    
224
/*
225
 * Register chunk send event
226
*/
227
void reg_chunk_send(int id)
228
{
229
  if (!print_every()) return;
230

    
231
  m.chunks_sent++;
232
}
233

    
234
/*
235
 * Register chunk accept evemt
236
*/
237
void reg_offer_accept(bool b)
238
{
239
  if (!print_every()) return;
240

    
241
  m.offers++;
242
  if (b) m.accepts++;
243
}
244

    
245
/*
246
 * messages sent (bytes vounted at message content level)
247
*/
248
void reg_message_send(int size, uint8_t type)
249
{
250
  if (!print_every()) return;
251

    
252
  m.bytes_sent += size;
253
  m.msgs_sent++;
254

    
255
  switch (type) {
256
   case MSG_TYPE_CHUNK:
257
     m.bytes_sent_chunk+= size;
258
     m.msgs_sent_chunk++;
259
     break;
260
   case MSG_TYPE_SIGNALLING:
261
     m.bytes_sent_sign+= size;
262
     m.msgs_sent_sign++;
263
     break;
264
   case MSG_TYPE_TOPOLOGY:
265
   case MSG_TYPE_TMAN:
266
     m.bytes_sent_topo+= size;
267
     m.msgs_sent_topo++;
268
     break;
269
   default:
270
     break;
271
  }
272
}
273

    
274
/*
275
 * messages sent (bytes vounted at message content level)
276
*/
277
void reg_message_recv(int size, uint8_t type)
278
{
279
  if (!print_every()) return;
280

    
281
  m.bytes_recvd += size;
282
  m.msgs_recvd++;
283

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

    
303
/*
304
 * Register the number of offers in flight
305
*/
306
void reg_offers_in_flight(int running_offers_threads)
307
{
308
  if (!print_every()) return;
309

    
310
  m.sum_offers_in_flight += running_offers_threads;
311
  m.samples_offers_in_flight++;
312
}
313

    
314
/*
315
 * Register the sample for RTT
316
*/
317
void reg_queue_delay(double last_queue_delay)
318
{
319
  if (!print_every()) return;
320

    
321
  m.sum_queue_delay += last_queue_delay;
322
  m.samples_queue_delay++;
323
}
324

    
325
/*
326
 * Initialize peer level measurements
327
*/
328
void init_measures()
329
{
330
}
331

    
332
/*
333
 * End peer level measurements
334
*/
335
void end_measures()
336
{
337
  print_measures();
338
}
339

    
340
/*
341
 * Initialize p2p measurements towards a peer
342
*/
343
void add_measures(struct nodeID *id)
344
{
345
}
346

    
347
/*
348
 * Delete p2p measurements towards a peer
349
*/
350
void delete_measures(struct nodeID *id)
351
{
352
}