Skip to content

Commit 716c19a

Browse files
committed
chore(tensorrt_yolox): add processing time and cyclic time debug topic (autowarefoundation#7126)
fix: add processing time topic Signed-off-by: badai-nguyen <dai.nguyen@tier4.jp>
1 parent d723d1a commit 716c19a

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

perception/tensorrt_yolox/include/tensorrt_yolox/tensorrt_yolox_node.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#include <opencv2/opencv.hpp>
2020
#include <rclcpp/rclcpp.hpp>
2121
#include <tensorrt_yolox/tensorrt_yolox.hpp>
22+
#include <tier4_autoware_utils/ros/debug_publisher.hpp>
23+
#include <tier4_autoware_utils/system/stop_watch.hpp>
2224

2325
#include <sensor_msgs/msg/image.hpp>
2426
#include <std_msgs/msg/header.hpp>
@@ -61,6 +63,8 @@ class TrtYoloXNode : public rclcpp::Node
6163

6264
LabelMap label_map_;
6365
std::unique_ptr<tensorrt_yolox::TrtYoloX> trt_yolox_;
66+
std::unique_ptr<tier4_autoware_utils::StopWatch<std::chrono::milliseconds>> stop_watch_ptr_;
67+
std::unique_ptr<tier4_autoware_utils::DebugPublisher> debug_publisher_;
6468
};
6569

6670
} // namespace tensorrt_yolox

perception/tensorrt_yolox/src/tensorrt_yolox_node.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@ namespace tensorrt_yolox
2929
TrtYoloXNode::TrtYoloXNode(const rclcpp::NodeOptions & node_options)
3030
: Node("tensorrt_yolox", node_options)
3131
{
32+
{
33+
stop_watch_ptr_ =
34+
std::make_unique<tier4_autoware_utils::StopWatch<std::chrono::milliseconds>>();
35+
debug_publisher_ =
36+
std::make_unique<tier4_autoware_utils::DebugPublisher>(this, "tensorrt_yolox");
37+
stop_watch_ptr_->tic("cyclic_time");
38+
stop_watch_ptr_->tic("processing_time");
39+
}
3240
using std::placeholders::_1;
3341
using std::chrono_literals::operator""ms;
3442

@@ -132,6 +140,7 @@ void TrtYoloXNode::onConnect()
132140

133141
void TrtYoloXNode::onImage(const sensor_msgs::msg::Image::ConstSharedPtr msg)
134142
{
143+
stop_watch_ptr_->toc("processing_time", true);
135144
tier4_perception_msgs::msg::DetectedObjectsWithFeature out_objects;
136145

137146
cv_bridge::CvImagePtr in_image_ptr;
@@ -173,6 +182,22 @@ void TrtYoloXNode::onImage(const sensor_msgs::msg::Image::ConstSharedPtr msg)
173182

174183
out_objects.header = msg->header;
175184
objects_pub_->publish(out_objects);
185+
186+
if (debug_publisher_) {
187+
const double processing_time_ms = stop_watch_ptr_->toc("processing_time", true);
188+
const double cyclic_time_ms = stop_watch_ptr_->toc("cyclic_time", true);
189+
const double pipeline_latency_ms =
190+
std::chrono::duration<double, std::milli>(
191+
std::chrono::nanoseconds(
192+
(this->get_clock()->now() - out_objects.header.stamp).nanoseconds()))
193+
.count();
194+
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
195+
"debug/cyclic_time_ms", cyclic_time_ms);
196+
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
197+
"debug/processing_time_ms", processing_time_ms);
198+
debug_publisher_->publish<tier4_debug_msgs::msg::Float64Stamped>(
199+
"debug/pipeline_latency_ms", pipeline_latency_ms);
200+
}
176201
}
177202

178203
bool TrtYoloXNode::readLabelFile(const std::string & label_path)

0 commit comments

Comments
 (0)