From 4a41c2bd61d1ca1f0443af5bc3c578fb121e0bc7 Mon Sep 17 00:00:00 2001 From: Christophe Bedard Date: Thu, 8 Aug 2019 11:29:14 +0200 Subject: [PATCH] Add addr_to_int util function --- .../tracetools_analysis/processor/profile.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/tracetools_analysis/tracetools_analysis/processor/profile.py b/tracetools_analysis/tracetools_analysis/processor/profile.py index e3a38e2..a92443b 100644 --- a/tracetools_analysis/tracetools_analysis/processor/profile.py +++ b/tracetools_analysis/tracetools_analysis/processor/profile.py @@ -43,13 +43,13 @@ class ProfileHandler(EventHandler): def __init__( self, - address_to_func: Dict[int, str] = {}, + address_to_func: Dict[Union[int, str], str] = {}, **kwargs, ) -> None: """ Constructor. - :param address_to_func: the mapping from function address to name + :param address_to_func: the mapping from function address (`int` or hex `str`) to name """ handler_map = { 'lttng_ust_cyg_profile_fast:func_entry': @@ -65,7 +65,9 @@ class ProfileHandler(EventHandler): ) self._data_model = ProfileDataModel() - self._address_to_func = address_to_func + self._address_to_func = { + self._addr_to_int(addr): name for addr, name in address_to_func.items() + } # Temporary buffers # tid -> @@ -80,6 +82,11 @@ class ProfileHandler(EventHandler): # ] self._current_funcs: Dict[int, List[List[Union[str, int]]]] = defaultdict(list) + @staticmethod + def _addr_to_int(addr: Union[int, str]) -> int: + """Transform an address into an `int` if it's a hex `str`.""" + return int(addr, 16) if isinstance(addr, str) else addr + @property def data(self) -> ProfileDataModel: return self._data_model