The Sparta Modeling Framework
Loading...
Searching...
No Matches
AppTriggers.hpp
Go to the documentation of this file.
1// <AppTriggers.hpp> -*- C++ -*-
2
3
9#pragma once
10
11
12#include "sparta/sparta.hpp"
15#include "sparta/trigger/Trigger.hpp"
16#include "sparta/trigger/Triggerable.hpp"
17#include "sparta/pevents/PeventTrigger.hpp"
18#include "sparta/pevents/PeventController.hpp"
20#include "sparta/log/Tap.hpp"
21
22namespace sparta {
23 namespace app {
24
29class PipelineTrigger : public trigger::Triggerable
30{
31public:
32 PipelineTrigger(const std::string& pipeline_collection_path,
33 const std::set<std::string>& pipeline_enabled_node_names,
34 uint64_t pipeline_heartbeat,
35 bool multiple_triggers,
37 pipeline_collection_path_(pipeline_collection_path),
38 pipeline_enabled_node_names_(pipeline_enabled_node_names),
39 pipeline_heartbeat_(pipeline_heartbeat),
40 multiple_triggers_(multiple_triggers),
41 clk_(clk),
42 root_(rtn)
43 {
44 pipeline_collector_.
45 reset(new sparta::collection::PipelineCollector(multiple_triggers_ ? getCollectionPath_() : pipeline_collection_path_,
46 pipeline_heartbeat_,
47 clk_,
48 root_));
49
50 }
51
52 void go() override
53 {
54 sparta_assert(!triggered_, "Why has pipeline trigger been triggered?");
55 triggered_ = true;
56 std::cout << "Pipeline collection started, output to files with prefix '"
57 << pipeline_collector_->getFilePath() << "'" << std::endl;
58 startCollection_();
59
60 if(multiple_triggers_) {
61 std::cout << "#" << num_collections_ << " pipeline collection started" << std::endl;
62 }
63 }
64
65 void stop() override
66 {
67 sparta_assert(triggered_, "Why stop an inactivated trigger?");
68 triggered_ = false;
69 stopCollection_();
70
71 if(multiple_triggers_) {
72 std::cout << "#" << num_collections_ << " pipeline collection ended" << std::endl;
73 ++num_collections_;
74 pipeline_collector_->reactivate(getCollectionPath_());
75 }
76 }
77
78private:
79 void startCollection_()
80 {
81 if(pipeline_enabled_node_names_.empty()) {
82 // Start collection at the root node
83 pipeline_collector_->startCollection(root_);
84 }
85 else {
86 // Find the nodes in the root and enable them
87 for(const auto & node_name : pipeline_enabled_node_names_) {
88 std::vector<TreeNode*> results;
89 root_->getSearchScope()->findChildren(node_name, results);
90 if(results.size() == 0) {
91 std::cerr << SPARTA_CURRENT_COLOR_RED
92 << "WARNING (Pipeline collection): Could not find node named: '"
93 << node_name
94 <<"' Collection will not occur on that node!"
96 << std::endl;
97 }
98 for(auto & tn : results) {
99 std::cout << "Collection enabled on node: '" << tn->getLocation() << "'" << std::endl;
100 pipeline_collector_->startCollection(tn);
101 }
102 }
103 }
104 }
105
106 void stopCollection_()
107 {
108 if(pipeline_enabled_node_names_.empty()) {
109 // Start collection at the root node
110 pipeline_collector_->stopCollection(root_);
111 }
112 else {
113 // Find the nodes in the root and enable them
114 for(const auto & node_name : pipeline_enabled_node_names_) {
115 std::vector<TreeNode*> results;
116 root_->getSearchScope()->findChildren(node_name, results);
117 for(auto & tn : results) {
118 pipeline_collector_->stopCollection(tn);
119 }
120 }
121 }
122 pipeline_collector_->destroy();
123 }
124
125 std::string getCollectionPath_() const
126 {
127 if(pipeline_collection_path_.back() == '/') {
128 return pipeline_collection_path_ + std::to_string(num_collections_) + '_';
129 }
130 else {
131 return pipeline_collection_path_ + '_' + std::to_string(num_collections_) + '_';
132 }
133 }
134
135 std::unique_ptr<collection::PipelineCollector> pipeline_collector_;
136 const std::string pipeline_collection_path_;
137 const std::set<std::string> pipeline_enabled_node_names_;
138 const uint64_t pipeline_heartbeat_;
139 const bool multiple_triggers_;
140 sparta::Clock * clk_ = nullptr;
141 sparta::RootTreeNode * root_ = nullptr;
142 uint32_t num_collections_ = 0;
143};
144
149class LoggingTrigger : public trigger::Triggerable
150{
151 Simulation& sim_;
152 log::TapDescVec taps_;
153
154public:
155
157 const log::TapDescVec& taps) :
158 Triggerable(),
159 sim_(sim),
160 taps_(taps)
161 {;}
162
163public:
164
165 virtual void go() override {
166 sim_.installTaps(taps_);
167 }
168 virtual void stop() override {
169 std::cerr << "Warning: no support for STOPPING a LoggingTrigger" << std::endl;
170 }
171};
172
173
174
175 } // namespace app
176} // namespace sparta
#define SPARTA_CURRENT_COLOR_NORMAL
Macros for accessing the colors through the default scheme.
Definition Colors.hpp:40
Class to facilitate pipeline collection operations.
Simulation setup base class.
#define sparta_assert(...)
Simple variadic assertion that will throw a sparta_exception if the condition fails.
A representation of simulated time.
Definition Clock.hpp:51
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...
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...
Trigger for strating logging given a number of tap descriptors.
Trigger used to enable/disable Pipeline colletion.
Simulator which builds a sparta DeviceTree.
void installTaps(const log::TapDescVec &taps)
Add new taps the the simulation immediately IF possible.
A class that facilitates all universal pipeline collection operations such as outputting finalized re...
Macros for handling exponential backoff.