supereight
Loading...
Searching...
No Matches
perfstats.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2011-2013 Gerhard Reitmayr, TU Graz
3 * SPDX-FileCopyrightText: 2014 University of Edinburgh, Imperial College, University of Manchester
4 * SPDX-FileCopyrightText: 2016-2019 Emanuele Vespa
5 * SPDX-FileCopyrightText: 2021 Smart Robotics Lab, Imperial College London, Technical University of Munich
6 * SPDX-FileCopyrightText: 2021 Nils Funk
7 * SPDX-FileCopyrightText: 2021-2024 Sotiris Papatheodorou
8 * SPDX-License-Identifier: MIT
9 */
10
11#ifndef SE_PERFSTATS_HPP
12#define SE_PERFSTATS_HPP
13
14#include <Eigen/Geometry>
15#include <algorithm>
16#include <chrono>
17#include <fstream>
18#include <iomanip>
19#include <map>
20#include <mutex>
21#include <numeric>
22#include <ostream>
23#include <sstream>
24#include <string>
25#include <vector>
26
27namespace se {
28
29struct PerfStats {
53
54 struct Stats {
56
63 static double meanIter(const std::vector<double>& iter_data_vec);
64
72 static double lastIter(const std::vector<double>& iter_data_vec);
73
81 static double minIter(const std::vector<double>& iter_data_vec);
82
90 static double maxIter(const std::vector<double>& iter_data_vec);
91
99 static double sumIter(const std::vector<double>& iter_data_vec);
100
109 static double mergeIter(const std::vector<double>& iter_data_vec, const Type type);
110
111
113
120 double meanIter(const size_t iter);
121
129 double lastIter(const size_t iter);
130
138 double minIter(const size_t iter);
139
147 double maxIter(const size_t iter);
148
156 double sumIter(const size_t iter);
157
166 double mergeIter(const size_t iter);
167
168
170
175 double mean() const;
176
182 double last() const;
183
189 double min() const;
190
196 double max() const;
197
203 double sum() const;
204
211 double merge() const;
212
213
217 std::string unitString();
218
219 // <iteration/frame, vector of values at iteration/frame>
220 std::map<size_t, std::vector<double>> data_;
222 std::mutex mutex_;
224 };
225
226 struct Results {
227 double mean;
228 double min;
229 double max;
230 double sum;
231 };
232
234
240 std::string createHeaderString();
241
242 std::string createDataIterString();
243
244 std::string createDataIterString(const size_t iter);
245
246 std::string createDataString();
247
254 const Stats& get(const std::string& key) const
255 {
256 return stats_.find(key)->second;
257 }
258
259 double sample(const std::string& key, const double value, const Type type = COUNT);
260
261 double sampleT_WB(const Eigen::Isometry3f& T_WB);
262
263 double sampleDurationStart(const std::string& key);
264
265 double sampleDurationEnd(const std::string& key);
266
267 void setFilestream(std::ofstream* filestream);
268
274 void setIter(const size_t iter)
275 {
276 iter_ = iter;
277 sample("iteration", iter, ITERATION);
278 };
279
286
287 void writeToOStream(std::ostream& ostream);
288
289 void writeSummaryToOStream(std::ostream& ostream, const bool include_iter_data = true);
290
292 static double timeNow();
293
299
301 size_t iter_;
302 std::map<int, std::string>
304 std::map<std::string, Stats> stats_;
305
306 std::ofstream* filestream_;
309 std::streampos filestream_pos_;
310
313};
314
315extern PerfStats perfstats;
316
317} // namespace se
318
319#include "impl/perfstats_impl.hpp"
320
321#endif // SE_PERFSTATS_HPP
Definition image.hpp:19
Helper wrapper to allocate and de-allocate octants in the octree.
Definition bounded_vector.hpp:14
PerfStats perfstats
Definition perfstats.hpp:226
double min
Definition perfstats.hpp:228
double max
Definition perfstats.hpp:229
double sum
Definition perfstats.hpp:230
double mean
Definition perfstats.hpp:227
Definition perfstats.hpp:54
double mergeIter(const size_t iter)
Merge the stats data a given interation into a scalar value.
double last() const
Provide the last stored value to the stats data.
static double sumIter(const std::vector< double > &iter_data_vec)
Compute the sum of the values of the stats data of an iteration.
double merge() const
Merge all stats data into a scalar value.
std::string unitString()
Type type_
The type of data stored in the stat struct.
Definition perfstats.hpp:223
std::mutex mutex_
Definition perfstats.hpp:222
double minIter(const size_t iter)
Compute the minimum value of the stats data of a given iteration.
double maxIter(const size_t iter)
Compute the maximum value of the stats data of a given iteration.
double sum() const
Compute the sum of all stats data stored so far.
double max() const
Compute the maximum value of all stats data stored so far.
double sumIter(const size_t iter)
Compute the sum value of the stats data of a given iteration.
double meanIter(const size_t iter)
Functions to summarise data of one iteration.
std::map< size_t, std::vector< double > > data_
Definition perfstats.hpp:220
static double meanIter(const std::vector< double > &iter_data_vec)
Static functions to summarise data of one iteration.
double lastIter(const size_t iter)
Provide the last value of the stats data of a given iteration.
double last_absolute_
The last absolute time the stat data was updated.
Definition perfstats.hpp:221
static double minIter(const std::vector< double > &iter_data_vec)
Compute the minimum value of the stats data of an iteration.
double min() const
Compute the minimum value of all stats data stored so far.
double mean() const
Functions to summarise data of the entire stats.
static double lastIter(const std::vector< double > &iter_data_vec)
Provide the last value of the stats data of an iteration.
static double mergeIter(const std::vector< double > &iter_data_vec, const Type type)
Merge the stats data of one interation into a scalar value.
static double maxIter(const std::vector< double > &iter_data_vec)
Compute the maximum value of the stats data of an iteration.
Definition perfstats.hpp:29
int insertion_idx_
The index of the next stat to be inserted to performance stats.
Definition perfstats.hpp:300
size_t iter_
The current iteration.
Definition perfstats.hpp:301
std::vector< PerfStats::Type > header_order_
The order the different types are added to the output.
Definition perfstats.hpp:295
void writeToFilestream()
Write performance stats to filestream.
bool filestream_aligned_
Definition perfstats.hpp:307
double sampleDurationEnd(const std::string &key)
std::string createDataIterString(const size_t iter)
Type
Definition perfstats.hpp:30
@ MEMORY
Definition perfstats.hpp:43
@ POWER
Definition perfstats.hpp:47
@ FRAME
Definition perfstats.hpp:39
@ COORDINATES
Definition perfstats.hpp:32
@ COUNT
Definition perfstats.hpp:33
@ DISTANCE
Definition perfstats.hpp:35
@ VOLTAGE
Definition perfstats.hpp:50
@ UNDEFINED
Definition perfstats.hpp:49
@ ITERATION
Definition perfstats.hpp:42
@ CURRENT
Definition perfstats.hpp:34
@ ORIENTATION
Definition perfstats.hpp:44
@ INT
Definition perfstats.hpp:41
@ FREQUENCY
Definition perfstats.hpp:40
@ ENERGY
Definition perfstats.hpp:38
@ VOLUME
Definition perfstats.hpp:51
@ DURATION
Definition perfstats.hpp:37
@ POSITION
Definition perfstats.hpp:46
@ BOOL
Definition perfstats.hpp:31
@ TIME
Definition perfstats.hpp:48
@ DOUBLE
Definition perfstats.hpp:36
@ PERCENTAGE
Definition perfstats.hpp:45
void setFilestream(std::ofstream *filestream)
void writeSummaryToOStream(std::ostream &ostream, const bool include_iter_data=true)
size_t ostream_last_iter_
Definition perfstats.hpp:312
std::ofstream * filestream_
Definition perfstats.hpp:306
double sampleDurationStart(const std::string &key)
void setIter(const size_t iter)
Set the current iteration and add it to the stats.
Definition perfstats.hpp:274
std::string createDataString()
size_t filestream_last_iter_
Definition perfstats.hpp:308
std::string createDataIterString()
bool ostream_aligned_
Definition perfstats.hpp:311
std::string createHeaderString()
std::map< std::string, Stats > stats_
The map stat name -> stat.
Definition perfstats.hpp:304
const Stats & get(const std::string &key) const
Definition perfstats.hpp:254
std::streampos filestream_pos_
Definition perfstats.hpp:309
double sample(const std::string &key, const double value, const Type type=COUNT)
double sampleT_WB(const Eigen::Isometry3f &T_WB)
void writeToOStream(std::ostream &ostream)
std::map< int, std::string > order_
The order the stats are added to the stats_ map | map idx -> stat name.
Definition perfstats.hpp:303
static double timeNow()
Return the current seconds since the epoch, as measured by std::chrono::steady_clock.