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
147 class CounterBehaviorDetailed
148 {
149 public:
156 CounterBehaviorDetailed(behavior, {})
157 {}
158
165 const InstrumentationNode::MetadataPairs & meta_data) :
166 behavior_(behavior),
167 meta_data_(meta_data)
168 {}
171 operator CounterBehavior() const { return behavior_; }
174 const InstrumentationNode::MetadataPairs & getMetadata() const {
175 return meta_data_;
176 }
177
178 private:
179 const CounterBehavior behavior_;
180 const InstrumentationNode::MetadataPairs meta_data_;
181 };
182
186
201 CounterBase(TreeNode* parent,
202 const std::string& name,
203 const std::string& group,
204 TreeNode::group_idx_type group_idx,
205 const std::string& desc,
206 CounterBehaviorDetailed behave,
207 visibility_t visibility) :
208 InstrumentationNode(nullptr,
209 name,
210 group,
211 group_idx,
212 desc,
214 visibility
215 ),
216 behave_(behave)
217 {
218 setExpectedParent_(parent);
219
220 ensureParentIsValid_(parent);
221
222 parent->addChild(this);
223
224 // Copy over the meta data to the InstrumentationNode.
225 meta_data_.insert(meta_data_.begin(),
226 behave.getMetadata().begin(),
227 behave.getMetadata().end());
228
229 }
230
231 // Alternate constructor
232 CounterBase(TreeNode* parent,
233 const std::string& name,
234 const std::string& group,
235 TreeNode::group_idx_type group_idx,
236 const std::string& desc,
237 CounterBehaviorDetailed behave) :
238 CounterBase(parent,
239 name,
240 group,
241 group_idx,
242 desc,
243 behave,
245 {
246 // Initialization handled in delegated constructor
247 }
248
249 // Alternate constructor
250 CounterBase(TreeNode* parent,
251 const std::string& name,
252 const std::string& desc,
253 CounterBehaviorDetailed behave) :
254 CounterBase(parent,
255 name,
258 desc,
259 behave)
260 {
261 // Initialization handled in delegated constructor
262 }
263
267 CounterBase(const CounterBase& rhp) = delete;
268
273 CounterBase(CounterBase&& rhp) :
274 InstrumentationNode(std::move(rhp)),
275 behave_(rhp.behave_)
276 {;}
277
281 virtual ~CounterBase() {}
282
285
291 CounterBehavior getBehavior() const { return behave_; }
292
295
299
307 virtual counter_type get() const = 0;
308
312 operator counter_type() const {
313 return get();
314 }
315
322 virtual bool supportsCompression() const {
323 return false;
324 }
325
328
333 // Override from TreeNode
334 virtual std::string stringize(bool pretty=false) const = 0;
335
339 static std::string getBehaviorName(CounterBehaviorDetailed behave) {
340 switch(behave){
341 case COUNT_NORMAL:
342 return "normal";
343 case COUNT_INTEGRAL:
344 return "integral";
345 case COUNT_LATEST:
346 return "current";
347 }
348 throw SpartaException("unknown counter behavior: ") << behave;
349 }
350
353
354 protected:
355
361 virtual void onAddingChild_(TreeNode* child) {
362 (void) child;
363 throw SpartaException("Cannot add children to a CounterBase");
364 }
365
366 private:
367
375 void ensureParentIsValid_(TreeNode* parent);
376
380 const CounterBehaviorDetailed behave_;
381
382 }; // class CounterBase
383
384} // 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.
Wrapper class to add meta information to a counter definition.
CounterBehaviorDetailed(CounterBehavior behavior)
Construct a CounterBehaviorDetailed without meta data.
const InstrumentationNode::MetadataPairs & getMetadata() const
Get the meta data provided by the user.
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.
virtual bool supportsCompression() const
CounterBase(TreeNode *parent, const std::string &name, const std::string &group, TreeNode::group_idx_type group_idx, const std::string &desc, CounterBehaviorDetailed behave, visibility_t visibility)
CounterBase constructor.
static std::string getBehaviorName(CounterBehaviorDetailed behave)
Returns a string containing the name of the given behavior.
uint64_t counter_type
Counter value type.
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.
CounterBehavior getBehavior() const
Gets the behavior for this counter specified at construction.
InstrumentationNode()=delete
Not default-constructable.
@ TYPE_COUNTER
Counter (of any subclass)
static constexpr visibility_t DEFAULT_VISIBILITY
Default node visibility.
uint32_t visibility_t
Continuous visibility level. Several key points along continum are indicated within Visibility.
MetadataPairs meta_data_
Add any arbitrary metadata as strings to this object. Used to add extra information to statistics rep...
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:204
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:302
static constexpr char GROUP_NAME_NONE[]
Group name indicating that a node belongs to no group.
Definition TreeNode.hpp:313
TreeNode()=delete
Not default-constructable.
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:260
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.