From 0eea4ea1d038ed31d2320ce8815ecf0256a1a39b Mon Sep 17 00:00:00 2001 From: "Takagi, Isamu" Date: Wed, 20 Dec 2023 15:05:44 +0900 Subject: [PATCH 1/3] add dump tool Signed-off-by: Takagi, Isamu --- .../CMakeLists.txt | 5 + system/diagnostic_graph_aggregator/tool/dump | 95 +++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100755 system/diagnostic_graph_aggregator/tool/dump diff --git a/system/diagnostic_graph_aggregator/CMakeLists.txt b/system/diagnostic_graph_aggregator/CMakeLists.txt index 188b1509dfca0..152a466634bbc 100644 --- a/system/diagnostic_graph_aggregator/CMakeLists.txt +++ b/system/diagnostic_graph_aggregator/CMakeLists.txt @@ -38,4 +38,9 @@ if(BUILD_TESTING) target_include_directories(gtest_${PROJECT_NAME} PRIVATE src/common) endif() +install(PROGRAMS + tool/dump + DESTINATION lib/${PROJECT_NAME} +) + ament_auto_package(INSTALL_TO_SHARE config example launch) diff --git a/system/diagnostic_graph_aggregator/tool/dump b/system/diagnostic_graph_aggregator/tool/dump new file mode 100755 index 0000000000000..9b2e33b7958f3 --- /dev/null +++ b/system/diagnostic_graph_aggregator/tool/dump @@ -0,0 +1,95 @@ +#!/usr/bin/env python3 + +# Copyright 2023 The Autoware Contributors +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse + +from diagnostic_msgs.msg import DiagnosticStatus +import rclpy +import rclpy.node +from tier4_system_msgs.msg import DiagnosticGraph + + +def print_table(lines: list, header: list): + widths = [0 for _ in range(len(header))] + lines.insert(0, header) + for line in lines: + widths = map(max, widths, map(len, line)) + widths = list(widths) + lines.insert(0, ["-" * w for w in widths]) + lines.insert(2, ["-" * w for w in widths]) + for line in lines: + line = map(lambda v, w: f"{v:{w}}", line, widths) + line = " | ".join(line) + print(f"| {line} |") + + +def get_level_text(level: int): + if level == DiagnosticStatus.OK: + return "OK" + if level == DiagnosticStatus.WARN: + return "WARN" + if level == DiagnosticStatus.ERROR: + return "ERROR" + if level == DiagnosticStatus.SATLE: + return "SATLE" + return "-----" + + +class NodeData: + def __init__(self, index, node): + self.index = index + self._node = node + + @property + def level(self): + return get_level_text(self._node.status.level) + + @property + def name(self): + return self._node.status.name + + @property + def links(self): + return " ".join(str(link.index) for link in self._node.links) + + @property + def line(self): + return [str(self.index), self.level, self.name, self.links] + + +class DumpNode(rclpy.node.Node): + def __init__(self, args): + super().__init__("dump_diagnostic_graph") + self.sub = self.create_subscription(DiagnosticGraph, args.topic, self.callback, 1) + + def callback(self, msg): + nodes = [NodeData(index, node) for index, node in enumerate(msg.nodes)] + table = [node.line for node in nodes] + print_table(table, ["index", "level", "name", "links"]) + + +if __name__ == "__main__": + parser = argparse.ArgumentParser() + parser.add_argument("--topic", default="/diagnostics_graph") + parser.add_argument("--order", default="index") + args, unparsed = parser.parse_known_args() + + try: + rclpy.init(args=unparsed) + rclpy.spin(DumpNode(args)) + rclpy.shutdown() + except KeyboardInterrupt: + pass From 10396cb95a5865a016eb8e3edef7fd4228a68631 Mon Sep 17 00:00:00 2001 From: "Takagi, Isamu" Date: Thu, 15 Feb 2024 15:50:55 +0900 Subject: [PATCH 2/3] fix Signed-off-by: Takagi, Isamu --- system/diagnostic_graph_aggregator/tool/dump | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/system/diagnostic_graph_aggregator/tool/dump b/system/diagnostic_graph_aggregator/tool/dump index 9b2e33b7958f3..3e639cbce104d 100755 --- a/system/diagnostic_graph_aggregator/tool/dump +++ b/system/diagnostic_graph_aggregator/tool/dump @@ -1,6 +1,6 @@ #!/usr/bin/env python3 -# Copyright 2023 The Autoware Contributors +# Copyright 2024 The Autoware Contributors # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -43,8 +43,8 @@ def get_level_text(level: int): return "WARN" if level == DiagnosticStatus.ERROR: return "ERROR" - if level == DiagnosticStatus.SATLE: - return "SATLE" + if level == DiagnosticStatus.STALE: + return "STALE" return "-----" From d69d46eba624b585fbce631bc3b8464538ea6f00 Mon Sep 17 00:00:00 2001 From: "Takagi, Isamu" Date: Tue, 20 Feb 2024 21:01:58 +0900 Subject: [PATCH 3/3] rename script to apply the spell check dict Signed-off-by: Takagi, Isamu --- system/diagnostic_graph_aggregator/CMakeLists.txt | 3 ++- .../diagnostic_graph_aggregator/{tool/dump => script/dump.py} | 0 2 files changed, 2 insertions(+), 1 deletion(-) rename system/diagnostic_graph_aggregator/{tool/dump => script/dump.py} (100%) diff --git a/system/diagnostic_graph_aggregator/CMakeLists.txt b/system/diagnostic_graph_aggregator/CMakeLists.txt index 152a466634bbc..c4a67032541b2 100644 --- a/system/diagnostic_graph_aggregator/CMakeLists.txt +++ b/system/diagnostic_graph_aggregator/CMakeLists.txt @@ -39,7 +39,8 @@ if(BUILD_TESTING) endif() install(PROGRAMS - tool/dump + script/dump.py + RENAME dump DESTINATION lib/${PROJECT_NAME} ) diff --git a/system/diagnostic_graph_aggregator/tool/dump b/system/diagnostic_graph_aggregator/script/dump.py similarity index 100% rename from system/diagnostic_graph_aggregator/tool/dump rename to system/diagnostic_graph_aggregator/script/dump.py