13#include "sparta/pairs/SpartaKeyPairs.hpp"
14#include "sparta/pevents/PeventTreeNode.hpp"
15#include "sparta/log/MessageSource.hpp"
16#include <boost/algorithm/string.hpp>
18#define PEVENT_COLLECTOR_NOTE "_pevent"
59 template <
class CollectedEntityType>
64 using PairCollector<CollectedEntityType>::getPEventLogVector;
65 using PairCollector<CollectedEntityType>::turnOn_;
66 using PairCollector<CollectedEntityType>::turnOff_;
67 using PairCollector<CollectedEntityType>::collect_;
70 using PairCollector<CollectedEntityType>::isCollecting;
72 PairCollector<CollectedEntityType>(),
74 event_name_(event_name),
75 message_src_(
this, event_name+PEVENT_COLLECTOR_NOTE,
"A collector used to collect pevent data."),
77 f_skew_(std::plus<uint64_t>()),
92 template<
typename... Targs>
93 void collect(
const typename CollectedEntityType::TypeCollected& obj,
94 const Targs&... pos_args)
98 collect_(obj, pos_args...);
110 void adjustSkew(
const int32_t & skew_amount) {
111 skew_ = std::abs(skew_amount);
112 if(skew_amount >= 0) {
113 f_skew_ = std::plus<uint64_t>();
115 f_skew_ = std::minus<uint64_t>();
127 virtual bool addTap(
const std::string& type,
const std::string& file,
const bool verbose)
override final
130 std::string lowertype = type;
131 boost::algorithm::to_lower(lowertype);
132 std::string lower_ev_name = event_name_;
133 boost::algorithm::to_lower(lower_ev_name);
134 if(( lowertype == lower_ev_name || lowertype ==
"all") && verbosity_ == verbose)
137 sparta_assert(running_ ==
false,
"Cannot turnOn a pevent collector for which go() has already been called.");
142 bool is_unique =
true;
143 for(
const auto& existing_tap : taps_)
145 if(existing_tap->getDestination()->compareStrings(file) &&
146 (existing_tap->getCategoryName() == lowertype || lowertype ==
"all"))
156 taps_.emplace_back(
new log::Tap(
this, event_name_+PEVENT_COLLECTOR_NOTE, file));
159 taps_[taps_.size() - 1]->detach();
174 virtual void turnOff(
const std::string& type)
override final
177 if(type == event_name_)
180 if(taps_.size() == 0)
192 virtual void go() override final
202 for(
auto& tap : taps_)
215 std::stringstream ss;
217 ss <<
"ev=" <<
"\"" << event_name_ <<
"\" ";
220 for(
const auto & pair : getPEventLogVector())
222 ss << pair.first <<
"=" <<
"\"" << pair.second <<
"\" ";
229 message_src_ << ss.str();
232 const std::string event_name_;
236 std::vector<std::unique_ptr<log::Tap > > taps_;
239 std::function<uint64_t(
const uint64_t &,
const uint32_t &)> f_skew_;
242 bool running_ =
false;
File that defines the Clock class.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
A representation of simulated time.
Cycle currentCycle() const
Get the current cycle (uses current tick from the Scheduler)
Node in a composite tree representing a sparta Tree item.
Message source object associated with a sparta TreeNode through which messages can be sent.
Logging Tap. Attach to a TreeNode to intercept logging messages from any NotificationSource nodes in ...
Class that is capable of recording pevents as key value pairs, where a PairDefinition has been define...
virtual void generateCollectionString_() override
Override the generateCollectionString_() of the bases PairCollector, In this method,...
virtual void go() override final
This method should be called on all pevent collectors when the trigger either manually fires to start...
virtual bool addTap(const std::string &type, const std::string &file, const bool verbose) override final
Mark this pevent with a tap to output the pevent's data to a file.
void collect(const typename CollectedEntityType::TypeCollected &obj, const Targs &... pos_args)
Actually collect the object, and write out a pevent. We ovverride the collect method to ensure the th...
virtual const std::string & eventName() override
Return the ev name.
Macros for handling exponential backoff.