ANNA Suite  2020b
Multipurpose development suite for Telco applications
Statistic.hpp
Go to the documentation of this file.
1 // ANNA - Anna is Not Nothingness Anymore //
2 // //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
4 // //
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 //
7 
8 
9 #ifndef anna_test_Statistic_hpp
10 #define anna_test_Statistic_hpp
11 
13 #include <anna/core/functions.hpp>
14 #include <anna/core/mt/Guard.hpp>
15 #include <anna/core/mt/Mutex.hpp>
17 
18 namespace test {
19 
20 using namespace anna;
21 
22 class Statistic : public anna::Mutex {
23 public:
24  Statistic () :
25  a_messageCounter (0),
26  a_successCounter (0),
27  a_initTime (0),
28  a_avgDelay ("AvgDelay"),
29  a_errorCounter (0)
30  {}
31 
32  void initTime () noexcept(false) {
33  if (a_initTime == 0) {
34  Guard guard (this, "Statistic::initTime");
35  if (a_initTime == 0)
36  a_initTime = anna::functions::millisecond ();
37  }
38  }
39 
40  Millisecond getInitTime () const { return a_initTime; }
41  int getMessageCounter () const { return a_messageCounter; }
42  int getSuccessCounter () const { return a_successCounter; }
43 
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;
49  }
50  void resetError () noexcept(false) {
51  if (a_errorCounter > 0) {
52  Guard guard (this, "Statistic::countError");
53  a_errorCounter = 0;
54  }
55  }
56 
57  void countDelay (const Millisecond value) noexcept(false) {
58  Guard guard (this, "Statistic::countDelay");
59  a_avgDelay += value;
60  }
61 
62  const Average <Microsecond>& getAvgDelay () const { return a_avgDelay; }
63 
64  int getMessage () const { return a_messageCounter; }
65 
66 private:
67  Millisecond a_initTime;
68  int a_messageCounter;
69  int a_successCounter;
70  Average <Microsecond> a_avgDelay;
71  int a_errorCounter;
72 
73 };
74 
75 }
76 
77 #endif
78 
Definition: Millisecond.hpp:24
Definition: Communicator.hpp:14
Definition: Average.hpp:24
static Millisecond millisecond()
Definition: functions.hpp:379
Definition: Statistic.hpp:22
void initTime() noexcept(false)
Definition: Statistic.hpp:32
int getMessage() const
Definition: Statistic.hpp:64
int countError() noexcept(false)
Definition: Statistic.hpp:46
int getMessageCounter() const
Definition: Statistic.hpp:41
const Average< Microsecond > & getAvgDelay() const
Definition: Statistic.hpp:62
int getSuccessCounter() const
Definition: Statistic.hpp:42
void countDelay(const Millisecond value) noexcept(false)
Definition: Statistic.hpp:57
void countSuccess()
Definition: Statistic.hpp:45
Definition: app.hpp:12
Definition: Guard.hpp:35
void countMessage()
Definition: Statistic.hpp:44
Definition: Mutex.hpp:41
Statistic()
Definition: Statistic.hpp:24
void resetError() noexcept(false)
Definition: Statistic.hpp:50
Millisecond getInitTime() const
Definition: Statistic.hpp:40