Merge branch '36-callback-instance-duration-as-int' into 'master'

Set callback_instances' timestamp & duration cols to datetime/timedelta

Closes #36

See merge request ros-tracing/tracetools_analysis!91
This commit is contained in:
Christophe Bedard 2021-03-31 19:34:27 +00:00
commit 3e0acc9a95
4 changed files with 17 additions and 11 deletions

View file

@ -127,7 +127,8 @@
" duration.xaxis[0].formatter = DatetimeTickFormatter(seconds=['%Ss'])\n",
"\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': dur_hist, \n",
" 'left': edges[:-1], \n",

View file

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

View file

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import numpy as np
import pandas as pd
from tracetools_analysis.loading import load_file
@ -48,7 +49,8 @@ def main():
stat_data = []
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((
durations.count(),
durations.sum(),
@ -57,5 +59,8 @@ def main():
format_fn(name),
))
stat_df = pd.DataFrame(columns=['Count', 'Sum', 'Mean', 'Std', 'Name'], data=stat_data)
print(stat_df.sort_values(by='Sum', ascending=False).to_string())
stat_df = pd.DataFrame(
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 Apex.AI, Inc.
# Copyright 2021 Christophe Bedard
#
# Licensed under the Apache License, Version 2.0 (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.
:param callback_obj: the callback object value
:return: a dataframe containing the start timestamp (datetime)
and duration (ms) of all callback instances for that object
:return: a dataframe containing the start timestamp (np.timestamp64)
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,
['timestamp', 'duration']
]
# Time conversion
return self.convert_time_columns(data, ['duration'], ['timestamp'])
def get_node_tid_from_name(
self,