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={
|
||||
'console_scripts': [
|
||||
f'analyze = {package_name}.analyze:main',
|
||||
f'convert = {package_name}.convert: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.
|
||||
|
||||
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.
|
||||
"""
|
||||
return []
|
||||
|
@ -104,6 +104,7 @@ class EventHandler(Dependant):
|
|||
Base event handling class.
|
||||
|
||||
Provides handling functions for some events, depending on the name.
|
||||
To be subclassed.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
@ -119,7 +120,8 @@ class EventHandler(Dependant):
|
|||
|
||||
: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.processor = None
|
||||
|
||||
|
|
|
@ -37,20 +37,8 @@ class ProfileHandler(EventHandler):
|
|||
* sched_switch
|
||||
"""
|
||||
|
||||
FUNCTIONS = {
|
||||
'get_next_ready_executable': [],
|
||||
'wait_for_work': [
|
||||
'collect_entities',
|
||||
'add_handles_to_wait_set',
|
||||
'rmw_wait',
|
||||
'remove_null_handles',
|
||||
],
|
||||
}
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
*,
|
||||
functions: Dict[str, List[str]] = FUNCTIONS,
|
||||
**kwargs,
|
||||
) -> None:
|
||||
handler_map = {
|
||||
|
@ -64,7 +52,6 @@ class ProfileHandler(EventHandler):
|
|||
super().__init__(handler_map=handler_map, **kwargs)
|
||||
|
||||
self._data = ProfileDataModel()
|
||||
self.functions = functions
|
||||
|
||||
# Temporary buffers
|
||||
# tid ->
|
||||
|
@ -86,7 +73,7 @@ class ProfileHandler(EventHandler):
|
|||
self, event: Dict, metadata: EventMetadata
|
||||
) -> None:
|
||||
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')
|
||||
if prev_tid in self._current_funcs:
|
||||
# Increment durations using last start timestamp
|
||||
|
@ -109,14 +96,12 @@ class ProfileHandler(EventHandler):
|
|||
) -> None:
|
||||
function_name = self._get_function_name(event)
|
||||
# Push function data to stack, setting both timestamps to now
|
||||
self._current_funcs[metadata.tid].append(
|
||||
[
|
||||
function_name,
|
||||
metadata.timestamp,
|
||||
metadata.timestamp,
|
||||
0,
|
||||
]
|
||||
)
|
||||
self._current_funcs[metadata.tid].append([
|
||||
function_name,
|
||||
metadata.timestamp,
|
||||
metadata.timestamp,
|
||||
0,
|
||||
])
|
||||
|
||||
def _handle_function_exit(
|
||||
self, event: Dict, metadata: EventMetadata
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue