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 // TODO cnyce
45 sparta_assert(!multiple_triggers_, "The --debug-on-roi option is not supported yet in MAP v3");
46
47 pipeline_collector_.
48 reset(new sparta::collection::PipelineCollector(multiple_triggers_ ? getCollectionPath_() : pipeline_collection_path_,
49 pipeline_heartbeat_,
50 clk_,
51 root_));
52
53 }
54
55 void go() override
56 {
57 sparta_assert(!triggered_, "Why has pipeline trigger been triggered?");
58 triggered_ = true;
59 std::cout << "Pipeline collection started, writing to database file '"
60 << pipeline_collector_->getFilePath() << "'" << std::endl;
61 startCollection_();
62
63 if(multiple_triggers_) {
64 std::cout << "#" << num_collections_ << " pipeline collection started" << std::endl;
65 }
66 }
67
68 void stop() override
69 {
70 sparta_assert(triggered_, "Why stop an inactivated trigger?");
71 triggered_ = false;
72 stopCollection_();
73
74 if(multiple_triggers_) {
75 std::cout << "#" << num_collections_ << " pipeline collection ended" << std::endl;
76 ++num_collections_;
77 pipeline_collector_->reactivate(getCollectionPath_());
78 }
79 }
80
81private:
82 void startCollection_()
83 {
84 if(pipeline_enabled_node_names_.empty()) {
85 // Start collection at the root node
86 pipeline_collector_->startCollection(root_);
87 }
88 else {
89 // Find the nodes in the root and enable them
90 for(const auto & node_name : pipeline_enabled_node_names_) {
91 std::vector<TreeNode*> results;
92 root_->getSearchScope()->findChildren(node_name, results);
93 if(results.size() == 0) {
94 std::cerr << SPARTA_CURRENT_COLOR_RED
95 << "WARNING (Pipeline collection): Could not find node named: '"
96 << node_name
97 <<"' Collection will not occur on that node!"
99 << std::endl;
100 }
101 for(auto & tn : results) {
102 std::cout << "Collection enabled on node: '" << tn->getLocation() << "'" << std::endl;
103 pipeline_collector_->startCollection(tn);
104 }
105 }
106 }
107 }
108
109 void stopCollection_()
110 {
111 if(pipeline_enabled_node_names_.empty()) {
112 // Start collection at the root node
113 pipeline_collector_->stopCollection(root_);
114 }
115 else {
116 // Find the nodes in the root and enable them
117 for(const auto & node_name : pipeline_enabled_node_names_) {
118 std::vector<TreeNode*> results;
119 root_->getSearchScope()->findChildren(node_name, results);
120 for(auto & tn : results) {
121 pipeline_collector_->stopCollection(tn);
122 }
123 }
124 }
125 pipeline_collector_->destroy();
126 }
127
128 std::string getCollectionPath_() const
129 {
130 if(pipeline_collection_path_.back() == '/') {
131 return pipeline_collection_path_ + std::to_string(num_collections_) + '_';
132 }
133 else {
134 return pipeline_collection_path_ + '_' + std::to_string(num_collections_) + '_';
135 }
136 }
137
138 std::unique_ptr<collection::PipelineCollector> pipeline_collector_;
139 const std::string pipeline_collection_path_;
140 const std::set<std::string> pipeline_enabled_node_names_;
141 const uint64_t pipeline_heartbeat_;
142 const bool multiple_triggers_;
143 sparta::Clock * clk_ = nullptr;
144 sparta::RootTreeNode * root_ = nullptr;
145 uint32_t num_collections_ = 0;
146};
147
152class LoggingTrigger : public trigger::Triggerable
153{
154 Simulation& sim_;
155 log::TapDescVec taps_;
156
157public:
158
160 const log::TapDescVec& taps) :
161 Triggerable(),
162 sim_(sim),
163 taps_(taps)
164 {;}
165
166public:
167
168 virtual void go() override {
169 sim_.installTaps(taps_);
170 }
171 virtual void stop() override {
172 std::cerr << "Warning: no support for STOPPING a LoggingTrigger" << std::endl;
173 }
174};
175
176
177
178 } // namespace app
179} // 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:44
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.