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:
commit
3e0acc9a95
4 changed files with 17 additions and 11 deletions
|
@ -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",
|
||||||
|
|
|
@ -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,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -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())
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue