Merge branch '4-process-symbols-to-make-them-more-readable' into 'master'

Resolve "Process symbols to make them more readable"

Closes #4

See merge request micro-ROS/ros_tracing/tracetools_analysis!7
This commit is contained in:
Christophe Bedard 2019-07-09 13:04:47 +00:00
commit a22532f3f8
2 changed files with 73 additions and 14 deletions

File diff suppressed because one or more lines are too long

View file

@ -39,6 +39,61 @@ class DataModelUtil():
""" """
self._data = data_model self._data = data_model
def _prettify(self, original: str) -> str:
"""
Process symbol to make it more readable.
* remove std::allocator
* remove std::default_delete
* bind object: remove placeholder
:param original: the original symbol
:return: the prettified symbol
"""
pretty = original
# remove spaces
pretty = pretty.replace(' ', '')
# allocator
STD_ALLOCATOR = '_<std::allocator<void>>'
pretty = pretty.replace(STD_ALLOCATOR, '')
# default_delete
STD_DEFAULTDELETE = 'std::default_delete'
if STD_DEFAULTDELETE in pretty:
dd_start = pretty.find(STD_DEFAULTDELETE)
template_param_open = dd_start + len(STD_DEFAULTDELETE)
# find index of matching/closing GT sign
template_param_close = template_param_open
level = 0
done = False
while not done:
template_param_close += 1
if pretty[template_param_close] == '<':
level += 1
elif pretty[template_param_close] == '>':
if level == 0:
done = True
else:
level -= 1
pretty = pretty[:dd_start] + pretty[(template_param_close + 1):]
# bind
STD_BIND = 'std::_Bind<'
if pretty.startswith(STD_BIND):
# remove bind<>
pretty = pretty.replace(STD_BIND, '')
pretty = pretty[:-1]
# remove placeholder stuff
placeholder_from = pretty.find('*')
placeholder_to = pretty.find(')', placeholder_from)
pretty = pretty[:placeholder_from] + '?' + pretty[(placeholder_to + 1):]
# remove dangling comma
pretty = pretty.replace(',>', '>')
# restore meaningful spaces
if pretty.startswith('void'):
pretty = 'void' + ' ' + pretty[len('void'):]
if pretty.endswith('const'):
pretty = pretty[:(len(pretty) - len('const'))] + ' ' + 'const'
return pretty
def get_callback_symbols(self) -> Mapping[int, str]: def get_callback_symbols(self) -> Mapping[int, str]:
""" """
Get mappings between a callback object and its resolved symbol. Get mappings between a callback object and its resolved symbol.
@ -51,7 +106,9 @@ class DataModelUtil():
# Get a list of callback objects # Get a list of callback objects
callback_objects = set(callback_instances['callback_object']) callback_objects = set(callback_instances['callback_object'])
# Get their symbol # Get their symbol
return {obj: callback_symbols.loc[obj, 'symbol'] for obj in callback_objects} return {
obj: self._prettify(callback_symbols.loc[obj, 'symbol']) for obj in callback_objects
}
def get_callback_durations( def get_callback_durations(
self, callback_obj: int self, callback_obj: int