Add ros2trace_analysis command and process/convert verbs

This commit is contained in:
Christophe Bedard 2019-10-13 14:39:21 -07:00
parent 42cf8a0a4a
commit f09cd960d6
17 changed files with 335 additions and 10 deletions

View file

@ -1,6 +1,6 @@
variables: variables:
DOCKER_DRIVER: overlay2 DOCKER_DRIVER: overlay2
PACKAGES_LIST: tracetools_analysis PACKAGES_LIST: tracetools_analysis ros2trace_analysis
base_image_id: registry.gitlab.com/micro-ros/ros_tracing/ci_base base_image_id: registry.gitlab.com/micro-ros/ros_tracing/ci_base
.global_artifacts: &global_artifacts .global_artifacts: &global_artifacts

3
ros2trace_analysis/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*~
*.pyc

View file

@ -0,0 +1,23 @@
<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format2.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="2">
<name>ros2trace_analysis</name>
<version>0.1.1</version>
<description>The trace analysis command for ROS 2 command line tools.</description>
<maintainer email="christophe.bedard@apex.ai">Christophe Bedard</maintainer>
<license>Apache 2.0</license>
<author email="christophe.bedard@apex.ai">Christophe Bedard</author>
<depend>ros2cli</depend>
<depend>tracetools_analysis</depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>ament_xmllint</test_depend>
<test_depend>python3-pytest</test_depend>
<export>
<build_type>ament_python</build_type>
</export>
</package>

View file

@ -0,0 +1,13 @@
# Copyright 2019 Apex.AI, 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.

View file

@ -0,0 +1,13 @@
# Copyright 2019 Apex.AI, 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.

View file

@ -0,0 +1,13 @@
# Copyright 2019 Apex.AI, 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.

View file

@ -0,0 +1,41 @@
# Copyright 2019 Apex.AI, 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.
"""Module for trace analysis command extension implementation."""
from ros2cli.command import add_subparsers
from ros2cli.command import CommandExtension
from ros2cli.verb import get_verb_extensions
class TraceAnalysisCommand(CommandExtension):
"""Analyze traces to extract useful execution data."""
def add_arguments(self, parser, cli_name):
self._subparser = parser
# get verb extensions and let them add their arguments
verb_extensions = get_verb_extensions('ros2trace_analysis.verb')
add_subparsers(
parser, cli_name, '_verb', verb_extensions, required=False)
def main(self, *, parser, args):
if not hasattr(args, '_verb'):
# in case no verb was passed
self._subparser.print_help()
return 0
extension = getattr(args, '_verb')
# call the verb's main method
return extension.main(args=args)

View file

@ -0,0 +1,13 @@
# Copyright 2019 Apex.AI, 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.

View file

@ -0,0 +1,30 @@
# Copyright 2019 Apex.AI, 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 ros2cli.verb import VerbExtension
from tracetools_analysis.convert import add_args
from tracetools_analysis.convert import convert
class ConvertVerb(VerbExtension):
"""Convert trace data to a file."""
def add_arguments(self, parser, cli_name):
add_args(parser)
def main(self, *, args):
return convert(
args.trace_directory,
args.output_file_name,
)

View file

@ -0,0 +1,30 @@
# Copyright 2019 Apex.AI, 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 ros2cli.verb import VerbExtension
from tracetools_analysis.process import add_args
from tracetools_analysis.process import process
class ProcessVerb(VerbExtension):
"""Process a file converted from a trace directory and output model data."""
def add_arguments(self, parser, cli_name):
add_args(parser)
def main(self, *, args):
return process(
args.input_path,
args.force_conversion,
)

View file

