Cleanup and format
This commit is contained in:
parent
8080bee2a3
commit
41a7a95fd4
4 changed files with 11 additions and 76 deletions
|
@ -39,7 +39,6 @@ setup(
|
||||||
),
|
),
|
||||||
entry_points={
|
entry_points={
|
||||||
'console_scripts': [
|
'console_scripts': [
|
||||||
f'analyze = {package_name}.analyze:main',
|
|
||||||
f'convert = {package_name}.convert:main',
|
f'convert = {package_name}.convert:main',
|
||||||
f'process = {package_name}.process:main',
|
f'process = {package_name}.process:main',
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
#!/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 import Processor
|
|
||||||
from tracetools_analysis.processor.profile import ProfileHandler
|
|
||||||
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)
|
|
||||||
|
|
||||||
profile_handler = ProfileHandler()
|
|
||||||
processor = Processor(profile_handler, somestring='aa')
|
|
||||||
processor.process(events)
|
|
||||||
|
|
||||||
time_diff = time.time() - start_time
|
|
||||||
print(f'processed {len(events)} events in {time_diff * 1000:.2f} ms')
|
|
||||||
|
|
||||||
profile_handler.get_data_model().print_model()
|
|
||||||
util = ProfileDataModelUtil(profile_handler.get_data_model())
|
|
||||||
print(util.get_tids())
|
|
|
@ -93,7 +93,7 @@ class Dependant():
|
||||||
"""
|
"""
|
||||||
Get the dependencies that should also exist along with this current one.
|
Get the dependencies that should also exist along with this current one.
|
||||||
|
|
||||||
Subclasses should override this method if they want to declare dependencies
|
Subclasses should override this method if they want to declare dependencies.
|
||||||
Default: no dependencies.
|
Default: no dependencies.
|
||||||
"""
|
"""
|
||||||
return []
|
return []
|
||||||
|
@ -104,6 +104,7 @@ class EventHandler(Dependant):
|
||||||
Base event handling class.
|
Base event handling class.
|
||||||
|
|
||||||
Provides handling functions for some events, depending on the name.
|
Provides handling functions for some events, depending on the name.
|
||||||
|
To be subclassed.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
@ -119,7 +120,8 @@ class EventHandler(Dependant):
|
||||||
|
|
||||||
:param handler_map: the mapping from event name to handling method
|
:param handler_map: the mapping from event name to handling method
|
||||||
"""
|
"""
|
||||||
assert handler_map is not None and len(handler_map) > 0, f'empty map: {handler_map}'
|
assert handler_map is not None and len(handler_map) > 0, \
|
||||||
|
f'empty map: {self.__class__.__name__}'
|
||||||
self._handler_map = handler_map
|
self._handler_map = handler_map
|
||||||
self.processor = None
|
self.processor = None
|
||||||
|
|
||||||
|
|
|
@ -37,20 +37,8 @@ class ProfileHandler(EventHandler):
|
||||||
* sched_switch
|
* sched_switch
|
||||||
"""
|
"""
|
||||||
|
|
||||||
FUNCTIONS = {
|
|
||||||
'get_next_ready_executable': [],
|
|
||||||
'wait_for_work': [
|
|
||||||
'collect_entities',
|
|
||||||
'add_handles_to_wait_set',
|
|
||||||
'rmw_wait',
|
|
||||||
'remove_null_handles',
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
*,
|
|
||||||
functions: Dict[str, List[str]] = FUNCTIONS,
|
|
||||||
**kwargs,
|
**kwargs,
|
||||||
) -> None:
|
) -> None:
|
||||||
handler_map = {
|
handler_map = {
|
||||||
|
@ -64,7 +52,6 @@ class ProfileHandler(EventHandler):
|
||||||
super().__init__(handler_map=handler_map, **kwargs)
|
super().__init__(handler_map=handler_map, **kwargs)
|
||||||
|
|
||||||
self._data = ProfileDataModel()
|
self._data = ProfileDataModel()
|
||||||
self.functions = functions
|
|
||||||
|
|
||||||
# Temporary buffers
|
# Temporary buffers
|
||||||
# tid ->
|
# tid ->
|
||||||
|
@ -86,7 +73,7 @@ class ProfileHandler(EventHandler):
|
||||||
self, event: Dict, metadata: EventMetadata
|
self, event: Dict, metadata: EventMetadata
|
||||||
) -> None:
|
) -> None:
|
||||||
timestamp = metadata.timestamp
|
timestamp = metadata.timestamp
|
||||||
# If function(s) currently running stop executing
|
# If function(s) currently running stop(s) executing
|
||||||
prev_tid = get_field(event, 'prev_tid')
|
prev_tid = get_field(event, 'prev_tid')
|
||||||
if prev_tid in self._current_funcs:
|
if prev_tid in self._current_funcs:
|
||||||
# Increment durations using last start timestamp
|
# Increment durations using last start timestamp
|
||||||
|
@ -109,14 +96,12 @@ class ProfileHandler(EventHandler):
|
||||||
) -> None:
|
) -> None:
|
||||||
function_name = self._get_function_name(event)
|
function_name = self._get_function_name(event)
|
||||||
# Push function data to stack, setting both timestamps to now
|
# Push function data to stack, setting both timestamps to now
|
||||||
self._current_funcs[metadata.tid].append(
|
self._current_funcs[metadata.tid].append([
|
||||||
[
|
function_name,
|
||||||
function_name,
|
metadata.timestamp,
|
||||||
metadata.timestamp,
|
metadata.timestamp,
|
||||||
metadata.timestamp,
|
0,
|
||||||
0,
|
])
|
||||||
]
|
|
||||||
)
|
|
||||||
|
|
||||||
def _handle_function_exit(
|
def _handle_function_exit(
|
||||||
self, event: Dict, metadata: EventMetadata
|
self, event: Dict, metadata: EventMetadata
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue