Statistics
| Branch: | Revision:

streamers / measures.c @ 7155c8d9

History | View | Annotate | Download (4.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 <math.h>
9
#ifndef NAN        //NAN is missing in some old math.h versions
10
#define NAN            (0.0/0.0)
11
#endif
12
#ifndef INFINITY
13
#define INFINITY       (1.0/0.0)
14
#endif
15
#include <sys/time.h>
16

    
17
#include "measures.h"
18

    
19
static struct timeval print_tdiff = {3600, 0};
20
static struct timeval print_tstartdiff = {60, 0};
21
static struct timeval print_tstart;
22

    
23
static int duplicates = 0;
24
static int chunks = 0;
25
static int played = 0;
26
static uint64_t sum_reorder_delay = 0;
27

    
28
static int chunks_received_dup = 0, chunks_received_nodup = 0, chunks_received_old = 0;
29
static int sum_hopcount = 0;
30
static uint64_t sum_receive_delay = 0;
31

    
32
static int chunks_sent = 0;
33

    
34
static int neighsize = 0;
35

    
36
double tdiff_sec(const struct timeval *a, const struct timeval *b)
37
{
38
  struct timeval tdiff;
39
  timersub(a, b, &tdiff);
40
  return tdiff.tv_sec + tdiff.tv_usec / 1000000.0;
41
}
42

    
43
void print_measure(const char *name, double value)
44
{
45
  fprintf(stderr,"abouttopublish,,,,%s,%f,,,\n", name, value);
46
}
47

    
48
void print_measures()
49
{
50
  struct timeval tnow;
51

    
52
  if (chunks) print_measure("PlayoutRatio", (double)played / chunks);
53
  if (chunks) print_measure("ReorderDelay(ok&lost)", (double)sum_reorder_delay / 1e6 / chunks);
54
  print_measure("NeighSize", (double)neighsize);
55
  if (chunks_received_nodup) print_measure("OverlayDistance(intime&nodup)", (double)sum_hopcount / chunks_received_nodup);
56
  if (chunks_received_nodup) print_measure("ReceiveDelay(intime&nodup)", (double)sum_receive_delay / 1e6 / chunks_received_nodup);
57

    
58
  gettimeofday(&tnow, NULL);
59
  if (timerisset(&print_tstart)) print_measure("ChunkRate", (double) chunks / tdiff_sec(&tnow, &print_tstart));
60
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(all)", (double) (chunks_received_old + chunks_received_nodup + chunks_received_dup)  / tdiff_sec(&tnow, &print_tstart));
61
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(old)", (double) chunks_received_old / tdiff_sec(&tnow, &print_tstart));
62
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(intime&nodup)", (double) chunks_received_nodup / tdiff_sec(&tnow, &print_tstart));
63
  if (timerisset(&print_tstart)) print_measure("ChunkReceiveRate(intime&dup)", (double) chunks_received_dup / tdiff_sec(&tnow, &print_tstart));
64
  if (timerisset(&print_tstart)) print_measure("ChunkSendRate", (double) chunks_sent / tdiff_sec(&tnow, &print_tstart));
65

    
66
  if (chunks_received_old + chunks_received_nodup + chunks_received_dup) print_measure("ReceiveRatio(intime&nodup-vs-all)", (double)chunks_received_nodup / (chunks_received_old + chunks_received_nodup + chunks_received_dup));
67
}
68

    
69
bool print_every()
70
{
71
  static struct timeval tnext;
72
  static bool startup = true;
73
  struct timeval tnow;
74

    
75
  gettimeofday(&tnow, NULL);
76
  if (startup) {
77
    if (!timerisset(&print_tstart)) {
78
      timeradd(&tnow, &print_tstartdiff, &print_tstart);
79
    }
80
    if (timercmp(&tnow, &print_tstart, <)) {
81
      return false;
82
    } else {
83
      startup = false;
84
    }
85
  }
86

    
87
  if (!timerisset(&tnext)) {
88
    timeradd(&print_tstart, &print_tdiff, &tnext);
89
  }
90
  if (!timercmp(&tnow, &tnext, <)) {
91
    print_measures();
92
    timeradd(&tnext, &print_tdiff, &tnext);
93
  }
94
  return true;
95
}
96

    
97
/*
98
 * Register duplicate arrival
99
*/
100
void reg_chunk_duplicate()
101
{
102
  if (!print_every()) return;
103

    
104
  duplicates++;
105
}
106

    
107
/*
108
 * Register playout/loss of a chunk before playout
109
*/
110
void reg_chunk_playout(int id, bool b, uint64_t timestamp)
111
{
112
  struct timeval tnow;
113

    
114
  if (!print_every()) return;
115

    
116
  played += b ? 1 : 0;
117
  chunks++;
118
  gettimeofday(&tnow, NULL);
119
  sum_reorder_delay += (tnow.tv_usec + tnow.tv_sec * 1000000ULL) - timestamp;
120
}
121

    
122
/*
123
 * Register actual neghbourhood size
124
*/
125
void reg_neigh_size(int s)
126
{
127
  if (!print_every()) return;
128

    
129
  neighsize = s;
130
}
131

    
132
/*
133
 * Register chunk receive event
134
*/
135
void reg_chunk_receive(int id, uint64_t timestamp, int hopcount, bool old, bool dup)
136
{
137
  struct timeval tnow;
138

    
139
  if (!print_every()) return;
140

    
141
  if (old) {
142
    chunks_received_old++;
143
  } else {
144
    if (dup) { //duplicate detection works only for in-time arrival
145
      chunks_received_dup++;
146
    } else {
147
      chunks_received_nodup++;
148
      sum_hopcount += hopcount;
149
      gettimeofday(&tnow, NULL);
150
      sum_receive_delay += (tnow.tv_usec + tnow.tv_sec * 1000000ULL) - timestamp;
151
    }
152
  }
153
}
154

    
155
/*
156
 * Register chunk send event
157
*/
158
void reg_chunk_send(int id)
159
{
160
  if (!print_every()) return;
161

    
162
  chunks_sent++;
163
}
164

    
165
/*
166
 * Register chunk accept evemt
167
*/
168
void reg_offer_accept(bool b)
169
{
170
  static int offers = 0;
171
  static int accepts = 0;
172

    
173
  offers++;
174
  if (b) accepts++;
175
}
176

    
177
/*
178
 * Initialize peer level measurements
179
*/
180
void init_measures()
181
{
182
}
183

    
184
/*
185
 * End peer level measurements
186
*/
187
void end_measures()
188
{
189
  print_measures();
190
}
191

    
192
/*
193
 * Initialize p2p measurements towards a peer
194
*/
195
void add_measures(struct nodeID *id)
196
{
197
}
198

    
199
/*
200
 * Delete p2p measurements towards a peer
201
*/
202
void delete_measures(struct nodeID *id)
203
{
204
}