code_profiler
profile_publisher.cpp
Go to the documentation of this file.
3 
4 #include <std_msgs/String.h>
5 #include <ros/node_handle.h>
6 
7 #include <sstream>
8 
9 namespace tue
10 {
11 
12 // ----------------------------------------------------------------------------------------------------
13 
14 ProfilePublisher::ProfilePublisher() : profiler_(nullptr)
15 {
16 }
17 
18 // ----------------------------------------------------------------------------------------------------
19 
21 {
22  initialize();
23 }
24 
25 // ----------------------------------------------------------------------------------------------------
26 
28 {
29  initialize();
30 }
31 
32 // ----------------------------------------------------------------------------------------------------
33 
35 {
37  initialize();
38 }
39 
40 // ----------------------------------------------------------------------------------------------------
41 
43 {
45  initialize();
46 }
47 
48 // ----------------------------------------------------------------------------------------------------
49 
51 {
52  assert((void("Profiler is a nullptr"), profiler_));
53  ros::NodeHandle nh("~");
54  pub_stats_ = nh.advertise<std_msgs::String>("profile/" + profiler_->getName(), 1);
55 }
56 
57 // ----------------------------------------------------------------------------------------------------
58 
60 {
61  if (pub_stats_.getTopic() == "")
62  {
63  std::cout << "[tue::Profiler] ProfilePublisher not initialized." << std::endl;
64  return;
65  }
66 
68  s << *profiler_;
69 
70  std_msgs::String msg;
71  msg.data = s.str();
72 
73  pub_stats_.publish(msg);
74 }
75 
76 }
sstream
tue::Profiler::getName
const std::string & getName() const
Definition: profiler.h:24
std::stringstream
tue::ProfilePublisher::profiler_
const Profiler * profiler_
Definition: profile_publisher.h:33
std::cout
profiler.h
profiler
tue::Profiler profiler
Definition: test_profiler.cpp:4
tue::ProfilePublisher::pub_stats_
ros::Publisher pub_stats_
Definition: profile_publisher.h:35
profile_publisher.h
tue::ProfilePublisher::publish
void publish() const
Definition: profile_publisher.cpp:59
tue::ProfilePublisher::initialize
void initialize()
Definition: profile_publisher.cpp:50
tue::Profiler
Definition: profiler.h:11
std::endl
T endl(T... args)
tue::ProfilePublisher::ProfilePublisher
ProfilePublisher()
Definition: profile_publisher.cpp:14
std::stringstream::str
T str(T... args)
tue
Definition: loop_timer.h:8