commit 9eb99e7d9d9371ae6eb93de2625c8ada7753e96a Author: Christophe Bedard Date: Sun Jun 23 17:44:02 2019 +0200 Add basic ros2tracee diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eef29c1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +*~ +*.pyc + diff --git a/package.xml b/package.xml new file mode 100644 index 0000000..eb4bcfd --- /dev/null +++ b/package.xml @@ -0,0 +1,25 @@ + + + + ros2trace + 0.0.1 + + The trace command for ROS 2 command line tools. + + Christophe Bedard + TODO + Christophe Bedard + + ros2cli + tracetools_trace + + ament_copyright + ament_flake8 + ament_pep257 + ament_xmllint + python3-pytest + + + ament_python + + diff --git a/ros2trace/__init__.py b/ros2trace/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ros2trace/api/__init__.py b/ros2trace/api/__init__.py new file mode 100644 index 0000000..63fa4c7 --- /dev/null +++ b/ros2trace/api/__init__.py @@ -0,0 +1,42 @@ +import os + +from tracetools_trace.tools import args +from tracetools_trace.tools import lttng + + +def add_trace_arguments(parser): + args.add_arguments(parser) + + +def init(args): + session_name = args.session_name + base_path = args.path + full_path = os.path.join(base_path, session_name) + ros_events = args.events_ust + kernel_events = args.events_kernel + + ust_enabled = len(ros_events) > 0 + kernel_enabled = len(kernel_events) > 0 + if ust_enabled: + print(f'UST tracing enabled ({len(ros_events)} events)') + if args.list: + print(f'\tevents: {ros_events}') + else: + print('UST tracing disabled') + if kernel_enabled: + print(f'kernel tracing enabled ({len(kernel_events)} events)') + if args.list: + print(f'\tevents: {kernel_events}') + else: + print('kernel tracing disabled') + + print(f'writting tracing session to: {full_path}') + input('press enter to start...') + lttng.lttng_init(session_name, full_path, ros_events=ros_events, kernel_events=kernel_events) + + +def fini(args): + session_name = args.session_name + input('press enter to stop...') + print('stopping & destroying tracing session') + lttng.lttng_fini(session_name) diff --git a/ros2trace/command/__init__.py b/ros2trace/command/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/ros2trace/command/trace.py b/ros2trace/command/trace.py new file mode 100644 index 0000000..1e5841e --- /dev/null +++ b/ros2trace/command/trace.py @@ -0,0 +1,16 @@ +from ros2cli.command import CommandExtension +from ros2trace.api import add_trace_arguments +from ros2trace.api import init +from ros2trace.api import fini + + +class TraceCommand(CommandExtension): + """Trace ROS.""" + + def add_arguments(self, parser, cli_name): + add_trace_arguments(parser) + + def main(self, *, parser, args): + init(args) + fini(args) + return 0 diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..d943b0a --- /dev/null +++ b/setup.py @@ -0,0 +1,26 @@ +from setuptools import find_packages +from setuptools import setup + +setup( + name='ros2trace', + version='0.0.1', + packages=find_packages(exclude=['test']), + install_requires=['ros2cli'], + zip_safe=True, + maintainer='Christophe Bedard', + maintainer_email='fixed-term.christophe.bourquebedard@de.bosch.com', + author='Christophe Bedard', + author_email='fixed-term.christophe.bourquebedard@de.bosch.com', + # url=', + keywords=[], + description='The run command for ROS 2 command line tools.', + long_description="""\ +The package provides the trace command for the ROS 2 command line tools.""", + license='TODO', + tests_require=['pytest'], + entry_points={ + 'ros2cli.command': [ + 'trace = ros2trace.command.trace:TraceCommand', + ], + } +) diff --git a/test/test_copyright.py b/test/test_copyright.py new file mode 100644 index 0000000..cf0fae3 --- /dev/null +++ b/test/test_copyright.py @@ -0,0 +1,23 @@ +# Copyright 2017 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 ament_copyright.main import main +import pytest + + +@pytest.mark.copyright +@pytest.mark.linter +def test_copyright(): + rc = main(argv=['.', 'test']) + assert rc == 0, 'Found errors' diff --git a/test/test_flake8.py b/test/test_flake8.py new file mode 100644 index 0000000..eff8299 --- /dev/null +++ b/test/test_flake8.py @@ -0,0 +1,23 @@ +# Copyright 2017 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 ament_flake8.main import main +import pytest + + +@pytest.mark.flake8 +@pytest.mark.linter +def test_flake8(): + rc = main(argv=[]) + assert rc == 0, 'Found errors' diff --git a/test/test_pep257.py b/test/test_pep257.py new file mode 100644 index 0000000..0e38a6c --- /dev/null +++ b/test/test_pep257.py @@ -0,0 +1,23 @@ +# Copyright 2017 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 ament_pep257.main import main +import pytest + + +@pytest.mark.linter +@pytest.mark.pep257 +def test_pep257(): + rc = main(argv=[]) + assert rc == 0, 'Found code style errors / warnings' diff --git a/test/test_xmllint.py b/test/test_xmllint.py new file mode 100644 index 0000000..f46285e --- /dev/null +++ b/test/test_xmllint.py @@ -0,0 +1,23 @@ +# Copyright 2019 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 ament_xmllint.main import main +import pytest + + +@pytest.mark.linter +@pytest.mark.xmllint +def test_xmllint(): + rc = main(argv=[]) + assert rc == 0, 'Found errors'