Skip to content

Commit 5a1bba5

Browse files
authored
Merge branch 'main' into chore/radar_tracks_msgs_converter_param
2 parents cc4ed4d + e67ab70 commit 5a1bba5

File tree

99 files changed

+3246
-1230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+3246
-1230
lines changed

common/tensorrt_common/include/tensorrt_common/logger.hpp

+56-7
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,15 @@
1919

2020
#include "NvInferRuntimeCommon.h"
2121

22+
#include <atomic>
2223
#include <cassert>
2324
#include <ctime>
2425
#include <iomanip>
2526
#include <iostream>
2627
#include <ostream>
2728
#include <sstream>
2829
#include <string>
30+
#include <thread>
2931

3032
namespace tensorrt_common
3133
{
@@ -200,7 +202,15 @@ class Logger : public nvinfer1::ILogger // NOLINT
200202
public:
201203
// Logger(Severity severity = Severity::kWARNING)
202204
// Logger(Severity severity = Severity::kVERBOSE)
203-
explicit Logger(Severity severity = Severity::kINFO) : mReportableSeverity(severity) {}
205+
explicit Logger(Severity severity = Severity::kINFO)
206+
: mReportableSeverity(severity), mVerbose(true), mThrottleStopFlag(false)
207+
{
208+
}
209+
210+
explicit Logger(const bool verbose, Severity severity = Severity::kINFO)
211+
: mReportableSeverity(severity), mVerbose(verbose), mThrottleStopFlag(false)
212+
{
213+
}
204214

205215
//!
206216
//! \enum TestResult
@@ -234,7 +244,44 @@ class Logger : public nvinfer1::ILogger // NOLINT
234244
//!
235245
void log(Severity severity, const char * msg) noexcept override
236246
{
237-
LogStreamConsumer(mReportableSeverity, severity) << "[TRT] " << std::string(msg) << std::endl;
247+
if (mVerbose) {
248+
LogStreamConsumer(mReportableSeverity, severity) << "[TRT] " << std::string(msg) << std::endl;
249+
}
250+
}
251+
252+
/**
253+
* @brief Logging with throttle.
254+
*
255+
* @example
256+
* Logger logger();
257+
* auto log_thread = logger.log_throttle(nvinfer1::ILogger::Severity::kINFO, "SOME MSG", 1);
258+
* // some operation
259+
* logger.stop_throttle(log_thread);
260+
*
261+
* @param severity
262+
* @param msg
263+
* @param duration
264+
* @return std::thread
265+
*
266+
*/
267+
std::thread log_throttle(Severity severity, const char * msg, const int duration) noexcept
268+
{
269+
mThrottleStopFlag.store(false);
270+
auto log_func = [this](Severity s, const char * m, const int d) {
271+
while (!mThrottleStopFlag.load()) {
272+
this->log(s, m);
273+
std::this_thread::sleep_for(std::chrono::seconds(d));
274+
}
275+
};
276+
277+
std::thread log_thread(log_func, severity, msg, duration);
278+
return log_thread;
279+
}
280+
281+
void stop_throttle(std::thread & log_thread) noexcept
282+
{
283+
mThrottleStopFlag.store(true);
284+
log_thread.join();
238285
}
239286

240287
//!
@@ -430,6 +477,8 @@ class Logger : public nvinfer1::ILogger // NOLINT
430477
}
431478

432479
Severity mReportableSeverity;
480+
bool mVerbose;
481+
std::atomic<bool> mThrottleStopFlag;
433482
};
434483

435484
namespace
@@ -444,7 +493,7 @@ namespace
444493
//!
445494
inline LogStreamConsumer LOG_VERBOSE(const Logger & logger)
446495
{
447-
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kVERBOSE);
496+
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kVERBOSE) << "[TRT] ";
448497
}
449498

450499
//!
@@ -456,7 +505,7 @@ inline LogStreamConsumer LOG_VERBOSE(const Logger & logger)
456505
//!
457506
inline LogStreamConsumer LOG_INFO(const Logger & logger)
458507
{
459-
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kINFO);
508+
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kINFO) << "[TRT] ";
460509
}
461510

