Skip to content

Commit

Permalink
feat(universe_utils): add extra info to time keeper warning (#9484)
Browse files Browse the repository at this point in the history
add extra info to time keeper warning

Signed-off-by: Daniel Sanchez <[email protected]>
  • Loading branch information
danielsanchezaran authored Nov 29, 2024
1 parent 70e4cd6 commit e4f8414
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
File renamed without changes.
8 changes: 5 additions & 3 deletions common/autoware_universe_utils/src/system/time_keeper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <fmt/format.h>

#include <stdexcept>
#include <string>

namespace autoware::universe_utils
{
Expand Down Expand Up @@ -135,9 +136,10 @@ void TimeKeeper::start_track(const std::string & func_name)
root_node_thread_id_ = std::this_thread::get_id();
} else {
if (root_node_thread_id_ != std::this_thread::get_id()) {
RCLCPP_WARN(
rclcpp::get_logger("TimeKeeper"),
"TimeKeeper::start_track() is called from a different thread. Ignoring the call.");
const auto warning_msg = fmt::format(
"TimeKeeper::start_track({}) is called from a different thread. Ignoring the call.",
func_name);
RCLCPP_WARN(rclcpp::get_logger("TimeKeeper"), "%s", warning_msg.c_str());
return;
}
current_time_node_ = current_time_node_->add_child(func_name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,11 @@ TEST_F(TimeKeeperTest, MultiThreadWarning)
t.join();

std::string err = testing::internal::GetCapturedStderr();
EXPECT_TRUE(
err.find("TimeKeeper::start_track() is called from a different thread. Ignoring the call.") !=
std::string::npos);
const bool error_found = err.find(
"TimeKeeper::start_track(MainFunction) is called from a different "
"thread. Ignoring the call.") != std::string::npos ||
err.find(
"TimeKeeper::start_track(ThreadFunction) is called from a different "
"thread. Ignoring the call.") != std::string::npos;
EXPECT_TRUE(error_found);
}

0 comments on commit e4f8414

Please sign in to comment.