introduced a StatisticsData Object to hold the aggregated stats data provided by...
[senf.git] / senf / Utils / Statistics.cci
index 1f109db..a9e51eb 100644 (file)
@@ -1,6 +1,6 @@
 // $Id$
 //
-// Copyright (C) 2008 
+// Copyright (C) 2008
 // Fraunhofer Institute for Open Communication Systems (FOKUS)
 // Competence Center NETwork research (NET), St. Augustin, GERMANY
 //     Stefan Bund <g0dil@berlios.de>
@@ -30,9 +30,9 @@
 #include "Range.hh"
 
 #define prefix_ inline
-///////////////////////////////cci.p///////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
-///////////////////////////////////////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 // senf::StatisticsBase::Transform
 
 prefix_ senf::StatisticsBase::Transform::result_type
@@ -42,31 +42,33 @@ senf::StatisticsBase::Transform::operator()(first_argument_type i)
     return i.second;
 }
 
-///////////////////////////////////////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 // senf::StatisticsBase::OutputEntry
 
 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry()
-    : n(), min(), avg(), max() 
+    : n(), min(), avg(), max(), dev()
 {
     initDir();
 }
 
 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(unsigned n_)
-    : n(n_), min(), avg(), max() 
+    : n(n_), min(), avg(), max(), dev()
 {
     initDir();
 }
 
 prefix_ senf::StatisticsBase::OutputEntry::OutputEntry(const OutputEntry& other)
-    : n(other.n), min(other.min), avg(other.avg), max(other.max) 
+    : n(other.n), min(other.min), avg(other.avg), max(other.max), dev(other.dev)
 {
     initDir();
 }
 
 prefix_ void senf::StatisticsBase::OutputEntry::initDir()
 {
-    dir.add("list", senf::membind(&OutputEntry::consoleList, this))
-        .doc("List all known connected targets. This list might not be complete.");
+    namespace fty = senf::console::factory;
+
+    dir.add("list", fty::Command(&OutputEntry::consoleList, this)
+            .doc("List all known connected targets. This list might not be complete.") );
 }
 
 prefix_ senf::StatisticsBase::OutputEntry &
@@ -76,6 +78,7 @@ senf::StatisticsBase::OutputEntry::operator=(const OutputEntry& other)
     min = other.min;
     avg = other.avg;
     max = other.max;
+    dev = other.dev;
     return *this;
 }
 
@@ -87,11 +90,11 @@ prefix_ void senf::StatisticsBase::OutputEntry::consoleList(std::ostream & os)
             os << i->label << "\n";
 }
 
-/////////////////////////////////////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 // senf::StatisticsBase
 
 prefix_ senf::StatisticsBase::StatisticsBase()
-    : min_ (0.0f), avg_ (0.0f), max_ (0.0f), maxQueueLen_ (0u)
+    : min_ (0.0f), avg_ (0.0f), max_ (0.0f), dev_ (0.0f), maxQueueLen_ (0u)
 {}
 
 prefix_ senf::StatisticsBase::~StatisticsBase()
@@ -120,6 +123,12 @@ prefix_ float senf::StatisticsBase::max()
     return max_;
 }
 
+prefix_ float senf::StatisticsBase::dev()
+    const
+{
+    return dev_;
+}
+
 prefix_ unsigned senf::StatisticsBase::rank()
     const
 {
@@ -137,11 +146,11 @@ prefix_ std::string senf::StatisticsBase::path()
     return v_path();
 }
 
-///////////////////////////////////////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 // senf::Collector
 
 prefix_ senf::Collector::Collector(StatisticsBase * owner, unsigned rank)
-    : rank_ (rank), i_ (0u), accMin_ (FLT_MAX), accAvg_ (0.0f), accMax_ (-FLT_MAX),
+    : rank_ (rank), i_ (0u), accMin_ (FLT_MAX), accSum_ (0.0f), accSumSq_ (0.0f), accMax_ (-FLT_MAX),
       owner_ (owner)
 {}
 
@@ -158,26 +167,38 @@ senf::Collector::output(unsigned n)
     return StatisticsBase::OutputProxy<Collector>(this, StatisticsBase::output(n));
 }
 
-///////////////////////////////////////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 // senf::Statistics
 
-prefix_ void senf::Statistics::operator()(float min, float avg, float max)
+prefix_ void senf::Statistics::operator()(unsigned n, float min, float avg, float max,
+                                          float dev)
+{
+    enter(n, min, avg, max, dev);
+}
+
+prefix_ void senf::Statistics::operator()(float min, float avg, float max, float dev)
+{
+    enter(1, min, avg, max, dev);
+}
+
+prefix_ void senf::Statistics::operator()(StatisticsData const & data)
 {
-    enter(min, avg, max);
+  enter(1, data.min, data.avg, data.max, data.stddev);
 }
 
-prefix_ void senf::Statistics::operator()(float value)
+prefix_ void senf::Statistics::operator()(float value, float dev)
 {
-    enter(value, value, value);
+    enter(1, value, value, value, dev);
 }
 
+
 prefix_ senf::StatisticsBase::OutputProxy<senf::Statistics>
 senf::Statistics::output(unsigned n)
 {
     return StatisticsBase::OutputProxy<Statistics>(this, StatisticsBase::output(n));
 }
 
-///////////////////////////////cci.e///////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 #undef prefix_
 
 \f