13#include "sparta/pairs/SpartaKeyPairs.hpp"
14#include "sparta/pevents/PeventTreeNode.hpp"
15#include "sparta/log/MessageSource.hpp"
18#include <boost/algorithm/string.hpp>
20#define PEVENT_COLLECTOR_NOTE "_pevent"
31 template<
typename DataT>
33 public sparta::PairCollector<
34 typename MetaStruct::remove_any_pointer<
38 typedef typename MetaStruct::remove_any_pointer<DataT>::type Data_t;
41 typedef typename Data_t::SpartaPairDefinitionType PairDef_t;
43 using PairCollector<PairDef_t>::getPEventLogVector;
44 using PairCollector<PairDef_t>::turnOn_;
45 using PairCollector<PairDef_t>::turnOff_;
46 using PairCollector<PairDef_t>::collect_;
49 using PairCollector<PairDef_t>::isCollecting;
53 const bool verbosity=
false) :
54 sparta::PairCollector<PairDef_t>(),
56 event_name+PEVENT_COLLECTOR_NOTE+(verbosity ?
"_verbose" :
"")),
57 event_name_(event_name),
59 event_name+PEVENT_COLLECTOR_NOTE,
60 "A collector used to collect pevent data."),
62 f_skew_(std::plus<uint64_t>()),
64 verbosity_(verbosity) {
77 template<
typename... Targs>
79 const Targs &... pos_args) {
81 collect_(obj, pos_args...);
91 void adjustSkew(
const int32_t & skew_amount) {
92 skew_ = std::abs(skew_amount);
93 if(skew_amount >= 0) {
94 f_skew_ = std::plus<uint64_t>();
97 f_skew_ = std::minus<uint64_t>();
109 virtual bool addTap(
const std::string& type,
const std::string& file,
const bool verbose)
override final {
112 std::string lowertype = type;
113 boost::algorithm::to_lower(lowertype);
114 std::string lower_ev_name = event_name_;
115 boost::algorithm::to_lower(lower_ev_name);
116 if(( lowertype == lower_ev_name || lowertype ==
"all") && verbosity_ == verbose) {
118 sparta_assert(running_ ==
false,
"Cannot turnOn a pevent collector for which go() has already been called.");
123 bool is_unique =
true;
124 for(
const auto& existing_tap : taps_) {
125 if(existing_tap->getDestination()->compareStrings(file) &&
126 (existing_tap->getCategoryName() == lowertype
127 || lowertype ==
"all")) {
135 taps_.emplace_back(
new log::Tap(
this, event_name_+PEVENT_COLLECTOR_NOTE, file));
138 taps_[taps_.size() - 1]->detach();
150 virtual void turnOff(
const std::string& type)
override final {
152 if(type == event_name_) {
166 virtual void go() override final {
167 if(taps_.size() > 0) {
174 for(
auto& tap : taps_) {
188 std::stringstream ss;
191 ss <<
"ev=" <<
"\"" << event_name_ <<
"\" ";
194 for(
const auto & pair : getPEventLogVector())
196 ss << pair.first <<
"=" <<
"\"" << pair.second <<
"\" ";
204 message_src_ << ss.str();
209 const std::string event_name_;
215 std::vector<std::unique_ptr<log::Tap > > taps_;
219 std::function<uint64_t(
const uint64_t &,
const uint32_t &)> f_skew_;
222 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 ...
a class that is capable of recording pevents as key value pairs, where a PairDefinition has been defi...
virtual void generateCollectionString_() override final
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 const std::string & eventName() override
Return the ev name.
void collect(const Data_t &obj, const Targs &... pos_args)
Actually collect the object, and write out a pevent. We ovverride the collect method to ensure the th...
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.
Macros for handling exponential backoff.