Skip to content

Commit e4f8414

Browse files
feat(universe_utils): add extra info to time keeper warning (#9484)
add extra info to time keeper warning Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent 70e4cd6 commit e4f8414

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed
File renamed without changes.

common/autoware_universe_utils/src/system/time_keeper.cpp

+5-3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <fmt/format.h>
2121

2222
#include <stdexcept>
23+
#include <string>
2324

2425
namespace autoware::universe_utils
2526
{
@@ -135,9 +136,10 @@ void TimeKeeper::start_track(const std::string & func_name)
135136
root_node_thread_id_ = std::this_thread::get_id();
136137
} else {
137138
if (root_node_thread_id_ != std::this_thread::get_id()) {
138-
RCLCPP_WARN(
139-
rclcpp::get_logger("TimeKeeper"),
140-
"TimeKeeper::start_track() is called from a different thread. Ignoring the call.");
139+
const auto warning_msg = fmt::format(
140+
"TimeKeeper::start_track({}) is called from a different thread. Ignoring the call.",
141+
func_name);
142+
RCLCPP_WARN(rclcpp::get_logger("TimeKeeper"), "%s", warning_msg.c_str());
141143
return;
142144
}
143145
current_time_node_ = current_time_node_->add_child(func_name);

common/autoware_universe_utils/test/src/system/test_time_keeper.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ TEST_F(TimeKeeperTest, MultiThreadWarning)
8686
t.join();
8787

8888
std::string err = testing::internal::GetCapturedStderr();
89-
EXPECT_TRUE(
90-
err.find("TimeKeeper::start_track() is called from a different thread. Ignoring the call.") !=
91-
std::string::npos);
89+
const bool error_found = err.find(
90+
"TimeKeeper::start_track(MainFunction) is called from a different "
91+
"thread. Ignoring the call.") != std::string::npos ||
92+
err.find(
93+
"TimeKeeper::start_track(ThreadFunction) is called from a different "
94+
"thread. Ignoring the call.") != std::string::npos;
95+
EXPECT_TRUE(error_found);
9296
}

0 commit comments

Comments
 (0)