Set callback_instances' timestamp & duration cols to datetime/timedelta

Signed-off-by: Christophe Bedard <bedard.christophe@gmail.com>
This commit is contained in:
Christophe Bedard 2021-03-31 14:50:17 -04:00
parent 3ed8f0ed1d
commit f9ef14e058
4 changed files with 17 additions and 11 deletions

View file

@ -127,7 +127,8 @@
" duration.xaxis[0].formatter = DatetimeTickFormatter(seconds=['%Ss'])\n", " duration.xaxis[0].formatter = DatetimeTickFormatter(seconds=['%Ss'])\n",
"\n", "\n",
" # Histogram\n", " # Histogram\n",
" dur_hist, edges = np.histogram(duration_df['duration'])\n", " # (convert to milliseconds)\n",
" dur_hist, edges = np.histogram(duration_df['duration'] * 1000 / np.timedelta64(1, 's'))\n",
" duration_hist = pd.DataFrame({\n", " duration_hist = pd.DataFrame({\n",
" 'duration': dur_hist, \n", " 'duration': dur_hist, \n",
" 'left': edges[:-1], \n", " 'left': edges[:-1], \n",

View file

@ -15,6 +15,7 @@
"""Module for ROS 2 data model.""" """Module for ROS 2 data model."""
import numpy as np
import pandas as pd import pandas as pd
from . import DataModel from . import DataModel
@ -167,8 +168,8 @@ class Ros2DataModel(DataModel):
) -> None: ) -> None:
self._callback_instances.append({ self._callback_instances.append({
'callback_object': callback_object, 'callback_object': callback_object,
'timestamp': timestamp, 'timestamp': np.datetime64(timestamp, 'ns'),
'duration': duration, 'duration': np.timedelta64(duration, 'ns'),
'intra_process': intra_process, 'intra_process': intra_process,
}) })

View file

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
import numpy as np
import pandas as pd import pandas as pd
from tracetools_analysis.loading import load_file from tracetools_analysis.loading import load_file
@ -48,7 +49,8 @@ def main():
stat_data = [] stat_data = []
for ptr, name in du.get_callback_symbols().items(): for ptr, name in du.get_callback_symbols().items():
durations = du.get_callback_durations(ptr)['duration'] # Convert to milliseconds to display it
durations = du.get_callback_durations(ptr)['duration'] * 1000 / np.timedelta64(1, 's')
stat_data.append(( stat_data.append((
durations.count(), durations.count(),
durations.sum(), durations.sum(),
@ -57,5 +59,8 @@ def main():
format_fn(name), format_fn(name),
)) ))
stat_df = pd.DataFrame(columns=['Count', 'Sum', 'Mean', 'Std', 'Name'], data=stat_data) stat_df = pd.DataFrame(
print(stat_df.sort_values(by='Sum', ascending=False).to_string()) columns=['Count', 'Sum (ms)', 'Mean (ms)', 'Std', 'Name'],
data=stat_data,
)
print(stat_df.sort_values(by='Sum (ms)', ascending=False).to_string())

View file

@ -1,5 +1,6 @@
# Copyright 2019 Robert Bosch GmbH # Copyright 2019 Robert Bosch GmbH
# Copyright 2019 Apex.AI, Inc. # Copyright 2019 Apex.AI, Inc.
# Copyright 2021 Christophe Bedard
# #
# Licensed under the Apache License, Version 2.0 (the "License"); # Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License. # you may not use this file except in compliance with the License.
@ -134,15 +135,13 @@ class Ros2DataModelUtil(DataModelUtil):
Get durations of callback instances for a given callback object. Get durations of callback instances for a given callback object.
:param callback_obj: the callback object value :param callback_obj: the callback object value
:return: a dataframe containing the start timestamp (datetime) :return: a dataframe containing the start timestamp (np.timestamp64)
and duration (ms) of all callback instances for that object and duration (np.timedelta64) of all callback instances for that object
""" """
data = self.data.callback_instances.loc[ return self.data.callback_instances.loc[
self.data.callback_instances.loc[:, 'callback_object'] == callback_obj, self.data.callback_instances.loc[:, 'callback_object'] == callback_obj,
['timestamp', 'duration'] ['timestamp', 'duration']
] ]
# Time conversion
return self.convert_time_columns(data, ['duration'], ['timestamp'])
def get_node_tid_from_name( def get_node_tid_from_name(
self, self,