Skip to content

Commit

Permalink
Added a new argument "plot_function_level_processing_time"
Browse files Browse the repository at this point in the history
Signed-off-by: Shintaro Sakoda <[email protected]>
  • Loading branch information
SakodaShintaro committed Nov 6, 2024
1 parent 3c33924 commit 9dfed7e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3

from tier4_debug_msgs.msg import Float64Stamped
from tier4_debug_msgs.msg import Float64Stamped, ProcessingTimeTree

from .system_performance_plotter_base import PREDEFINED_COMPONENT_NAMES
from .system_performance_plotter_base import SystemPerformancePlotterBase
Expand Down Expand Up @@ -28,17 +28,29 @@ def check_topic(self, topic_name):
return False
return True

def update_metrics_func(self, topic_name, data, date_time):
if not isinstance(data, Float64Stamped):
return

if topic_name not in self.stamp_and_metrics:
self.stamp_and_metrics[topic_name] = []
self.max_metrics[topic_name] = 0.0

processing_time_ms = data.data
self.stamp_and_metrics[topic_name].append([date_time, processing_time_ms])
self.max_metrics[topic_name] = max(self.max_metrics[topic_name], processing_time_ms)
def update_metrics_func(self, topic_name, data, date_time, parse_processing_time_tree=False):
if isinstance(data, Float64Stamped):
if topic_name not in self.stamp_and_metrics:
self.stamp_and_metrics[topic_name] = []
self.max_metrics[topic_name] = 0.0

processing_time_ms = data.data
self.stamp_and_metrics[topic_name].append([date_time, processing_time_ms])
self.max_metrics[topic_name] = max(self.max_metrics[topic_name], processing_time_ms)
elif isinstance(data, ProcessingTimeTree) and parse_processing_time_tree:
for node in data.nodes:
curr_name = topic_name + ":" + node.name
if curr_name not in self.stamp_and_metrics:
self.stamp_and_metrics[curr_name] = []
self.max_metrics[curr_name] = 0.0

processing_time_ms = node.processing_time
self.stamp_and_metrics[curr_name].append(
[date_time, processing_time_ms]
)
self.max_metrics[curr_name] = max(
self.max_metrics[curr_name], processing_time_ms
)


def main():
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ def __init__(self, args, ylabel, output_suffix):
self.stamp_and_metrics = {}
self.max_metrics = {}

self.additional_args = {}
if args.plot_function_level_processing_time:
self.additional_args["parse_processing_time_tree"] = True

def run(self):
# read data from rosbag
reader = create_reader(self.input_bag_dir)
Expand All @@ -60,7 +64,7 @@ def run(self):
time_stamp = stamp * to_nanosec
date_time = datetime.fromtimestamp(time_stamp)

self.update_metrics_func(topic_name, data, date_time)
self.update_metrics_func(topic_name, data, date_time, **self.additional_args)

# sort stamp_and_metrics by alphabetical order
self.stamp_and_metrics = dict(sorted(self.stamp_and_metrics.items(), key=lambda x: x[0]))
Expand Down Expand Up @@ -202,6 +206,13 @@ def create_common_argment(ymax=None):
action="store_true",
help="whether to skip plt.show()",
)
parser.add_argument(
"-f",
"--plot_function_level_processing_time",
default=False,
action="store_true",
help="whether to plot function level processing time",
)

args = parser.parse_args()

Expand Down

0 comments on commit 9dfed7e

Please sign in to comment.