The Sparta Modeling Framework
Loading...
Searching...
No Matches
CounterBase.hpp
1// <Counter> -*- C++ -*-
2
3
4#pragma once
5
11
12
13namespace sparta
14{
20 {
21 public:
22
26
30 typedef uint64_t counter_type;
31
101
104
105 public:
106
110
126 const std::string& name,
127 const std::string& group,
128 TreeNode::group_idx_type group_idx,
129 const std::string& desc,
130 CounterBehavior behave,
131 visibility_t visibility) :
132 InstrumentationNode(nullptr,
133 name,
134 group,
135 group_idx,
136 desc,
138 visibility
139 ),
140 behave_(behave)
141 {
142 setExpectedParent_(parent);
143
144 ensureParentIsValid_(parent);
145
146 parent->addChild(this);
147 }
148
149 // Alternate constructor
150 CounterBase(TreeNode* parent,
151 const std::string& name,
152 const std::string& group,
153 TreeNode::group_idx_type group_idx,
154 const std::string& desc,
155 CounterBehavior behave) :
156 CounterBase(parent,
157 name,
158 group,
159 group_idx,
160 desc,
161 behave,
163 {
164 // Initialization handled in delegated constructor
165 }
166
167 // Alternate constructor
168 CounterBase(TreeNode* parent,
169 const std::string& name,
170 const std::string& desc,
171 CounterBehavior behave) :
172 CounterBase(parent,
173 name,
174 TreeNode::GROUP_NAME_NONE,
175 TreeNode::GROUP_IDX_NONE,
176 desc,
177 behave)
178 {
179 // Initialization handled in delegated constructor
180 }
181
185 CounterBase(const CounterBase& rhp) = delete;
186
192 InstrumentationNode(std::move(rhp)),
193 behave_(rhp.behave_)
194 {;}
195
199 virtual ~CounterBase() {}
200
203
207
209 CounterBehavior getBehavior() const { return behave_; }
210
213
217
225 virtual counter_type get() const = 0;
226
230 operator counter_type() const {
231 return get();
232 }
233
240 virtual bool supportsCompression() const {
241 return false;
242 }
243
246
250
251 // Override from TreeNode
252 virtual std::string stringize(bool pretty=false) const = 0;
253
257 static std::string getBehaviorName(CounterBehavior behave) {
258 switch(behave){
259 case COUNT_NORMAL:
260 return "normal";
261 case COUNT_INTEGRAL:
262 return "integral";
263 case COUNT_LATEST:
264 return "current";
265 }
266 throw SpartaException("unknown counter behavior: ") << behave;
267 }
268
271
272 protected:
273
279 virtual void onAddingChild_(TreeNode* child) {
280 (void) child;
281 throw SpartaException("Cannot add children to a CounterBase");
282 }
283
284 private:
285
293 void ensureParentIsValid_(TreeNode* parent);
294
298 const CounterBehavior behave_;
299
300 }; // class CounterBase
301
302} // namespace sparta
Byte order types and byte-swapping routines.
Virtual interface node for simulator instrumentation (e.g. counters, stats, nontifications).
Set of macros for Sparta assertions. Caught by the framework.
Exception class for all of Sparta.
Basic Node framework in sparta device tree composite pattern.
The base class for all Counters.
virtual ~CounterBase()
Destructor.
virtual void onAddingChild_(TreeNode *child)
React to child registration.
virtual counter_type get() const =0
Gets the value of this counter.
static std::string getBehaviorName(CounterBehavior behave)
Returns a string containing the name of the given behavior.
uint64_t counter_type
Counter value type.
virtual bool supportsCompression() const
CounterBase(const CounterBase &rhp)=delete
Copy construction not allowed.
CounterBehavior
Behavior of this counter.
@ COUNT_INTEGRAL
Counter intended to increase each cycle by some variable X.
@ COUNT_LATEST
Counter holds the latest value (from most recent activity) and can increase or decrease at any time.
@ COUNT_NORMAL
Counter counts the number of times something happens like one would expect. This is a weakly monotoni...
virtual std::string stringize(bool pretty=false) const =0
Create a string representation of this node.
CounterBase(CounterBase &&rhp)
Move constructor.
CounterBase(TreeNode *parent, const std::string &name, const std::string &group, TreeNode::group_idx_type group_idx, const std::string &desc, CounterBehavior behave, visibility_t visibility)
CounterBase constructor.
CounterBehavior getBehavior() const
Gets the behavior for this counter specified at construction.
@ TYPE_COUNTER
Counter (of any subclass)
uint32_t visibility_t
Continuous visibility level. Several key points along continum are indicated within Visibility.
static constexpr visibility_t DEFAULT_VISIBILITY
Default node visibility.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
static const group_idx_type GROUP_IDX_NONE
GroupIndex indicating that a node has no group index because it belongs to no group.
Definition TreeNode.hpp:303
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
Definition TreeNode.hpp:314
void addChild(TreeNode *child, bool inherit_phase=true)
Adds a TreeNode to this node as a child.
uint32_t group_idx_type
Index within a group.
Definition TreeNode.hpp:261
void setExpectedParent_(const TreeNode *parent)
Tracks a node as an expected parent without actually adding this node as a child. This is used almost...
Macros for handling exponential backoff.