X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=senf%2FUtils%2FStatistics.hh;h=b4cf0bfc00f2f13393b30d359cb76fe20d791b21;hb=c6fb7bc1210f26501d95064eb8e6399a881f884e;hp=bc3b2818e51562097d3bb035db6575235cafb538;hpb=26610f603ebdd465307b9621f532c1fe19fd5571;p=senf.git diff --git a/senf/Utils/Statistics.hh b/senf/Utils/Statistics.hh index bc3b281..b4cf0bf 100644 --- a/senf/Utils/Statistics.hh +++ b/senf/Utils/Statistics.hh @@ -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 @@ -47,7 +47,7 @@ namespace senf { /** \defgroup senf_statistics Statistics The statistics functionality has two parts: - + \li the senf::Statistics class \li statistics sources @@ -61,10 +61,10 @@ namespace senf { class Collector; class Statistics; - + /** \brief Internal: Generic Statistics collection */ class StatisticsBase - { + { typedef std::map Children; struct Transform { @@ -111,7 +111,7 @@ namespace senf { // Function object struct Collector { - void operator()(float min, float avg, float max) + void operator()(float min, float avg, float max, float dev) { ... } }; \endcode @@ -125,7 +125,7 @@ namespace senf { template Owner & connect(Target & target, std::string label="") const; ///< Connect externally managed target - template Owner & connect(std::auto_ptr target, + template Owner & connect(std::auto_ptr target, std::string label="") const; ///< Connect internally managed target Owner & noconnect() const; ///< Don't connect the output @@ -136,7 +136,7 @@ namespace senf { private: #endif OutputProxy(Owner * owner, OutputEntry * entry); - template + template OutputProxy(Owner * owner, OutputProxy const & other); private: @@ -145,7 +145,7 @@ namespace senf { template friend class OutputProxy; }; - + /////////////////////////////////////////////////////////////////////////// ///\name Accessing the current value ///\{ @@ -153,6 +153,7 @@ namespace senf { float min() const; ///< Last min value entered float avg() const; ///< Last avg value entered float max() const; ///< Last max value entered + float dev() const; ///< Last dev value entered virtual unsigned rank() const; ///< Return collectors rank value /**< \returns number of basic values collected into each new @@ -168,7 +169,7 @@ namespace senf { /**< This member will return a reference to the collector collecting \a rank values. \param[in] rank Number of values the requested - collector collects into each combined value. + collector collects into each combined value. \throws InvalidRankException if \a rank is not a valid registered rank value. */ CollectorRange collectors(); ///< List all child collectors @@ -186,7 +187,7 @@ namespace senf { Statistics & base(); ///< Get base statistics object /**< Returns the base statistics object. If this is a child collector, this will return the outermost - statistics object, otherwise it will return + statistics object, otherwise it will return \c *this. */ std::string path() const; ///< Get the path to this collector @@ -227,7 +228,7 @@ namespace senf { protected: StatisticsBase(); virtual ~StatisticsBase(); - void enter(float min, float avg, float max); + void enter(float min, float avg, float max, float dev); private: virtual Statistics & v_base() = 0; @@ -239,15 +240,17 @@ namespace senf { float min_; float avg_; float max_; + float dev_; Children children_; - + struct QueueEntry { float min; float avg; float max; - QueueEntry() : min(), avg(), max() {} - QueueEntry(float min_, float avg_, float max_) - : min(min_), avg(avg_), max(max_) {} + float dev; + QueueEntry() : min(), avg(), max(), dev() {} + QueueEntry(float min_, float avg_, float max_, float dev_) + : min(min_), avg(avg_), max(max_), dev(dev_) {} }; typedef std::deque Queue; Queue queue_; @@ -264,7 +267,7 @@ namespace senf { struct Target : public TargetBase { boost::scoped_ptr target_; - Target(std::auto_ptr target, std::string const & label) + Target(std::auto_ptr target, std::string const & label) : TargetBase (label), target_ (target.release()) {} explicit Target(std::string const & label) : TargetBase (label), target_ (0) {} @@ -282,8 +285,9 @@ namespace senf { float min; float avg; float max; + float dev; - boost::signal signal; + boost::signal signal; boost::ptr_vector targets_; senf::console::ScopedDirectory<> dir; @@ -333,7 +337,7 @@ namespace senf { .collect(10u) // seconds .collect(60u) // minutes .collect(60u); // hours - + packetStats[10u].collect(100u); // 100 seconds rateAnalyzer.startStatistics(senf::ClockService::milliseconds(100u)); @@ -378,8 +382,8 @@ namespace senf { statslog.route(); \endcode - We use a StatisticsLogger to send the log messages to the senf::StatisticsStream log - stream. The stream, area an level to send the statistics log messages to may be configured + We use a StatisticsLogger to send the %log messages to the senf::StatisticsStream %log + stream. The stream, area an level to send the statistics %log messages to may be configured using template arguments to StatisticsLogger. It is also possible to skip sending the output to any target or send one output to several @@ -406,7 +410,7 @@ namespace senf { \see senf::StatisticsBase::OutputProxy for the output proxy (connect) interface \ingroup senf_statistics */ - class Statistics + class Statistics : public StatisticsBase, boost::noncopyable { public: @@ -416,7 +420,7 @@ namespace senf { Statistics(); - void operator()(float min, float avg, float max); + void operator()(float min, float avg, float max, float dev=0.0f); ///< Enter new data /**< This member must be called whenever a new data value is available. It is important to call this member \e @@ -429,9 +433,11 @@ namespace senf { \param[in] min minimal data value since last call \param[in] avg average data value since last call - \param[in] max maximal data values since last call */ + \param[in] max maximal data values since last call + \param[in] dev standard deviation of avg value */ - void operator()(float value); ///< Same as enter() with \a min == \a avg == \a max + void operator()(float value, float dev=0.0f); + ///< Same as enter() with \a min == \a avg == \a max /**< Provided so a Statistics instance can be directly used as a signal target. */ @@ -457,20 +463,21 @@ namespace senf { class Collector : public StatisticsBase { public: - virtual unsigned rank() const; + virtual unsigned rank() const; StatisticsBase::OutputProxy output(unsigned n = 1u); - + private: Collector(StatisticsBase * owner, unsigned rank); - void enter(float min, float avg, float max); + void enter(float min, float avg, float max, float dev); Statistics & v_base(); std::string v_path() const; unsigned rank_; unsigned i_; float accMin_; - float accAvg_; + float accSum_; + float accSumSq_; float accMax_; StatisticsBase * owner_;