]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ferret/lib/producer/histogram_init.c
update
[l4.git] / l4 / pkg / ferret / lib / producer / histogram_init.c
1 /**
2  * \file   ferret/lib/sensor/histogram_init.c
3  * \brief  Histogram init functions.
4  *
5  * \date   17/11/2005
6  * \author Martin Pohlack  <mp26@os.inf.tu-dresden.de>
7  */
8 /*
9  * (c) 2005-2009 Technische Universität Dresden
10  * This file is part of TUD:OS and distributed under the terms of the
11  * GNU General Public License 2.
12  * Please see the COPYING-GPL-2 file for details.
13  */
14 #include <l4/ferret/types.h>
15 #include <l4/ferret/sensors/common.h>
16 #include <l4/ferret/sensors/histogram.h>
17 #include <l4/ferret/sensors/histogram_init.h>
18
19 #include <stdio.h>
20 #include <sys/types.h>
21
22 #include <l4/log/l4log.h>
23
24 static void ferret_histo_init_head(ferret_histo_header_t *head, ferret_time_t low,
25                                    ferret_time_t high, unsigned int bins);
26 static void ferret_histo_init_head(ferret_histo_header_t *head, ferret_time_t low,
27                                    ferret_time_t high, unsigned int bins)
28 {
29     head->low  = low;
30     head->high = high;
31     head->bins = bins;
32     head->size = high - low;
33
34     head->underflow = 0;
35     head->overflow  = 0;
36     head->val_min   = FERRET_TIME_MAX;
37     head->val_max   = FERRET_TIME_MIN;
38     head->val_sum   = 0;
39     head->val_count = 0;
40 }
41
42 int ferret_histo_init(ferret_histo_t * histo, const char * config)
43 {
44     ferret_time_t low, high;
45     unsigned int bins;
46     int ret, i;
47
48     // "<low value>:<high value>:<bins>"
49     ret = sscanf(config, "%lld:%lld:%u", &low, &high, &bins);
50     //LOG("Config found: %lld, %lld, %u", low, high, bins);
51
52     if (ret != 3 || bins < 1 || low >= high)
53     {
54         return -1;
55         //LOG("Warning: config string not recognized or flawed: %s!", config);
56     }
57     else
58     {
59         ferret_histo_init_head(&histo->head, low, high, bins);
60         for (i = 0; i < bins; ++i)
61             histo->data[i] = 0;
62     }
63     return 0;
64 }
65
66 int ferret_histo64_init(ferret_histo64_t * histo, const char * config)
67 {
68     ferret_time_t low, high;
69     unsigned int bins;
70     int ret, i;
71
72     // "<low value>:<high value>:<bins>"
73     ret = sscanf(config, "%lld:%lld:%u", &low, &high, &bins);
74     //LOG("Config found: %lld, %lld, %u", low, high, bins);
75
76     if (ret != 3 || bins < 1 || low >= high)
77     {
78         return -1;
79         //LOG("Warning: config string not recognized or flawed: %s!", config);
80     }
81     else
82     {
83         ferret_histo_init_head(&histo->head, low, high, bins);
84         for (i = 0; i < bins; ++i)
85             histo->data[i] = 0;
86     }
87     return 0;
88 }
89
90 // fixme: all of the sensor type functions should be stored in a
91 //        function table
92 ssize_t ferret_histo_size_config(const char * config)
93 {
94     ferret_time_t low, high;
95     unsigned int bins;
96     int ret;
97     ferret_histo_t temp;
98
99     ret = sscanf(config, "%lld:%lld:%u", &low, &high, &bins);
100     //LOG("Config found: %lld, %lld, %u", low, high, bins);
101
102     if (ret != 3 || bins < 1 || low >= high)
103     {
104         //LOG("Warning: config string not recognized or flawed: %s!", config);
105         return -1;
106     }
107
108     return sizeof(ferret_histo_t) + sizeof(temp.data[0]) * bins;
109 }
110
111 ssize_t ferret_histo64_size_config(const char * config)
112 {
113     ferret_time_t low, high;
114     unsigned int bins;
115     int ret;
116     ferret_histo64_t temp;
117
118     ret = sscanf(config, "%lld:%lld:%u", &low, &high, &bins);
119     //LOG("Config found: %lld, %lld, %u", low, high, bins);
120
121     if (ret != 3 || bins < 1 || low >= high)
122     {
123         //LOG("Warning: config string not recognized or flawed: %s!", config);
124         return -1;
125     }
126
127     return sizeof(ferret_histo64_t) + sizeof(temp.data[0]) * bins;
128 }
129
130 ssize_t ferret_histo_size(const ferret_histo_t * histo)
131 {
132     return sizeof(ferret_histo_t) + sizeof(histo->data[0]) * histo->head.bins;
133 }
134
135 ssize_t ferret_histo64_size(const ferret_histo64_t * histo)
136 {
137     return sizeof(ferret_histo64_t) + sizeof(histo->data[0]) * histo->head.bins;
138 }