From 2002190ade430b3253278abd212265b1851c56bd Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Fri, 2 Aug 2019 13:04:24 +0200 Subject: [PATCH] Extract non-ROS analyses to an 'analyze' entrypoint --- tracetools_analysis/setup.py | 1 + .../tracetools_analysis/analyze.py | 54 +++++++++++++++++++ .../tracetools_analysis/process.py | 10 +--- 3 files changed, 57 insertions(+), 8 deletions(-) create mode 100644 tracetools_analysis/tracetools_analysis/analyze.py diff --git a/tracetools_analysis/setup.py b/tracetools_analysis/setup.py index 3187757..fb55e12 100644 --- a/tracetools_analysis/setup.py +++ b/tracetools_analysis/setup.py @@ -36,6 +36,7 @@ setup( ), entry_points={ 'console_scripts': [ + f'analyze = {package_name}.analyze:main', f'convert = {package_name}.convert:main', f'process = {package_name}.process:main', ], diff --git a/tracetools_analysis/tracetools_analysis/analyze.py b/tracetools_analysis/tracetools_analysis/analyze.py new file mode 100644 index 0000000..02a28db --- /dev/null +++ b/tracetools_analysis/tracetools_analysis/analyze.py @@ -0,0 +1,54 @@ +#!/usr/bin/env python3 +# Copyright 2019 Robert Bosch GmbH +# +# 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. + +"""Entrypoint/script for analysis.""" + +import argparse +import time + +from tracetools_analysis.loading import load_pickle +from tracetools_analysis.processor.cpu_time import CpuTimeHandler +from tracetools_analysis.processor.profile import ProfileHandler +from tracetools_analysis.processor.ros2 import Ros2Handler +from tracetools_analysis.utils import ProfileDataModelUtil + + +def parse_args(): + parser = argparse.ArgumentParser(description='Process a pickle file generated ' + 'from tracing and analyze the data.') + parser.add_argument('pickle_file', help='the pickle file to import') + return parser.parse_args() + + +def main(): + args = parse_args() + pickle_filename = args.pickle_file + + start_time = time.time() + + events = load_pickle(pickle_filename) + + # cpu_handler = CpuTimeHandler.process(events) + profile_handler = ProfileHandler.process(events) + + time_diff = time.time() - start_time + print(f'processed {len(events)} events in {time_diff * 1000:.2f} ms') + + # cpu_handler.get_data_model().print_model() + profile_handler.get_data_model().print_model() + util = ProfileDataModelUtil(profile_handler.get_data_model()) + print(util.get_tids()) + util.get_stats(12616) + print(util.get_call_tree(12616)) diff --git a/tracetools_analysis/tracetools_analysis/process.py b/tracetools_analysis/tracetools_analysis/process.py index 8c407b4..2fc64ff 100644 --- a/tracetools_analysis/tracetools_analysis/process.py +++ b/tracetools_analysis/tracetools_analysis/process.py @@ -19,8 +19,6 @@ import argparse import time from tracetools_analysis.loading import load_pickle -from tracetools_analysis.processor.cpu_time import CpuTimeHandler -from tracetools_analysis.processor.profile import ProfileHandler from tracetools_analysis.processor.ros2 import Ros2Handler @@ -38,13 +36,9 @@ def main(): start_time = time.time() events = load_pickle(pickle_filename) - # ros2_handler = Ros2Handler.process(events) - # cpu_handler = CpuTimeHandler.process(events) - profile_handler = ProfileHandler.process(events) + ros2_handler = Ros2Handler.process(events) time_diff = time.time() - start_time print(f'processed {len(events)} events in {time_diff * 1000:.2f} ms') - # ros2_handler.get_data_model().print_model() - # cpu_handler.get_data_model().print_model() - profile_handler.get_data_model().print_model() + ros2_handler.get_data_model().print_model()