Statistics
| Branch: | Revision:

napa-baselibs / monl / result_buffer.h @ 507372bb

History | View | Annotate | Download (2.91 KB)

1
/***************************************************************************
2
 *   Copyright (C) 2009 by Robert Birke
3
 *   robert.birke@polito.it
4
 *
5
 * This library is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU Lesser General Public
7
 * License as published by the Free Software Foundation; either
8
 * version 2.1 of the License, or (at your option) any later version.
9

10
 * This library is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
 * Lesser General Public License for more details.
14

15
 * You should have received a copy of the GNU Lesser General Public
16
 * License along with this library; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA 
18
 ***********************************************************************/
19

    
20
#ifndef _RESULT_BUFFER_H_
21
#define _RESULT_BUFFER_H_
22

    
23
#include "ids.h"
24
#include <string.h>
25
#include <string>
26
#include <algorithm>
27
#include <math.h>
28
#include "ml.h"
29
#include "mon.h"
30

    
31
#include "napa_log.h"
32

    
33
class ResultBuffer {
34
private:
35
        class MonMeasure *m;
36
        static const char *stat_suffixes[];
37
        result *circular_buffer;
38
        result *circular_buffer_var;
39
        int size,pos;
40

    
41
        bool new_data;
42
        result last_publish;
43

    
44
        int samples;
45

    
46
        int n_samples;
47
        result sum_win_samples;
48
        result rate_sum_samples;
49

    
50
        result sum_win_var_samples;
51

    
52
        char **originator_name;
53

    
54
        std::string publish_name;
55
        std::string cnl;
56
        const char *default_name;
57
        int name_size;
58
        enum stat_types *publish;
59
        int publish_length;
60

    
61
        void *repo_client;
62

    
63
        int newSampleWin(result r);
64

    
65
public:
66
        result stats[LAST_STAT_TYPE];
67

    
68
        ResultBuffer(int s, const char *pname, char** oname, MonMeasure *ptr_m): size(s), publish(NULL), publish_length(0), new_data(false), m(ptr_m) {
69
                last_publish = 0.0;
70
                circular_buffer = new result[s];
71
                circular_buffer_var = new result[s];
72
                default_name = pname;
73
                originator_name = oname;
74
                publish_name += default_name;
75
                name_size = publish_name.size();
76
                init();
77
        };
78

    
79
        ~ResultBuffer() {
80
                delete[] circular_buffer;
81
                delete[] circular_buffer_var;
82
                if(publish) { delete[] publish;}
83
        };
84

    
85
        int init();
86

    
87
        int setPublishStatisticalType(const char *publishing_name, const char *channel, enum stat_types *st, int length, void *rc) {
88
                publish_name.clear();
89

    
90
                if(publishing_name != NULL)
91
                        publish_name = publishing_name;
92
                else
93
                        publish_name = default_name;
94
                name_size = publish_name.size();
95

    
96
                std::replace(publish_name.begin(), publish_name.end(), ' ', '_');
97

    
98
                if(channel != NULL)
99
                        cnl = channel;
100
                else
101
                        cnl = "";
102

    
103
                if(publish)
104
                        delete[] publish;
105
                publish = new stat_types [length];
106
                memcpy(publish,st, length * sizeof(enum stat_types));
107
                publish_length = length;
108
                repo_client = rc;
109

    
110
                return publishResults();
111
        }
112

    
113
        int publishResults(void);
114
        int resizeBuffer(int s);
115
        int newSample(result r);
116
        void updateStats(void);
117
};
118

    
119
#endif