1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_test_Statistic_hpp
10 #define anna_test_Statistic_hpp
12 #include <anna/core/util/Average.hpp>
13 #include <anna/core/functions.hpp>
14 #include <anna/core/mt/Guard.hpp>
15 #include <anna/core/mt/Mutex.hpp>
16 #include <anna/core/RuntimeException.hpp>
22 class Statistic : public anna::Mutex {
28 a_avgDelay ("AvgDelay"),
32 void initTime () noexcept(false) {
33 if (a_initTime == 0) {
34 Guard guard (this, "Statistic::initTime");
36 a_initTime = anna::functions::millisecond ();
40 Millisecond getInitTime () const { return a_initTime; }
41 int getMessageCounter () const { return a_messageCounter; }
42 int getSuccessCounter () const { return a_successCounter; }
44 void countMessage () { a_messageCounter ++; }
45 void countSuccess () { a_successCounter ++; }
46 int countError () noexcept(false) {
47 Guard guard (this, "Statistic::countError");
48 return ++ a_errorCounter;
50 void resetError () noexcept(false) {
51 if (a_errorCounter > 0) {
52 Guard guard (this, "Statistic::countError");
57 void countDelay (const Millisecond value) noexcept(false) {
58 Guard guard (this, "Statistic::countDelay");
62 const Average <Microsecond>& getAvgDelay () const { return a_avgDelay; }
64 int getMessage () const { return a_messageCounter; }
67 Millisecond a_initTime;
70 Average <Microsecond> a_avgDelay;