mars_lib 0.1.0.2abe2576fe7f
Modular and Robust Sensor-Fusion
Loading...
Searching...
No Matches
m_perf.h
Go to the documentation of this file.
1// Copyright (C) 2022 Christian Brommer, Control of Networked Systems, University of Klagenfurt, Austria.
2//
3// All rights reserved.
4//
5// This software is licensed under the terms of the BSD-2-Clause-License with
6// no commercial use allowed, the full terms of which are made available
7// in the LICENSE file. No license in patents is granted.
8//
9// You can contact the author at <christian.brommer@ieee.org>
10
11#ifndef M_PERF_H
12#define M_PERF_H
13
14#include <chrono>
15#include <iostream>
16#include <map>
17#include <memory>
18#include <vector>
19
20namespace mars
21{
28{
29public:
34 bool AddStart();
35
40 bool AddStop();
41
46 std::vector<double> get_start_times();
51 std::vector<double> get_stop_times();
52
57 double get_mean();
58
63 double get_std();
64
69 double get_max();
70
75 double get_min();
76
81 std::vector<double> get_diff_vec();
82
87 int get_size();
88
89private:
93 using time_type = std::chrono::high_resolution_clock::time_point;
94
98 std::string name_;
99
103 std::vector<time_type> start_;
104
108 std::vector<time_type> stop_;
109
113 bool is_running_{ false };
114
120};
121
127class MPerf
128{
129public:
130 MPerf(const std::string& name);
132
138 bool StartEntity(const std::string& entity_name);
139
145 bool StopEntity(const std::string& entity_name);
146
151 std::string PrintStats();
152
158 std::string get_stats_as_csv(const std::string& entity_name);
159
164 std::string get_entity_names();
165
166private:
170 using m_perf_map = std::map<std::string, std::shared_ptr<MPerfType>>;
171
176
180 std::string name_;
181
185 bool name_set_{ false };
186
190 bool verbose_{ false };
191};
192} // namespace mars
193#endif // M_PERF_H
The MPerf class Class which hosts individual time tracking instances.
Definition m_perf.h:128
std::string get_entity_names()
get_entity_names Print the names of all registered entities
MPerf(const std::string &name)
bool StartEntity(const std::string &entity_name)
StartEntity Starts/Adds an entity to be tracked.
bool name_set_
name_set_ Indicator if a name for the tracker was set
Definition m_perf.h:185
std::string name_
name_ Name of the performance tracking instance
Definition m_perf.h:180
bool StopEntity(const std::string &entity_name)
StopEntity Stops an entity that was tracked.
std::map< std::string, std::shared_ptr< MPerfType > > m_perf_map
m_perf_map Type of the map which hosts time tracking elements
Definition m_perf.h:170
std::string PrintStats()
PrintStats Prints the stats of all entities.
bool verbose_
verbose_ Increased console output
Definition m_perf.h:190
m_perf_map data_
data_ Map of all time tracked elements associated by map key
Definition m_perf.h:175
std::string get_stats_as_csv(const std::string &entity_name)
get_stats_as_csv Provide stats of all entities in form of a csv string
The MPerfType class Class of performance entry types.
Definition m_perf.h:28
double get_mean()
get_mean Returns the mean of the duration times of the current instance
std::vector< time_type > start_
start_ Vector of tracked starting times
Definition m_perf.h:103
std::vector< double > get_stop_times()
get_stop_times Returns a full vector of all stop times
double get_std()
get_std Returns the std of the mean for the duration times of the current instance
bool AddStop()
AddStop Adds stop time to time buffer of the current instance.
time_type get_time()
get_time Get current time
double get_max()
get_max Returns the max of the duration times of the current instance
std::string name_
name_ Name of the current tracking instance
Definition m_perf.h:98
std::vector< double > get_start_times()
get_start_times Returns a full vector of all start times
std::vector< double > get_diff_vec()
get_diff_vec Returns a vector with durations for all entries
std::chrono::high_resolution_clock::time_point time_type
time_type Type which the timer isntance returns
Definition m_perf.h:93
bool is_running_
is_running_ Indicator if the current instance is already tracking a duration
Definition m_perf.h:113
std::vector< time_type > stop_
stop_ Vector of tracked stopping times
Definition m_perf.h:108
bool AddStart()
AddStart Adds start time to time buffer of the current instance.
double get_min()
get_min Returns the min of the duration times of the current instance
int get_size()
get_size Gets the size of all start stop time combinations
Definition buffer.h:27