@ -0,0 +1,44 @@
from setuptools import find_packages
from setuptools import setup
package_name = 'ros2trace_analysis'
setup(
name=package_name,
version='0.1.1',
packages=find_packages(exclude=['test']),
data_files=[
('share/' + package_name, ['package.xml']),
],
install_requires=['ros2cli'],
zip_safe=True,
maintainer=(
'Christophe Bedard'
),
maintainer_email=(
'christophe.bedard@apex.ai'
),
author='Christophe Bedard',
author_email='christophe.bedard@apex.ai',
url='https://gitlab.com/micro-ROS/ros_tracing/tracetools_analysis',
keywords=[],
description='The trace analysis command for ROS 2 command line tools.',
long_description=(
'The package provides the trace analysis '
'command for the ROS 2 command line tools.'
),
license='Apache 2.0',
tests_require=['pytest'],
entry_points={
'ros2cli.command': [
f'trace-analysis = {package_name}.command.trace_analysis:TraceAnalysisCommand',
],
'ros2cli.extension_point': [
f'{package_name}.verb = {package_name}.verb:VerbExtension',
],
f'{package_name}.verb': [
f'convert = {package_name}.verb.convert:ConvertVerb',
f'process = {package_name}.verb.process:ProcessVerb',
],
}
)

View file

@ -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'

View file

@ -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'

View file

@ -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'

View file

@ -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'

View file

@ -18,6 +18,7 @@
import argparse import argparse
import os import os
import time import time
from typing import Optional
from tracetools_analysis.conversion import ctf from tracetools_analysis.conversion import ctf
@ -25,24 +26,28 @@ from tracetools_analysis.conversion import ctf
DEFAULT_CONVERT_FILE_NAME = 'converted' DEFAULT_CONVERT_FILE_NAME = 'converted'
def parse_args(): def add_args(parser: argparse.ArgumentParser) -> None:
parser = argparse.ArgumentParser(
description='Convert CTF trace data to a file.')
parser.add_argument( parser.add_argument(
'trace_directory', 'trace_directory',
help='the path to the main CTF trace directory') help='the path to the main trace directory')
parser.add_argument( parser.add_argument(
'-o', '--output-file-name', dest='output_file_name', '-o', '--output-file-name', dest='output_file_name',
default=DEFAULT_CONVERT_FILE_NAME, default=DEFAULT_CONVERT_FILE_NAME,
help='the name of the output file to generate, ' help='the name of the output file to generate, '
'under $trace_directory (default: %(default)s)') 'under $trace_directory (default: %(default)s)')
def parse_args():
parser = argparse.ArgumentParser(
description='Convert trace data to a file.')
add_args(parser)
return parser.parse_args() return parser.parse_args()
def convert( def convert(
trace_directory: str, trace_directory: str,
output_file_name: str = DEFAULT_CONVERT_FILE_NAME, output_file_name: str = DEFAULT_CONVERT_FILE_NAME,
) -> None: ) -> Optional[int]:
""" """
Convert trace directory to a file. Convert trace directory to a file.

View file

@ -19,6 +19,7 @@ import argparse
import os import os
import sys import sys
import time import time
from typing import Optional
from typing import Tuple from typing import Tuple
from tracetools_analysis.convert import convert from tracetools_analysis.convert import convert
@ -28,9 +29,7 @@ from tracetools_analysis.processor.ros2 import Ros2Handler
from tracetools_read.trace import is_trace_directory from tracetools_read.trace import is_trace_directory
def parse_args(): def add_args(parser: argparse.ArgumentParser) -> None:
parser = argparse.ArgumentParser(description='Process a file converted from a trace '
'directory and output model data.')
parser.add_argument( parser.add_argument(
'input_path', 'input_path',
help='the path to a converted file to import and process, ' help='the path to a converted file to import and process, '
@ -39,6 +38,12 @@ def parse_args():
'-f', '--force-conversion', dest='force_conversion', '-f', '--force-conversion', dest='force_conversion',
action='store_true', default=False, action='store_true', default=False,
help='re-convert trace directory even if converted file is found') help='re-convert trace directory even if converted file is found')
def parse_args():
parser = argparse.ArgumentParser(description='Process a file converted from a trace '
'directory and output model data.')
add_args(parser)
return parser.parse_args() return parser.parse_args()
@ -106,7 +111,7 @@ def inspect_input_path(
def process( def process(
input_path: str, input_path: str,
force_conversion: bool = False, force_conversion: bool = False,
) -> None: ) -> Optional[int]:
""" """
Process converted trace file. Process converted trace file.