The Sparta Modeling Framework
Loading...
Searching...
No Matches
PeventController.hpp
1#pragma once
2
4#include "sparta/pevents/PeventCollector.hpp"
5#include "sparta/simulation/TreeNodePrivateAttorney.hpp"
6namespace sparta{
7namespace pevents{
18 {
24 struct CachedTapData
25 {
26 CachedTapData(const std::string& tree_dest,
27 const std::string& f,
28 const std::string& type,
29 bool is_verbose) :
30 file(f),
31 event_type(type),
32 treenode_dest(tree_dest),
33 verbose(is_verbose)
34 {}
35 std::string file;
36 std::string event_type;
37 std::string treenode_dest;
38 bool verbose;
39 };
40 public:
41
46 void cacheTap(const std::string& file, const std::string& type, const bool verbose,
47 const std::string& node="ROOT")
48 {
49 tap_info_.emplace_back(CachedTapData(node, file, type, verbose));
50 }
51
57 {
58 for(auto& tap_data : tap_info_)
59 {
60 uint32_t count_added = 0;
61 if(tap_data.treenode_dest != "ROOT")
62 {
63 std::vector<TreeNode*> results;
64 root->getSearchScope()->findChildren(tap_data.treenode_dest, results);
65 for(TreeNode* node : results) {
66 addTap_(node, tap_data.event_type, tap_data.file, tap_data.verbose, count_added);
67 }
68 }
69 else {
70 addTap_(root, tap_data.event_type, tap_data.file, tap_data.verbose, count_added);
71 }
72 // assert that we at least turned on one pevent other wise the user may be bummed out
73 // when their run actually finishes.
74 if (count_added == 0)
75 {
76 std::stringstream s;
77 s << "No pevents were actually enabled for the pevent " << tap_data.event_type << ". You likely supplied an invalid event type to the command line. ";
78 throw SpartaException(s.str());
79 }
80
81
82
83 }
84 }
85
87 void printEventNames(std::ostream& o, TreeNode* root)
88 {
89 o << "<TreeNode Path> : Event Name" << std::endl;
90 printEventNames_(o, root);
91
92 }
93
94 private:
96 void printEventNames_(std::ostream& o, TreeNode* root)
97 {
98 for(TreeNode* node : TreeNodePrivateAttorney::getAllChildren(root))
99 {
100 PeventCollectorTreeNode* c_node = dynamic_cast<PeventCollectorTreeNode*>(node);
101 if (c_node)
102 {
103 o << c_node->stringize() << " : " << c_node->eventName() << std::endl;
104 }
105 printEventNames_(o, node);
106 }
107 }
108
109 // Add a tap to every collector below root recursively, where the pevent type is the same.
110 bool addTap_(TreeNode* root, const std::string& type, const std::string& file, const bool verbose,
111 uint32_t& count_added)
112 {
113 PeventCollectorTreeNode* c_node = dynamic_cast<PeventCollectorTreeNode*>(root);
114 if(c_node)
115 {
116 if(c_node->addTap(type, file, verbose))
117 {
118 count_added = count_added + 1; // We successfully added a tap.
119 }
120 }
121 for(TreeNode* node : TreeNodePrivateAttorney::getAllChildren(root))
122 {
123 addTap_(node, type, file, verbose, count_added);
124 }
125
126 return true;
127 }
128 std::vector<CachedTapData> tap_info_;
129 };
130
131}// namespace pevents
132}// namspace sparta
133
Basic Node framework in sparta device tree composite pattern.
TreeNode which represents the root ("top") of a device tree.
GlobalTreeNode * getSearchScope()
Gets the search node "parent" of this root node which is suitable for performing searches that includ...
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:205
uint32_t findChildren(const std::string &pattern, std::vector< TreeNode * > &results, std::vector< std::vector< std::string > > &replacements)
Finds all children starting at this node with a given pattern relative to this node by matching names...
Simple class for recursively adding taps to pevents. There is probably a more efficient way than each...
void printEventNames(std::ostream &o, TreeNode *root)
Print out a nice listing of the pevents that we have in the model.
void cacheTap(const std::string &file, const std::string &type, const bool verbose, const std::string &node="ROOT")
Add knowledge of a tap that will need to be created later, right now we are only parsing the command ...
void finalize(RootTreeNode *root)
we are done parsing the command line, and simulation is setup, propagate the tap information throug t...
Macros for handling exponential backoff.