14#include "sparta/utils/Utils.hpp"
15#include "sparta/log/MessageSource.hpp"
68template <
typename IterableType, SchedulingPhase collection_phase = SchedulingPhase::Collection,
bool sparse_array_type = false>
72 typedef typename IterableType::size_type size_type;
85 const std::string & name,
86 const std::string & group,
88 const std::string & desc,
89 const IterableType * iterable,
90 const size_type expected_capacity) :
92 iterable_object_(iterable),
93 expected_capacity_(expected_capacity),
95 ev_close_record_(&event_set_, name +
"_pipeline_collectable_close_event",
98 for (size_type i = 0; i < expected_capacity_; ++i)
100 std::stringstream name_str;
101 name_str << name << i;
102 positions_.emplace_back(
new CollectableT(
this, name_str.str(), group, i));
118 const std::string & name,
119 const std::string & group,
120 const uint32_t index,
121 const std::string & desc,
122 const IterableType & iterable,
123 const size_type expected_capacity) :
124 IterableCollector(parent, name, group, index, desc, &iterable, expected_capacity)
136 const std::string & name,
137 const std::string & desc,
138 const IterableType * iterable,
139 const size_type expected_capacity) :
152 const std::string & name,
153 const std::string & desc,
154 const IterableType & iterable,
155 const size_type expected_capacity) :
167 const std::string & name,
168 const IterableType * iterable,
169 const size_type expected_capacity) :
171 iterable, expected_capacity)
184 const std::string & name,
185 const IterableType & iterable,
186 const size_type expected_capacity) :
188 &iterable, expected_capacity)
200 const std::string & name,
201 const size_type expected_capacity) :
203 nullptr, expected_capacity)
213 void collect(
const IterableType * iterable_object)
216 if(
nullptr == iterable_object) {
226 <<
"WARNING! The collected object '"
228 <<
"expected capacity (given at construction) for collection. "
229 <<
"Expected " << expected_capacity_ <<
" but grew to "
230 << iterable_object->size()
231 <<
" This is your first and last warning.";
232 warn_on_size_ =
false;
235 collectImpl_(iterable_object, std::integral_constant<bool, sparse_array_type>());
247 void closeRecord(
const bool & simulation_ending =
false)
override {
248 for (size_type i = 0; i < positions_.size(); ++i) {
249 positions_[i]->closeRecord(simulation_ending);
263 auto_collect_ =
false;
279 iterable_object_ = obj;
285 void collectImpl_(
const IterableType * iterable_object, std::false_type)
288 "Can't collect iterable_object because it's a nullptr! How did we get here?");
289 auto itr = iterable_object->begin();
290 auto eitr = iterable_object->end();
291 for (uint32_t i = 0; i < expected_capacity_; ++i)
294 positions_[i]->collect(*itr);
297 positions_[i]->closeRecord();
305 void collectImpl_(
const IterableType * iterable_object, std::true_type)
308 "Can't collect iterable_object because it's a nullptr! How did we get here?");
310 auto itr = iterable_object->begin();
311 for (uint32_t i = 0; i < expected_capacity_; ++i, ++s)
314 positions_[i]->collect(*itr);
316 positions_[i]->closeRecord();
324 void setCollecting_(
bool collect, Collector * collector)
override
326 PipelineCollector * pipeline_col =
dynamic_cast<PipelineCollector *
>(collector);
332 pipeline_col->addToAutoCollection(
this, collection_phase);
339 const IterableType * iterable_object_;
340 std::vector<std::unique_ptr<CollectableT>> positions_;
341 const size_type expected_capacity_ = 0;
342 bool auto_collect_ =
true;
343 bool warn_on_size_ =
true;
define a CollectableTreeNode type TreeNode.
Implementation of the Collectable class that allows a user to collect an object into an pipeViewer pi...
Class to facilitate pipeline collection operations.
File that defines the phases used in simulation.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
#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)
Set of Events that a unit (or sparta::TreeNode, sparta::Resource) contains and are visible through a ...
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.
void schedule()
Schedule this event with its pre-set delay using the pre-set Clock.
Node in a composite tree representing a sparta Tree item.
std::string getLocation() const override final
An abstract type of TreeNode that has virtual calls to start collection on this node,...
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.
A collector of any iterable type (std::vector, std::list, sparta::Buffer, etc)
void reattach(const IterableType *obj)
Reattach to a new iterable object (used for moves)
void collect(const IterableType *iterable_object)
void setManualCollection()
Do not perform any automatic collection The SchedulingPhase is ignored.
void closeRecord(const bool &simulation_ending=false) override
void scheduleCloseRecord(sparta::Clock::Cycle cycle)
Schedule event to close all records for this iterable type.
IterableCollector(TreeNode *parent, const std::string &name, const std::string &desc, const IterableType &iterable, const size_type expected_capacity)
constructor
IterableCollector(TreeNode *parent, const std::string &name, const IterableType &iterable, const size_type expected_capacity)
constructor with no description
void collect() override
Collect the contents of the associated iterable object.
IterableCollector(TreeNode *parent, const std::string &name, const IterableType *iterable, const size_type expected_capacity)
constructor with no description
IterableCollector(TreeNode *parent, const std::string &name, const std::string &group, const uint32_t index, const std::string &desc, const IterableType *iterable, const size_type expected_capacity)
constructor
IterableCollector(TreeNode *parent, const std::string &name, const std::string &group, const uint32_t index, const std::string &desc, const IterableType &iterable, const size_type expected_capacity)
constructor
void collectWithDuration(sparta::Clock::Cycle duration)
Perform a collection, then close the records in the future.
IterableCollector(TreeNode *parent, const std::string &name, const size_type expected_capacity)
constructor with no iterable object associated
IterableCollector(TreeNode *parent, const std::string &name, const std::string &desc, const IterableType *iterable, const size_type expected_capacity)
constructor
static MessageSource & getGlobalWarn()
Gets the global warning logger. These messages can be picked up by placing a Tap on the sparta::TreeN...
Macros for handling exponential backoff.