Skip to content

Commit

Permalink
Merge branch 'ros2:rolling' into patch-7
Browse files Browse the repository at this point in the history
  • Loading branch information
mosfet80 authored Aug 9, 2024
2 parents 6f52120 + 27a6b60 commit 349df5c
Show file tree
Hide file tree
Showing 17 changed files with 126 additions and 65 deletions.
28 changes: 15 additions & 13 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ jobs:
name: ament_${{ matrix.linter }}
runs-on: ubuntu-latest
container:
image: rostooling/setup-ros-docker:ubuntu-focal-ros-rolling-ros-base-latest
image: rostooling/setup-ros-docker:ubuntu-noble-ros-rolling-ros-base-latest
strategy:
fail-fast: false
matrix:
linter: [copyright, xmllint]
steps:
- uses: actions/checkout@v2
- uses: ros-tooling/action-ros-lint@v0.1
- uses: actions/checkout@v4
- uses: ros-tooling/action-ros-lint@0.1.3
with:
linter: ${{ matrix.linter }}
distribution: rolling
Expand Down Expand Up @@ -43,10 +43,11 @@ jobs:
strategy:
fail-fast: false
matrix:
linter: [cppcheck, cpplint, uncrustify]
# We exclude cppcheck due to https://github.com/ament/ament_lint/pull/345
linter: [cpplint, uncrustify]
steps:
- uses: actions/checkout@v2
- uses: ros-tooling/action-ros-lint@v0.1
- uses: actions/checkout@v4
- uses: ros-tooling/action-ros-lint@0.1.3
with:
linter: ${{ matrix.linter }}
distribution: rolling
Expand All @@ -67,17 +68,18 @@ jobs:
name: ament_${{ matrix.linter }}
runs-on: ubuntu-latest
container:
image: rostooling/setup-ros-docker:ubuntu-focal-ros-rolling-ros-base-latest
image: rostooling/setup-ros-docker:ubuntu-noble-ros-rolling-ros-base-latest
strategy:
fail-fast: false
matrix:
linter: [cppcheck, cpplint, clang_format]
# We exclude cppcheck due to https://github.com/ament/ament_lint/pull/345
linter: [cpplint, clang_format]
include:
- linter: clang_format
arguments: "--config rosbag2_storage_mcap/.clang-format"
steps:
- uses: actions/checkout@v2
- uses: ros-tooling/action-ros-lint@v0.1
- uses: actions/checkout@v4
- uses: ros-tooling/action-ros-lint@0.1.3
with:
linter: ${{ matrix.linter }}
arguments: ${{ matrix.arguments }}
Expand All @@ -88,14 +90,14 @@ jobs:
name: ament_${{ matrix.linter }}
runs-on: ubuntu-latest
container:
image: rostooling/setup-ros-docker:ubuntu-focal-ros-rolling-ros-base-latest
image: rostooling/setup-ros-docker:ubuntu-noble-ros-rolling-ros-base-latest
strategy:
fail-fast: false
matrix:
linter: [pep257, flake8]
steps:
- uses: actions/checkout@v2
- uses: ros-tooling/action-ros-lint@v0.1
- uses: actions/checkout@v4
- uses: ros-tooling/action-ros-lint@0.1.3
with:
linter: ${{ matrix.linter }}
distribution: rolling
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
build_and_test:
runs-on: ubuntu-latest
container:
image: rostooling/setup-ros-docker:ubuntu-jammy-latest
image: rostooling/setup-ros-docker:ubuntu-noble-latest
steps:
- name: Build and run tests
id: action-ros-ci
Expand Down Expand Up @@ -91,8 +91,7 @@ jobs:
- name: Is regeneration of Python stubs required?
run: |
rosbag2_path=$(colcon list -p --packages-select rosbag2)/..
sudo pip uninstall -y mypy
sudo apt update && sudo apt -y install mypy=0.942-1ubuntu1
sudo apt update && sudo apt -y install mypy
source install/setup.sh
stubgen -p rosbag2_py -o ${rosbag2_path}/rosbag2_py
cd ${rosbag2_path}
Expand Down
12 changes: 12 additions & 0 deletions ros2bag/ros2bag/verb/record.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ def add_recorder_arguments(parser: ArgumentParser) -> None:
'--compression-threads', type=int, default=0,
help='Number of files or messages that may be compressed in parallel. '
'Default is %(default)d, which will be interpreted as the number of CPU cores.')
parser.add_argument(
'--compression-threads-priority', type=int, default=0,
help='Compression threads scheduling priority. \nFor Windows the valid values are:'
' THREAD_PRIORITY_LOWEST=-2, THREAD_PRIORITY_BELOW_NORMAL=-1 and'
' THREAD_PRIORITY_NORMAL=0. Please refer to'
' https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-setthreadpriority' # noqa E501
' for details.\n'
'For POSIX compatible OSes this is the "nice" value. The nice value range is'
' -20 to +19 where -20 is highest, 0 default and +19 is lowest.'
' Please refer to https://man7.org/linux/man-pages/man2/nice.2.html for details.\n'
'Default is %(default)d.')
parser.add_argument(
'--compression-mode', type=str, default='none',
choices=['none', 'file', 'message'],
Expand Down Expand Up @@ -338,6 +349,7 @@ def main(self, *, args): # noqa: D102
record_options.compression_format = args.compression_format
record_options.compression_queue_size = args.compression_queue_size
record_options.compression_threads = args.compression_threads
record_options.compression_threads_priority = args.compression_threads_priority
record_options.topic_qos_profile_overrides = qos_profile_overrides
record_options.include_hidden_topics = args.include_hidden_topics
record_options.include_unpublished_topics = args.include_unpublished_topics
Expand Down
55 changes: 55 additions & 0 deletions ros2bag/test/test_record_with_compression_thread_priority.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
# Copyright 2024 Open Source Robotics Foundation, Inc.
#
# 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.

from pathlib import Path
import tempfile

import unittest

from launch import LaunchDescription
from launch.actions import ExecuteProcess

import launch_testing
import launch_testing.actions

import pytest


@pytest.mark.launch_test
def generate_test_description():
tmp_dir_name = tempfile.mkdtemp()
output_path = Path(tmp_dir_name) / 'ros2bag_test_record_with_compression_thread_priority'
record_process = ExecuteProcess(
cmd=['ros2', 'bag', 'record', '-a', '--output', output_path.as_posix(),
'--log-level', 'debug', '--compression-threads-priority', '1',
'--compression-mode', 'file', '--compression-format', 'zstd'],
name='ros2bag-cli',
output='screen',
)

return LaunchDescription([
record_process,
launch_testing.actions.ReadyToTest()
]), locals()


class TestRecordWithCompressionThreadPriority(unittest.TestCase):

def test_priority_propagated_into_compression_thread(
self, record_process, proc_output):
proc_output.assertWaitFor(
'Setting compression thread priority to 1',
timeout=45,
process=record_process
)
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,9 @@ struct CompressionOptions
/// \brief // The number of compression threads
uint64_t compression_threads{0};
/// \brief If set, the compression thread(s) will try to set the given priority for itself
/// For Windows the valid values are: THREAD_PRIORITY_LOWEST, THREAD_PRIORITY_BELOW_NORMAL and
/// THREAD_PRIORITY_NORMAL. For POSIX compatible OSes this is the "nice" value.
/// For Windows the valid values are: THREAD_PRIORITY_LOWEST=-2, THREAD_PRIORITY_BELOW_NORMAL=-1
/// and THREAD_PRIORITY_NORMAL=0. For POSIX compatible OSes this is the "nice" value.
/// The nice value range is -20 to +19 where -20 is highest, 0 default and +19 is lowest.
std::optional<int32_t> thread_priority;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ SequentialCompressionWriter::~SequentialCompressionWriter()
void SequentialCompressionWriter::compression_thread_fn()
{
if (compression_options_.thread_priority) {
ROSBAG2_COMPRESSION_LOG_DEBUG_STREAM(
"Setting compression thread priority to "
<< *compression_options_.thread_priority);
#ifdef _WIN32
// This must match THREAD_PRIORITY_IDLE, THREAD_PRIORITY_LOWEST...
int wanted_thread_priority = *compression_options_.thread_priority;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ class SequentialCompressionWriterTest : public TestWithParam<uint64_t>

const uint64_t kDefaultCompressionQueueSize = 1;
const uint64_t kDefaultCompressionQueueThreads = 4;
const std::optional<int32_t> kDefaultCompressionQueueThreadsPriority = std::nullopt;
const int32_t kDefaultCompressionQueueThreadsPriority = 0;
};

TEST_F(SequentialCompressionWriterTest, open_throws_on_empty_storage_options_uri)
Expand Down
7 changes: 6 additions & 1 deletion rosbag2_py/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ source install/setup.sh
# Make sure rosbag2_py can be imported
python3 -c 'import rosbag2_py'
sudo apt update && sudo apt install mypy=0.942-1ubuntu1
# Ubuntu 24.04
sudo apt update && sudo apt install mypy
# Older Ubuntu
# pip3 install -U mypy==1.9
cd <rosbag2 git repo>
stubgen -p rosbag2_py -o rosbag2_py
```
2 changes: 2 additions & 0 deletions rosbag2_py/rosbag2_py/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ from rosbag2_py._reindexer import Reindexer as Reindexer
from rosbag2_py._storage import BagMetadata as BagMetadata, ConverterOptions as ConverterOptions, FileInformation as FileInformation, MessageDefinition as MessageDefinition, MetadataIo as MetadataIo, ReadOrder as ReadOrder, ReadOrderSortBy as ReadOrderSortBy, StorageFilter as StorageFilter, StorageOptions as StorageOptions, TopicInformation as TopicInformation, TopicMetadata as TopicMetadata, get_default_storage_id as get_default_storage_id, to_rclcpp_qos_vector as to_rclcpp_qos_vector
from rosbag2_py._transport import PlayOptions as PlayOptions, Player as Player, RecordOptions as RecordOptions, Recorder as Recorder, ServiceRequestsSource as ServiceRequestsSource, bag_rewrite as bag_rewrite
from rosbag2_py._writer import SequentialCompressionWriter as SequentialCompressionWriter, SequentialWriter as SequentialWriter, get_registered_compressors as get_registered_compressors, get_registered_serializers as get_registered_serializers, get_registered_writers as get_registered_writers

__all__ = ['bag_rewrite', 'CompressionMode', 'CompressionOptions', 'compression_mode_from_string', 'compression_mode_to_string', 'ConverterOptions', 'FileInformation', 'get_default_storage_id', 'get_registered_readers', 'get_registered_writers', 'get_registered_compressors', 'get_registered_serializers', 'to_rclcpp_qos_vector', 'ReadOrder', 'ReadOrderSortBy', 'Reindexer', 'SequentialCompressionReader', 'SequentialCompressionWriter', 'SequentialReader', 'SequentialWriter', 'StorageFilter', 'StorageOptions', 'TopicMetadata', 'TopicInformation', 'BagMetadata', 'MessageDefinition', 'MetadataIo', 'Info', 'Player', 'PlayOptions', 'ServiceRequestsSource', 'Recorder', 'RecordOptions', 'LocalMessageDefinitionSource']
3 changes: 0 additions & 3 deletions rosbag2_py/rosbag2_py/_compression_options.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,17 @@ MESSAGE: CompressionMode
NONE: CompressionMode

class CompressionMode:
__doc__: ClassVar[str] = ... # read-only
__members__: ClassVar[dict] = ... # read-only
FILE: ClassVar[CompressionMode] = ...
MESSAGE: ClassVar[CompressionMode] = ...
NONE: ClassVar[CompressionMode] = ...
__entries: ClassVar[dict] = ...
def __init__(self, value: int) -> None: ...
def __eq__(self, other: object) -> bool: ...
def __getstate__(self) -> int: ...
def __hash__(self) -> int: ...
def __index__(self) -> int: ...
def __int__(self) -> int: ...
def __ne__(self, other: object) -> bool: ...
def __setstate__(self, state: int) -> None: ...
@property
def name(self) -> str: ...
@property
Expand Down
4 changes: 1 addition & 3 deletions rosbag2_py/rosbag2_py/_message_definitions.pyi
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from typing import Any

class LocalMessageDefinitionSource:
def __init__(self) -> None: ...
def get_full_text(self, *args, **kwargs) -> Any: ...
def get_full_text(self, *args, **kwargs): ...
14 changes: 6 additions & 8 deletions rosbag2_py/rosbag2_py/_reader.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
from typing import Any

class SequentialCompressionReader:
def __init__(self) -> None: ...
def get_all_message_definitions(self, *args, **kwargs) -> Any: ...
def get_all_topics_and_types(self, *args, **kwargs) -> Any: ...
def get_metadata(self, *args, **kwargs) -> Any: ...
def get_all_message_definitions(self, *args, **kwargs): ...
def get_all_topics_and_types(self, *args, **kwargs): ...
def get_metadata(self, *args, **kwargs): ...
def has_next(self) -> bool: ...
def open(self, arg0, arg1) -> None: ...
def open_uri(self, arg0: str) -> None: ...
Expand All @@ -16,9 +14,9 @@ class SequentialCompressionReader:

class SequentialReader:
def __init__(self) -> None: ...
def get_all_message_definitions(self, *args, **kwargs) -> Any: ...
def get_all_topics_and_types(self, *args, **kwargs) -> Any: ...
def get_metadata(self, *args, **kwargs) -> Any: ...
def get_all_message_definitions(self, *args, **kwargs): ...
def get_all_topics_and_types(self, *args, **kwargs): ...
def get_metadata(self, *args, **kwargs): ...
def has_next(self) -> bool: ...
def open(self, arg0, arg1) -> None: ...
def open_uri(self, arg0: str) -> None: ...
Expand Down
Loading

0 comments on commit 349df5c

Please sign in to comment.