Statistics
| Branch: | Revision:

streamers / measures.c @ a5c0b447

History | View | Annotate | Download (4.43 KB)

1
#include <mon.h>
2
#include <ml.h>
3

    
4
#include "dbg.h"
5
#include <net_helper.h>
6

    
7
static const char* channel = "OfferStreamer2";
8

    
9
typedef struct nodeID {
10
        socketID_handle addr;
11
        int connID;        // connection associated to this node, -1 if myself
12
        int refcnt;
13
        //a quick and dirty static vector for measures TODO: make it dinamic
14
        MonHandler mhs[20];
15
        int n_mhs;
16
} nodeID;
17

    
18
static MonHandler chunk_dup, chunk_playout, neigh_size;
19

    
20
void add_measure(MonHandler *mh, MeasurementId id, MeasurementCapabilities mc, MonParameterValue rate, const char *pubname, enum stat_types st[], int length, SocketId dst, MsgType mt)
21
{
22
        *mh = monCreateMeasure(id, mc);
23
        monSetParameter (*mh, P_PUBLISHING_RATE, rate);
24
        monPublishStatisticalType(*mh, pubname, channel, st , length, NULL);
25
        monActivateMeasure(*mh, dst, mt);
26
}
27

    
28
void reg_chunk_duplicate()
29
{
30
        if (!chunk_dup) {
31
                enum stat_types st[] = {SUM};
32
                add_measure(&chunk_dup, GENERIC, 0, 120, "ChunkDuplicates", st, sizeof(st)/sizeof(enum stat_types), NULL, MSG_TYPE_ANY);
33
        }
34
        monNewSample(chunk_dup, 1);
35
}
36

    
37
void reg_chunk_playout(bool b)
38
{
39
        if (!chunk_playout) {
40
                enum stat_types st[] = {AVG, SUM};
41
                add_measure(&chunk_playout, GENERIC, 0, 120, "ChunksPlayed", st, sizeof(st)/sizeof(enum stat_types), NULL, MSG_TYPE_ANY);
42
        }
43
        monNewSample(chunk_playout, b);
44
}
45

    
46
void reg_neigh_size(int s)
47
{
48
        if (!neigh_size) {
49
                enum stat_types st[] = {LAST};
50
                add_measure(&neigh_size, GENERIC, 0, 120, "NeighSize", st, sizeof(st)/sizeof(enum stat_types), NULL, MSG_TYPE_ANY);
51
        }
52
        monNewSample(neigh_size, s);
53
}
54

    
55
void add_measures(struct nodeID *id)
56
{
57
        // Add measures
58
        int j = 0;
59
        enum stat_types stavg[] = {AVG, WIN_AVG};
60
        enum stat_types stsum[] = {SUM};
61

    
62
        dprintf("adding measures to %s\n",node_addr(id));
63

    
64
        /* HopCount */
65
       add_measure(&id->mhs[j++], HOPCOUNT, TXRXUNI | PACKET | IN_BAND, 600, "HopCount", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);
66

    
67
        /* Round Trip Time */
68
       add_measure(&id->mhs[j++], RTT, TXRXBI | PACKET | IN_BAND, 60, "RoundTripDelay", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_SIGNALLING);
69

    
70
        /* Loss */
71
       add_measure(&id->mhs[j++], LOSS, TXRXUNI | PACKET | IN_BAND, 60, "LossRate", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);
72

    
73
        // Cumulative Traffic
74
       //add_measure(&id->mhs[j++], BYTE, RXONLY | PACKET | IN_BAND, 120, "RxBytes", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_ANY);
75
       //add_measure(&id->mhs[j++], BYTE, TXONLY | PACKET | IN_BAND, 120, "TxBytes", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_ANY);
76
       add_measure(&id->mhs[j++], BYTE, RXONLY | PACKET | IN_BAND, 120, "RxBytesChunk", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);
77
       add_measure(&id->mhs[j++], BYTE, TXONLY | PACKET | IN_BAND, 120, "TxBytesChunk", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);
78

    
79
        // Traffic
80
       add_measure(&id->mhs[j++], BULK_TRANSFER, RXONLY | PACKET | TIMER_BASED, 120, "RxBytesChunkPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);
81
       add_measure(&id->mhs[j++], BULK_TRANSFER, TXONLY | PACKET | TIMER_BASED, 120, "TxBytesChunkPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);
82
       add_measure(&id->mhs[j++], BULK_TRANSFER, RXONLY | PACKET | TIMER_BASED, 120, "RxBytesSigPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_SIGNALLING);
83
       add_measure(&id->mhs[j++], BULK_TRANSFER, TXONLY | PACKET | TIMER_BASED, 120, "TxBytesSigPSec", stavg, sizeof(stavg)/sizeof(enum stat_types), id->addr, MSG_TYPE_SIGNALLING);
84

    
85
        // Chunks
86
       add_measure(&id->mhs[j++], COUNTER, RXONLY | DATA | IN_BAND, 120, "RxChunks", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);
87
       add_measure(&id->mhs[j++], COUNTER, TXONLY | DATA | IN_BAND, 120, "TxChunks", stsum, sizeof(stsum)/sizeof(enum stat_types), id->addr, MSG_TYPE_CHUNK);
88

    
89
        // for static must not be more then 10 or whatever size is in net_helper-ml.c
90
        id->n_mhs = j;
91
}
92

    
93
void delete_measures(struct nodeID *id)
94
{
95
        int j;
96
        dprintf("deleting measures from %s\n",node_addr(id));
97
        for(j = 0; j < id->n_mhs; j++) {
98
                monDestroyMeasure(id->mhs[j]);
99
        }
100
}
101

    
102
double get_measure(struct nodeID *id, int j, enum stat_types st)
103
{
104
        return monRetrieveResult(id->mhs[j], st);
105
}
106

    
107
//in seconds
108
double get_rtt(struct nodeID *id){
109
        return get_measure(id, 1, WIN_AVG);
110
}
111

    
112
double get_lossrate(struct nodeID *id){
113
        return get_measure(id, 2, WIN_AVG);
114
}