2 * \file ferret/lib/sensor/histogram_init.c
3 * \brief Histogram init functions.
6 * \author Martin Pohlack <mp26@os.inf.tu-dresden.de>
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.
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>
20 #include <sys/types.h>
22 #include <l4/log/l4log.h>
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)
32 head->size = high - low;
36 head->val_min = FERRET_TIME_MAX;
37 head->val_max = FERRET_TIME_MIN;
42 int ferret_histo_init(ferret_histo_t * histo, const char * config)
44 ferret_time_t low, high;
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);
52 if (ret != 3 || bins < 1 || low >= high)
55 //LOG("Warning: config string not recognized or flawed: %s!", config);
59 ferret_histo_init_head(&histo->head, low, high, bins);
60 for (i = 0; i < bins; ++i)
66 int ferret_histo64_init(ferret_histo64_t * histo, const char * config)
68 ferret_time_t low, high;
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);
76 if (ret != 3 || bins < 1 || low >= high)
79 //LOG("Warning: config string not recognized or flawed: %s!", config);
83 ferret_histo_init_head(&histo->head, low, high, bins);
84 for (i = 0; i < bins; ++i)
90 // fixme: all of the sensor type functions should be stored in a
92 ssize_t ferret_histo_size_config(const char * config)
94 ferret_time_t low, high;
99 ret = sscanf(config, "%lld:%lld:%u", &low, &high, &bins);
100 //LOG("Config found: %lld, %lld, %u", low, high, bins);
102 if (ret != 3 || bins < 1 || low >= high)
104 //LOG("Warning: config string not recognized or flawed: %s!", config);
108 return sizeof(ferret_histo_t) + sizeof(temp.data[0]) * bins;
111 ssize_t ferret_histo64_size_config(const char * config)
113 ferret_time_t low, high;
116 ferret_histo64_t temp;
118 ret = sscanf(config, "%lld:%lld:%u", &low, &high, &bins);
119 //LOG("Config found: %lld, %lld, %u", low, high, bins);
121 if (ret != 3 || bins < 1 || low >= high)
123 //LOG("Warning: config string not recognized or flawed: %s!", config);
127 return sizeof(ferret_histo64_t) + sizeof(temp.data[0]) * bins;
130 ssize_t ferret_histo_size(const ferret_histo_t * histo)
132 return sizeof(ferret_histo_t) + sizeof(histo->data[0]) * histo->head.bins;
135 ssize_t ferret_histo64_size(const ferret_histo64_t * histo)
137 return sizeof(ferret_histo64_t) + sizeof(histo->data[0]) * histo->head.bins;