The Sparta Modeling Framework
Loading...
Searching...
No Matches
ReportStatsCollector.hpp
1#pragma once
2
3#include "simdb/apps/App.hpp"
4#include "simdb/utils/ConcurrentQueue.hpp"
5
6#include <map>
7#include <unordered_map>
8#include <unordered_set>
9
10namespace sparta {
11 class Report;
12 class Scheduler;
13 class StatisticInstance;
14}
15
16namespace sparta::report::format {
17 class ReportHeader;
18}
19
20namespace sparta::app {
21
22class ReportDescriptor;
23
30
31class ReportStatsCollector : public simdb::App
32{
33public:
34 static constexpr auto NAME = "simdb-reports";
35
36 ReportStatsCollector(simdb::DatabaseManager* db_mgr)
37 : db_mgr_(db_mgr)
38 {}
39
40 static void defineSchema(simdb::Schema&);
41
42 void createPipeline(simdb::pipeline::PipelineManager* pipeline_mgr) override;
43
44 void setScheduler(const Scheduler* scheduler);
45
46 void addDescriptor(const ReportDescriptor* desc);
47
48 int getDescriptorID(const ReportDescriptor* desc,
49 bool must_exist = true) const;
50
51 void setHeader(const ReportDescriptor* desc,
52 const report::format::ReportHeader& header);
53
54 void updateReportMetadata(const ReportDescriptor* desc,
55 const std::string& key,
56 const std::string& value);
57
58 void updateReportStartTime(const ReportDescriptor* desc);
59
60 void updateReportEndTime(const ReportDescriptor* desc);
61
62 void postInit(int argc, char** argv) override;
63
64 void collect(const ReportDescriptor* desc);
65
66 void writeSkipAnnotation(const ReportDescriptor* desc,
67 const std::string& annotation);
68
69 void postTeardown() override;
70
72 {
73 public:
74 ReportAtTick(const ReportDescriptor* descriptor, uint64_t tick)
75 : descriptor_(descriptor)
76 , tick_(tick)
77 {}
78
79 // Default constructor needed to read these out of simdb::ConcurrentQueue's
80 ReportAtTick() = default;
81
82 const ReportDescriptor* getDescriptor() const
83 {
84 return descriptor_;
85 }
86
87 uint64_t getTick() const
88 {
89 return tick_;
90 }
91
92 private:
93 const ReportDescriptor* descriptor_ = nullptr;
94 uint64_t tick_ = 0;
95 };
96
98 {
99 public:
100 ReportStatsAtTick(const ReportDescriptor* descriptor,
101 uint64_t tick,
102 std::vector<double>&& stats)
103 : ReportAtTick(descriptor, tick)
104 , stats_(std::move(stats))
105 {}
106
107 // Default constructor needed to read these out of simdb::ConcurrentQueue's
108 ReportStatsAtTick() = default;
109
110 std::vector<char> compress() const;
111
112 private:
113 std::vector<double> stats_;
114 };
115
117 {
118 public:
120 : ReportAtTick(uncompressed.getDescriptor(), uncompressed.getTick())
121 , bytes_(uncompressed.compress())
122 {}
123
124 // Default constructor needed to read these out of simdb::ConcurrentQueue's
125 CompressedReportStatsAtTick() = default;
126
127 const std::vector<char>& getBytes() const
128 {
129 return bytes_;
130 }
131
132 private:
133 std::vector<char> bytes_;
134 };
135
136private:
137 void writeReportInfo_(const ReportDescriptor* desc);
138
139 void writeReportInfo_(const ReportDescriptor* desc,
140 const Report* r,
141 std::unordered_set<std::string>& visited_stats,
142 int parent_report_id);
143
144 using Descriptor = std::tuple<std::string, std::string, std::string, std::string>;
145 std::vector<std::pair<const ReportDescriptor*, Descriptor>> descriptors_;
146 std::unordered_map<const ReportDescriptor*, int> descriptor_ids_;
147 std::unordered_map<const ReportDescriptor*, const report::format::ReportHeader*> descriptor_headers_;
148 std::unordered_map<const ReportDescriptor*, std::vector<int>> descriptor_report_ids_;
149 std::unordered_map<const ReportDescriptor*, std::vector<int>> descriptor_report_style_ids_;
150 std::unordered_map<const ReportDescriptor*, std::vector<int>> descriptor_report_meta_ids_;
151 std::unordered_map<const ReportDescriptor*, std::vector<const StatisticInstance*>> simdb_stats_;
152 std::unordered_map<const ReportDescriptor*, uint64_t> report_start_times_;
153 std::unordered_map<const ReportDescriptor*, uint64_t> report_end_times_;
154 std::unordered_map<const ReportDescriptor*, std::map<std::string, std::string>> report_metadata_;
155 std::unordered_map<const ReportDescriptor*, std::vector<std::pair<uint64_t, std::string>>> report_skip_annotations_;
156 const Scheduler* scheduler_ = nullptr;
157 simdb::DatabaseManager* db_mgr_ = nullptr;
158 simdb::ConcurrentQueue<ReportStatsAtTick>* pipeline_queue_ = nullptr;
159};
160
161} // namespace sparta::app
A class that lets you schedule events now and in the future.
Describes one or more report to instantiate.
Sparta Application framework.
Macros for handling exponential backoff.