From 6f234b412e61107e64d750fdc703953dec65795e Mon Sep 17 00:00:00 2001 From: h-suzuki-isp <146712054+h-suzuki-isp@users.noreply.github.com> Date: Tue, 12 Dec 2023 15:28:04 +0900 Subject: [PATCH] fix: error when drawn empty communication (#445) * fix: drawn empty dataframe Signed-off-by: h-suzuki * fix: spelling miss * feat: add NOTE comment Signed-off-by: h-suzuki * fix: refactor NOTE comment Signed-off-by: h-suzuki --------- Signed-off-by: h-suzuki --- .../infra/lttng/records_provider_lttng.py | 11 +++++++++++ .../infra/lttng/test_latency_definitions.py | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/caret_analyze/infra/lttng/records_provider_lttng.py b/src/caret_analyze/infra/lttng/records_provider_lttng.py index f5ee65b01..1e4e2d93c 100644 --- a/src/caret_analyze/infra/lttng/records_provider_lttng.py +++ b/src/caret_analyze/infra/lttng/records_provider_lttng.py @@ -1613,6 +1613,17 @@ def publish_records( ColumnValue(COLUMN_NAME.SOURCE_TIMESTAMP), ] ) + # NOTE: There is concern that publisher_handles has only one publisher_handle. + if not set(publisher_handles) & set(grouped_records.keys()): + return RecordsFactory.create_instance( + None, + columns=[ + ColumnValue(COLUMN_NAME.PUBLISHER_HANDLE), + ColumnValue(COLUMN_NAME.RCLCPP_PUBLISH_TIMESTAMP), + ColumnValue(COLUMN_NAME.MESSAGE_TIMESTAMP), + ColumnValue(COLUMN_NAME.SOURCE_TIMESTAMP), + ] + ) sample_records = grouped_records[publisher_handles[0]] column_values = Columns.from_str(sample_records.columns).to_value() pub_records = RecordsFactory.create_instance(None, columns=column_values) diff --git a/src/test/infra/lttng/test_latency_definitions.py b/src/test/infra/lttng/test_latency_definitions.py index 16950e46b..ace619204 100644 --- a/src/test/infra/lttng/test_latency_definitions.py +++ b/src/test/infra/lttng/test_latency_definitions.py @@ -816,6 +816,24 @@ def test_generic_publisher( assert generic_df.equals(generic_df_expect) + # non_communication + non_communicate_pub_handle = 20 + publisher_lttng_mock = create_publisher_lttng(non_communicate_pub_handle) + publisher_struct_mock = create_publisher_struct('pub_topic') + setup_bridge_get_publisher(publisher_struct_mock, [publisher_lttng_mock]) + pub_records = provider.publish_records(publisher_struct_mock) + pub_df = pub_records.to_dataframe() + pub_df_expect = pd.DataFrame( + [], + columns=[ + f'{publisher_struct_mock.topic_name}/rclcpp_publish_timestamp', + f'{publisher_struct_mock.topic_name}/message_timestamp', + f'{publisher_struct_mock.topic_name}/source_timestamp', + ], + dtype='Int64' + ) + assert pub_df.equals(pub_df_expect) + class TestSubscriptionRecords: