code_profiler
src
ros
profile_publisher.cpp
Go to the documentation of this file.
1
#include "
tue/profiling/ros/profile_publisher.h
"
2
#include "
tue/profiling/profiler.h
"
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
20
ProfilePublisher::ProfilePublisher
(
const
Profiler
&
profiler
) : profiler_(&
profiler
)
21
{
22
initialize
();
23
}
24
25
// ----------------------------------------------------------------------------------------------------
26
27
ProfilePublisher::ProfilePublisher
(
const
Profiler
*
profiler
) : profiler_(
profiler
)
28
{
29
initialize
();
30
}
31
32
// ----------------------------------------------------------------------------------------------------
33
34
void
ProfilePublisher::initialize
(
const
Profiler
&
profiler
)
35
{
36
profiler_
= &
profiler
;
37
initialize
();
38
}
39
40
// ----------------------------------------------------------------------------------------------------
41
42
void
ProfilePublisher::initialize
(
const
Profiler
*
profiler
)
43
{
44
profiler_
=
profiler
;
45
initialize
();
46
}
47
48
// ----------------------------------------------------------------------------------------------------
49
50
void
ProfilePublisher::initialize
()
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
59
void
ProfilePublisher::publish
()
const
60
{
61
if
(
pub_stats_
.getTopic() ==
""
)
62
{
63
std::cout
<<
"[tue::Profiler] ProfilePublisher not initialized."
<<
std::endl
;
64
return
;
65
}
66
67
std::stringstream
s;
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
Generated on Sun Feb 23 2025 04:33:26 for code_profiler by
1.8.17