462511
//!
@@ -468,7 +517,7 @@ inline LogStreamConsumer LOG_INFO(const Logger & logger)
468517
//!
469518
inline LogStreamConsumer LOG_WARN(const Logger & logger)
470519
{
471-
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kWARNING);
520+
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kWARNING) << "[TRT] ";
472521
}
473522

474523
//!
@@ -480,7 +529,7 @@ inline LogStreamConsumer LOG_WARN(const Logger & logger)
480529
//!
481530
inline LogStreamConsumer LOG_ERROR(const Logger & logger)
482531
{
483-
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kERROR);
532+
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kERROR) << "[TRT] ";
484533
}
485534

486535
//!
@@ -494,7 +543,7 @@ inline LogStreamConsumer LOG_ERROR(const Logger & logger)
494543
//!
495544
inline LogStreamConsumer LOG_FATAL(const Logger & logger)
496545
{
497-
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kINTERNAL_ERROR);
546+
return LogStreamConsumer(logger.getReportableSeverity(), Severity::kINTERNAL_ERROR) << "[TRT] ";
498547
}
499548

500549
} // anonymous namespace

common/tensorrt_common/src/tensorrt_common.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,11 @@ void TrtCommon::setup()
186186
} else {
187187
std::cout << "Building... " << cache_engine_path << std::endl;
188188
logger_.log(nvinfer1::ILogger::Severity::kINFO, "Start build engine");
189+
auto log_thread = logger_.log_throttle(
190+
nvinfer1::ILogger::Severity::kINFO,
191+
"Applying optimizations and building TRT CUDA engine. Please wait for a few minutes...", 5);
189192
buildEngineFromOnnx(model_file_path_, cache_engine_path);
193+
logger_.stop_throttle(log_thread);
190194
logger_.log(nvinfer1::ILogger::Severity::kINFO, "End build engine");
191195
}
192196
engine_path = cache_engine_path;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(tier4_metrics_rviz_plugin)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
find_package(Qt5 REQUIRED Core Widgets Charts)
8+
set(QT_WIDGETS_LIB Qt5::Widgets)
9+
set(QT_CHARTS_LIB Qt5::Charts)
10+
set(CMAKE_AUTOMOC ON)
11+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
12+
add_definitions(-DQT_NO_KEYWORDS)
13+
14+
ament_auto_add_library(${PROJECT_NAME} SHARED
15+
src/metrics_visualize_panel.cpp
16+
)
17+
18+
target_link_libraries(${PROJECT_NAME}
19+
${QT_WIDGETS_LIB}
20+
${QT_CHARTS_LIB}
21+
)
22+
23+
target_compile_options(${PROJECT_NAME} PUBLIC -Wno-error=deprecated-copy -Wno-error=pedantic)
24+
# Export the plugin to be imported by rviz2
25+
pluginlib_export_plugin_description_file(rviz_common plugins/plugin_description.xml)
26+
27+
ament_auto_package(
28+
INSTALL_TO_SHARE
29+
icons
30+
plugins
31+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# tier4_metrics_rviz_plugin
2+
3+
## Purpose
4+
5+
This plugin panel to visualize `planning_evaluator` output.
6+
7+
## Inputs / Outputs
8+
9+
| Name | Type | Description |
10+
| ---------------------------------------- | --------------------------------------- | ------------------------------------- |
11+
| `/diagnostic/planning_evaluator/metrics` | `diagnostic_msgs::msg::DiagnosticArray` | Subscribe `planning_evaluator` output |
12+
13+
## HowToUse
14+
15+
1. Start rviz and select panels/Add new panel.
16+
2. Select MetricsVisualizePanel and press OK.
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>tier4_metrics_rviz_plugin</name>
5+
<version>0.0.0</version>
6+
<description>The tier4_metrics_rviz_plugin package</description>
7+
<maintainer email="satoshi.ota@tier4.jp">Satoshi OTA</maintainer>
8+
<maintainer email="kyoichi.sugahara@tier4.jp">Kyoichi Sugahara</maintainer>
9+
<maintainer email="maxime.clement@tier4.jp">Maxime CLEMENT</maintainer>
10+
<license>Apache License 2.0</license>
11+
12+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
13+
<buildtool_depend>autoware_cmake</buildtool_depend>
14+
15+
<depend>diagnostic_msgs</depend>
16+
<depend>libqt5-core</depend>
17+
<depend>libqt5-gui</depend>
18+
<depend>libqt5-widgets</depend>
19+
<depend>qtbase5-dev</depend>
20+
<depend>rclcpp</depend>
21+
<depend>rviz_common</depend>
22+
23+
<test_depend>ament_lint_auto</test_depend>
24+
<test_depend>autoware_lint_common</test_depend>
25+
26+
<export>
27+
<build_type>ament_cmake</build_type>
28+
<rviz plugin="${prefix}/plugins/plugin_description.xml"/>
29+
</export>
30+
</package>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<library path="tier4_metrics_rviz_plugin">
2+
<class type="rviz_plugins::MetricsVisualizePanel" base_class_type="rviz_common::Panel">
3+
<description>MetricsVisualizePanel</description>
4+
</class>
5+
</library>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright 2024 TIER IV, Inc. All rights reserved.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
#include "metrics_visualize_panel.hpp"
17+
18+
#include <rviz_common/display_context.hpp>
19+
20+
#include <X11/Xlib.h>
21+
22+
#include <algorithm>
23+
#include <optional>
24+
#include <string>
25+
#include <vector>
26+
27+
namespace rviz_plugins
28+
{
29+
MetricsVisualizePanel::MetricsVisualizePanel(QWidget * parent)
30+
: rviz_common::Panel(parent), grid_(new QGridLayout())
31+
{
32+
setLayout(grid_);
33+
}
34+
35+
void MetricsVisualizePanel::onInitialize()
36+
{
37+
using std::placeholders::_1;
38+
39+
raw_node_ = this->getDisplayContext()->getRosNodeAbstraction().lock()->get_raw_node();
40+
41+
sub_ = raw_node_->create_subscription<DiagnosticArray>(
42+
"/diagnostic/planning_evaluator/metrics", rclcpp::QoS{1},
43+
std::bind(&MetricsVisualizePanel::onMetrics, this, _1));
44+
45+
const auto period = std::chrono::milliseconds(static_cast<int64_t>(1e3 / 10));
46+
timer_ = raw_node_->create_wall_timer(period, [&]() { onTimer(); });
47+
}
48+
49+
void MetricsVisualizePanel::onTimer()
50+
{
51+
std::lock_guard<std::mutex> message_lock(mutex_);
52+
53+
for (auto & [name, metric] : metrics_) {
54+
metric.updateGraph();
55+
metric.updateTable();
56+
}
57+
}
58+
59+
void MetricsVisualizePanel::onMetrics(const DiagnosticArray::ConstSharedPtr msg)
60+
{
61+
std::lock_guard<std::mutex> message_lock(mutex_);
62+
63+
const auto time = msg->header.stamp.sec + msg->header.stamp.nanosec * 1e-9;
64+
65+
constexpr size_t GRAPH_COL_SIZE = 5;
66+
for (size_t i = 0; i < msg->status.size(); ++i) {
67+
const auto & status = msg->status.at(i);
68+
69+
if (metrics_.count(status.name) == 0) {
70+
auto metric = Metric(status);
71+
metrics_.emplace(status.name, metric);
72+
grid_->addWidget(metric.getTable(), i / GRAPH_COL_SIZE * 2, i % GRAPH_COL_SIZE);
73+
grid_->setRowStretch(i / GRAPH_COL_SIZE * 2, false);
74+
grid_->addWidget(metric.getChartView(), i / GRAPH_COL_SIZE * 2 + 1, i % GRAPH_COL_SIZE);
75+
grid_->setRowStretch(i / GRAPH_COL_SIZE * 2 + 1, true);
76+
grid_->setColumnStretch(i % GRAPH_COL_SIZE, true);
77+
}
78+
79+
metrics_.at(status.name).updateData(time, status);
80+
}
81+
}
82+
83+
} // namespace rviz_plugins
84+
85+
#include <pluginlib/class_list_macros.hpp>
86+
PLUGINLIB_EXPORT_CLASS(rviz_plugins::MetricsVisualizePanel, rviz_common::Panel)

0 commit comments

Comments
 (0)