From a48149f106135ff1671882d5deb3741c95c3910c Mon Sep 17 00:00:00 2001
From: Olivier Stasse <olivier.stasse@laas.fr>
Date: Sat, 2 Dec 2023 03:13:47 +0100
Subject: [PATCH] Add display the list of nodes and the number of threads.

---
 include/dynamic_graph_bridge/ros.hpp |  5 +++++
 src/ros.cpp                          | 25 +++++++++++++++++++++++++
 2 files changed, 30 insertions(+)

diff --git a/include/dynamic_graph_bridge/ros.hpp b/include/dynamic_graph_bridge/ros.hpp
index bbf1e0e..5340598 100644
--- a/include/dynamic_graph_bridge/ros.hpp
+++ b/include/dynamic_graph_bridge/ros.hpp
@@ -67,6 +67,11 @@ typedef std_srvs::srv::Empty EmptyServiceType;
  */
 RosNodePtr get_ros_node(std::string node_name);
 
+
+size_t ros_executor_get_nb_threads();
+
+void ros_display_list_of_nodes();
+
 /**
  * @brief Add a ros node to the global executor.
  *
diff --git a/src/ros.cpp b/src/ros.cpp
index c306efc..dd07121 100644
--- a/src/ros.cpp
+++ b/src/ros.cpp
@@ -131,6 +131,13 @@ class Executor {
     }
   }
 
+  /**
+   * @brief Return the number of threads
+   */
+  size_t get_number_of_threads() {
+    return ros_executor_.get_number_of_threads();
+  }
+
  private:
   /**
    * @brief Thread callback function
@@ -204,6 +211,7 @@ std::string executable_name() {
 #endif
 }
 
+
 /**
  * @brief Private function that allow us to initialize ROS only once.
  */
@@ -273,6 +281,23 @@ void ros_shutdown() {
   // rclcpp::shutdown();
 }
 
+size_t ros_executor_get_nb_threads() {
+  return get_ros_executor()->get_number_of_threads();
+}
+
+void ros_display_list_of_nodes() {
+  GlobalListOfRosNodeType::iterator ros_node_it =
+      GLOBAL_LIST_OF_ROS_NODE.begin();
+  while(ros_node_it!=GLOBAL_LIST_OF_ROS_NODE.end()) {
+    RCLCPP_INFO(rclcpp::get_logger("dynamic_graph_bridge"),
+                "ros_display_list_of_nodes: %s/%s",
+                ros_node_it->second->get_namespace(),
+                ros_node_it->second->get_name());
+    ros_node_it++;
+  }
+
+}
+
 void ros_clean() {
   ros_stop_spinning();
   GlobalListOfRosNodeType::iterator ros_node_it =
-- 
GitLab