2#ifndef CLICK_STATVECTOR_HH
3#define CLICK_STATVECTOR_HH
4#include <click/batchelement.hh>
5#include <click/multithread.hh>
8#include <click/statvector.hh>
17 enum{H_MEDIAN=736,H_AVERAGE,H_DUMP,H_MAX_OBS,H_N_OBS,H_NZ,H_MAX,H_MAX_OBS_VAL};
21 StatVector *fd = (StatVector*)e->
cast(
"StatVector");
22 switch ((intptr_t)thunk) {
26 Vector<T> sums(fd->stats.get_value(0).size(),0);
28 int max_batch_index = -1;
32 for (
unsigned j = 0; j < (unsigned)sums.size(); j++) {
33 for (
unsigned i = 0; i < fd->stats.weight(); i++) {
34 sums[j] += fd->stats.get_value(i)[j];
36 if (sums[j] > max_batch_v) {
37 max_batch_v = sums[j];
45 if ((intptr_t)thunk == H_MAX) {
47 }
else if ((intptr_t)thunk == H_NZ) {
50 return String(max_batch_index);
54 Vector<T> sums(fd->stats.get_value(0).size(),0);
56 for (
unsigned j = 0; j < (unsigned)sums.size(); j++) {
57 for (
unsigned i = 0; i < fd->stats.weight(); i++) {
58 sums[j] += fd->stats.get_value(i)[j];
62 if ((intptr_t)thunk == H_N_OBS)
65 for (
int i = 0; i < sums.size(); i++) {
75 for (
unsigned i = 0; i < fd->stats.weight(); i++) {
76 for (
unsigned j = 0; j < (unsigned)fd->stats.get_value(i).size(); j++) {
77 total += fd->stats.get_value(i)[j] * j;
78 count += fd->stats.get_value(i)[j];
82 return String((
double)total/(
double)count);
88 Vector<T> sums(fd->stats.get_value(0).size(),0);
89 for (
unsigned i = 0; i < fd->stats.weight(); i++) {
90 for (
unsigned j = 0; j < (unsigned)fd->stats.get_value(i).size(); j++) {
91 sums[j] += fd->stats.get_value(i)[j];
92 if (i == fd->stats.weight() - 1 && sums[j] != 0)
93 s << j <<
": " << sums[j] <<
"\n";
113 void add_stat_handler(
Element* e) {
Base class for Click elements.
Definition element.hh:42
void add_read_handler(const String &name, ReadHandlerCallback read_callback, const void *user_data=0, uint32_t flags=0)
Register a read handler named name.
Definition element.cc:2020
virtual void * cast(const char *name)
Attempt to cast the element to a named type.
Definition element.cc:515
@ f_expensive
Read handler is expensive to call.
Definition handler.hh:41
Efficiently build up Strings from pieces.
Definition straccum.hh:28
String take_string()
Return a String object with this StringAccum's contents.
Definition straccum.cc:211
A string of characters.
Definition string.hh:22
Vector template.
Definition vector.hh:111
Click's StringAccum class, used to construct Strings efficiently from pieces.
Click's vector container template.