Nebula
Loading...
Searching...
No Matches
debugcounter.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "core/refcounted.h"
13#include "util/stringatom.h"
14#include "util/ringbuffer.h"
16
17//------------------------------------------------------------------------------
18#if NEBULA_ENABLE_PROFILING
19#define _declare_counter(counter) Ptr<Debug::DebugCounter> counter;
20#define _setup_counter(counter) counter = Debug::DebugCounter::Create(); counter->Setup(Util::StringAtom(#counter));
21#define _setup_grouped_counter(counter, group) counter = Debug::DebugCounter::Create(); counter->Setup(Util::StringAtom(#counter), group);
22#define _discard_counter(counter) counter->Discard(); counter = nullptr;
23#define _begin_counter(counter) counter->Begin();
24#define _begin_counter_noreset(counter) counter->Begin(false);
25#define _reset_counter(counter) counter->Reset();
26#define _incr_counter(counter, val) counter->Incr(val);
27#define _decr_counter(counter, val) counter->Decr(val);
28#define _set_counter(counter, val) counter->Set(val);
29#define _end_counter(counter) counter->End();
30#else
31#define _declare_counter(counter)
32#define _setup_counter(counter)
33#define _setup_grouped_counter(counter, group)
34#define _discard_counter(counter)
35#define _begin_counter(counter)
36#define _begin_counter_noreset()
37#define _reset_counter(counter)
38#define _incr_counter(counter, val)
39#define _decr_counter(counter, val)
40#define _set_counter(counter, val)
41#define _end_counter(counter)
42#endif
43//------------------------------------------------------------------------------
44namespace Debug
45{
47{
49public:
53 virtual ~DebugCounter();
54
56 void Setup(const Util::StringAtom& name, const Util::StringAtom& group = Util::StringAtom("Ungrouped"));
58 void Discard();
60 bool IsValid() const;
61
63 void Begin(bool reset=true);
65 void Reset();
67 void Incr(int amount);
69 void Decr(int amount);
71 void Set(int val);
73 void End();
74
76 const Util::StringAtom& GetName() const;
78 const Util::StringAtom& GetGroup() const;
80 int GetSample() const;
83
84private:
88 int value;
90};
91
92//------------------------------------------------------------------------------
95inline bool
97{
98 return this->name.IsValid();
99}
100
101//------------------------------------------------------------------------------
104inline void
106{
107 if (reset)
108 {
109 this->value = 0;
110 }
111}
112
113//------------------------------------------------------------------------------
116inline void
118{
119 this->value = 0;
120}
121
122//------------------------------------------------------------------------------
125inline void
127{
128 this->value += amount;
129}
130
131//------------------------------------------------------------------------------
134inline void
136{
137 this->value -= amount;
138}
139
140//------------------------------------------------------------------------------
143inline void
145{
146 this->value = val;
147}
148
149//------------------------------------------------------------------------------
152inline void
154{
155 this->critSect.Enter();
156 this->history.Add(this->value);
157 this->critSect.Leave();
158}
159
160//------------------------------------------------------------------------------
163inline const Util::StringAtom&
165{
166 return this->name;
167}
168
169//------------------------------------------------------------------------------
172inline const Util::StringAtom&
174{
175 return this->group;
176}
177
178} // namespace Debug
179//------------------------------------------------------------------------------
The common base class of Nebula.
Definition refcounted.h:38
A debug counter for counting events.
Definition debugcounter.h:47
DebugCounter()
constructor
Definition debugcounter.cc:19
void End()
end counting, write current value to history
Definition debugcounter.h:153
void Decr(int amount)
decrement the counter by a specific value
Definition debugcounter.h:135
void Incr(int amount)
increment the counter by a specific value
Definition debugcounter.h:126
void Reset()
manually reset the counter to zero
Definition debugcounter.h:117
__DeclareClass(DebugCounter)
void Setup(const Util::StringAtom &name, const Util::StringAtom &group=Util::StringAtom("Ungrouped"))
setup the counter
Definition debugcounter.cc:41
Threading::CriticalSection critSect
Definition debugcounter.h:85
void Discard()
discard the counter
Definition debugcounter.cc:60
Util::Array< int > GetHistory() const
get the counter's history
Definition debugcounter.cc:92
void Set(int val)
set the counter directly
Definition debugcounter.h:144
virtual ~DebugCounter()
destructor
Definition debugcounter.cc:29
Util::RingBuffer< int > history
Definition debugcounter.h:89
bool IsValid() const
return true if object has been setup
Definition debugcounter.h:96
void Begin(bool reset=true)
begin counting, optionally reset the counter
Definition debugcounter.h:105
Util::StringAtom name
Definition debugcounter.h:86
const Util::StringAtom & GetGroup() const
get the timer group
Definition debugcounter.h:173
Util::StringAtom group
Definition debugcounter.h:87
const Util::StringAtom & GetName() const
get the counter's name
Definition debugcounter.h:164
int value
Definition debugcounter.h:88
int GetSample() const
get the most recent sample
Definition debugcounter.cc:76
Critical section objects are used to protect a portion of code from parallel execution.
Nebula's dynamic array class.
Definition array.h:60
A ring buffer stores up to a maximum number of elements in a circular fashion.
Definition ringbuffer.h:21
void Add(const TYPE &elm)
add an element to the ring buffer
Definition ringbuffer.h:316
A StringAtom.
Definition stringatom.h:22
bool IsValid() const
return true if valid (contains a non-empty string)
Definition stringatom.h:353
Definition corepagehandler.cc:13