Skip to content

Commit

Permalink
use metric_msgs for autoware_processing_time_checker.
Browse files Browse the repository at this point in the history
  • Loading branch information
xtk8532704 committed Oct 29, 2024
1 parent 54ea4e1 commit 0e10eb5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 24 deletions.
2 changes: 1 addition & 1 deletion system/autoware_processing_time_checker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ ros2 launch autoware_processing_time_checker processing_time_checker.launch.xml

| Name | Type | Description |
| ----------------------------------------- | --------------------------------- | ---------------------------------- |
| `/system/processing_time_checker/metrics` | `diagnostic_msgs/DiagnosticArray` | processing time of all the modules |
| `/system/processing_time_checker/metrics` | `tier4_metric_msgs::msg::MetricArray` | processing time of all the modules |

## Parameters

Expand Down
2 changes: 1 addition & 1 deletion system/autoware_processing_time_checker/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
<buildtool_depend>ament_cmake</buildtool_depend>
<buildtool_depend>autoware_cmake</buildtool_depend>

<depend>diagnostic_updater</depend>
<depend>rclcpp</depend>
<depend>rclcpp_components</depend>
<depend>tier4_debug_msgs</depend>
<depend>tier4_metric_msgs</depend>

<test_depend>ament_lint_auto</test_depend>
<test_depend>ament_lint_common</test_depend>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include <rclcpp/rclcpp.hpp>

#include <chrono>
#include <string>
#include <vector>

Expand Down Expand Up @@ -84,7 +83,7 @@ ProcessingTimeChecker::ProcessingTimeChecker(const rclcpp::NodeOptions & node_op
// clang-format on
}

diag_pub_ = create_publisher<DiagnosticArray>("~/metrics", 1);
metrics_pub_ = create_publisher<MetricArrayMsg>("~/metrics", 1);

const auto period_ns = rclcpp::Rate(update_rate).period();
timer_ = rclcpp::create_timer(
Expand All @@ -93,28 +92,23 @@ ProcessingTimeChecker::ProcessingTimeChecker(const rclcpp::NodeOptions & node_op

void ProcessingTimeChecker::on_timer()
{
// create diagnostic status
DiagnosticStatus status;
status.level = status.OK;
status.name = "processing_time";
// create MetricArrayMsg
MetricArrayMsg metrics_msg;
for (const auto & processing_time_iterator : processing_time_map_) {
const auto processing_time_topic_name = processing_time_iterator.first;
const double processing_time = processing_time_iterator.second;

// generate diagnostic status
diagnostic_msgs::msg::KeyValue key_value;
key_value.key = processing_time_topic_name;
key_value.value = std::to_string(processing_time);
status.values.push_back(key_value);
// generate MetricMsg
MetricMsg metric;
metric.name = processing_time_topic_name + "/processing_time";
metric.value = std::to_string(processing_time);
metric.unit = "millisecond";
metrics_msg.metric_array.push_back(metric);
}

// create diagnostic array
DiagnosticArray diag_msg;
diag_msg.header.stamp = now();
diag_msg.status.push_back(status);

// publish
diag_pub_->publish(diag_msg);
metrics_msg.stamp = now();
metrics_pub_->publish(metrics_msg);
}
} // namespace autoware::processing_time_checker

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,18 @@

#include <rclcpp/rclcpp.hpp>

#include "diagnostic_msgs/msg/diagnostic_array.hpp"
#include "tier4_debug_msgs/msg/float64_stamped.hpp"
#include <tier4_debug_msgs/msg/float64_stamped.hpp>
#include <tier4_metric_msgs/msg/metric.hpp>
#include <tier4_metric_msgs/msg/metric_array.hpp>

#include <string>
#include <unordered_map>
#include <vector>

namespace autoware::processing_time_checker
{
using diagnostic_msgs::msg::DiagnosticArray;
using diagnostic_msgs::msg::DiagnosticStatus;
using MetricMsg = tier4_metric_msgs::msg::Metric;
using MetricArrayMsg = tier4_metric_msgs::msg::MetricArray;
using tier4_debug_msgs::msg::Float64Stamped;

class ProcessingTimeChecker : public rclcpp::Node
Expand All @@ -40,7 +41,7 @@ class ProcessingTimeChecker : public rclcpp::Node

rclcpp::TimerBase::SharedPtr timer_;

rclcpp::Publisher<DiagnosticArray>::SharedPtr diag_pub_;
rclcpp::Publisher<MetricArrayMsg>::SharedPtr metrics_pub_;
std::vector<rclcpp::Subscription<Float64Stamped>::SharedPtr> processing_time_subscribers_;

// topic name - module name
Expand Down

0 comments on commit 0e10eb5

Please sign in to comment.