The Sparta Modeling Framework
Loading...
Searching...
No Matches
DelayedCollectable.hpp
Go to the documentation of this file.
1// <DelayedCollectable.hpp> -*- C++ -*-
2
10#pragma once
11
12#include <sstream>
13#include <functional>
15#include "sparta/pipeViewer/transaction_structures.hpp"
18
19namespace sparta {
20
21namespace collection
22{
34 template<class DataT>
35 class DelayedCollectable : public Collectable<DataT>
36 {
38
39 struct DurationData
40 {
41 DurationData() {}
42
43 DurationData(const DataT & dat,
44 sparta::Clock::Cycle duration) :
45 data(dat), duration(duration)
46 {}
47
48 DataT data;
49 sparta::Clock::Cycle duration;
50 };
51
52 public:
53
54 // Promote the collect method from Collectable
55 using Collectable<DataT>::collect;
56
67 const std::string& name,
68 const std::string& group,
69 uint32_t index,
70 uint64_t parentid = 0,
71 const std::string & desc = "DelayedCollectable <manual, no desc>") :
72 Collectable<DataT>(parent, name, group, index, desc)
73 {
74 (void) parentid;
75 }
76
86 const std::string& name,
87 const DataT * collected_object,
88 uint64_t parentid = 0,
89 const std::string & desc = "DelayedCollectable <no desc>") :
90 Collectable<DataT>(parent, name, collected_object, parentid, desc)
91 {}
92
101 const std::string& name,
102 uint64_t parentid = 0,
103 const std::string & desc = "DelayedCollectable <manual, no desc>") :
104 DelayedCollectable(parent, name, nullptr, parentid, desc)
105 {
106 // Can't auto collect without setting iterable_object_
108 }
109
119 void collect(const DataT & val, sparta::Clock::Cycle delay)
120 {
121 if(SPARTA_EXPECT_FALSE(isCollected()))
122 {
123 if(delay != 0) {
124 ev_collect_.schedule(val, delay);
125 }
126 else {
128 }
129 }
130 }
131
142 void collectWithDuration(const DataT & val,
143 sparta::Clock::Cycle delay,
144 sparta::Clock::Cycle duration)
145 {
146 if(SPARTA_EXPECT_FALSE(isCollected()))
147 {
148 if(delay != 0) {
149 ev_collect_duration_.preparePayload({val, duration})->schedule(delay);
150 }
151 else {
153 }
154 }
155 }
156
157 private:
158
159 // Called from collectWithDuration where the data needs to be
160 // delivered at a given delayed time, but only for a short
161 // duration.
162 void collectWithDuration_(const DurationData & dur_dat) {
163 Collectable<DataT>::collectWithDuration(dur_dat.data, dur_dat.duration);
164 }
165
166 // For those folks that want collection to appear in the
167 // future
169 &Collectable<DataT>::getEventSet_(), "delayedpipelinecollectable_event",
170 CREATE_SPARTA_HANDLER_WITH_DATA(Collectable<DataT>, collect, DataT)};
171
172 // For those folks that want collection to appear in the
173 // future with a duration
175 &Collectable<DataT>::getEventSet_(), "delayedpipelinecollectable_duration_event",
176 CREATE_SPARTA_HANDLER_WITH_DATA(DelayedCollectable<DataT>,
177 collectWithDuration_, DurationData)};
178
179
180 };
181}//namespace collection
182}//namespace sparta
183
Implementation of the Collectable class that allows a user to collect an object into an pipeViewer pi...
File that defines the EventSet class.
File that defines the PayloadEvent class.
#define SPARTA_EXPECT_FALSE(x)
A macro for hinting to the compiler a particular condition should be considered most likely false.
#define CREATE_SPARTA_HANDLER_WITH_DATA(clname, meth, dataT)
Class to schedule a Scheduleable in the future with a payload, typed on both the data type and the sc...
ScheduleableHandle preparePayload(const DataT &payload)
Prepare a Scheduleable Payload for scheduling either now or later.
Node in a composite tree representing a sparta Tree item.
Definition TreeNode.hpp:205
bool isCollected() const
Determine whether or not this node has collection turned on or off.
Class used to either manually or auto-collect an Annotation String object in a pipeline database.
void setManualCollection()
Do not perform any automatic collection The SchedulingPhase is ignored.
void collect() override final
void collectWithDuration(const DataT &val, sparta::Clock::Cycle duration)
Explicitly collect a value for the given duration.
EventSet & getEventSet_()
Get a reference to the internal event set.
Class used to record data in pipeline collection, but recorded in a delayed fashion.
DelayedCollectable(sparta::TreeNode *parent, const std::string &name, const DataT *collected_object, uint64_t parentid=0, const std::string &desc="DelayedCollectable <no desc>")
Construct the DelayedCollectable.
void collect(const DataT &val, sparta::Clock::Cycle delay)
Explicitly collect a value in the future.
DelayedCollectable(sparta::TreeNode *parent, const std::string &name, const std::string &group, uint32_t index, uint64_t parentid=0, const std::string &desc="DelayedCollectable <manual, no desc>")
Construct the DelayedCollectable, no data object associated, part of a group.
void collectWithDuration(const DataT &val, sparta::Clock::Cycle delay, sparta::Clock::Cycle duration)
Explicitly collect a value in the future.
DelayedCollectable(sparta::TreeNode *parent, const std::string &name, uint64_t parentid=0, const std::string &desc="DelayedCollectable <manual, no desc>")
Construct the DelayedCollectable, no data object associated.
Macros for handling exponential backoff.