mrs_lib
Various reusable classes, functions and utilities for use in MRS projects
profiler.h
Go to the documentation of this file.
1 
5 #ifndef PROFILER_H
6 #define PROFILER_H
7 
8 #include <ros/ros.h>
9 #include <mrs_msgs/ProfilerUpdate.h>
10 #include <mutex>
11 
12 namespace mrs_lib
13 {
14 
15 class Routine {
16 
17 public:
18  Routine(std::string name, std::string node_name, std::shared_ptr<ros::Publisher> publisher, std::shared_ptr<std::mutex> mutex_publisher,
19  bool profiler_enabled);
20  Routine(std::string name, std::string node_name, double expected_rate, double threshold, std::shared_ptr<ros::Publisher> publisher,
21  std::shared_ptr<std::mutex> mutex_publisher, bool profiler_enabled, ros::TimerEvent event);
22  ~Routine();
23 
24  void end(void);
25 
26 private:
27  std::string _routine_name_;
28  std::string _node_name_;
29 
30  std::shared_ptr<ros::Publisher> publisher_;
31  std::shared_ptr<std::mutex> mutex_publisher_;
32 
33  // if periodic, those are the stats from the trigger event
34  double _threshold_;
35  long iteration_ = 0;
36 
37  bool _profiler_enabled_ = false;
38 
39  // those are the stats from the execution of the routine
40  ros::Time execution_start_;
41 
42  // this will be published
43  mrs_msgs::ProfilerUpdate msg_out_;
44 };
45 
46 class Profiler {
47 
48 public:
52  Profiler();
53 
61  Profiler(ros::NodeHandle& nh, std::string node_name, bool profiler_enabled);
62 
68  Profiler(const Profiler& other);
69 
77  Profiler& operator=(const Profiler& other);
78 
89  Routine createRoutine(std::string name, double expected_rate, double threshold, ros::TimerEvent event);
90 
98  Routine createRoutine(std::string name);
99 
100 private:
101  std::shared_ptr<ros::Publisher> publisher_;
102  std::shared_ptr<std::mutex> mutex_publisher_;
103  std::string _node_name_;
104  bool _profiler_enabled_ = false;
105 
106  std::shared_ptr<ros::NodeHandle> nh_;
107 
108  bool is_initialized_ = false;
109 };
110 
111 } // namespace mrs_lib
112 
113 #endif
mrs_lib::Profiler
Definition: profiler.h:46
mrs_lib::Profiler::operator=
Profiler & operator=(const Profiler &other)
the assignment operator
Definition: profiler.cpp:42
mrs_lib::Profiler::createRoutine
Routine createRoutine(std::string name, double expected_rate, double threshold, ros::TimerEvent event)
create a routine for a periodic function
Definition: profiler.cpp:65
mrs_lib::Profiler::Profiler
Profiler()
the basic constructor
Definition: profiler.cpp:10
mrs_lib::Routine
Definition: profiler.h:15
mrs_lib
All mrs_lib functions, classes, variables and definitions are contained in this namespace.
Definition: attitude_converter.h:29