From 06bdaa34e5149fc0966db8639c3d9da220a3a8f0 Mon Sep 17 00:00:00 2001 From: Chris Ye Date: Mon, 27 Aug 2018 16:39:44 +0800 Subject: [PATCH] set max window_size to avoid out-of-memory can't have infinite window size due to memory restrictions, only keep statistics for the last 10000 messages so as not to run out of memory Signed-off-by: Chris Ye --- ros2topic/ros2topic/verb/hz.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ros2topic/ros2topic/verb/hz.py b/ros2topic/ros2topic/verb/hz.py index fcfe40b14..406b15796 100644 --- a/ros2topic/ros2topic/verb/hz.py +++ b/ros2topic/ros2topic/verb/hz.py @@ -118,8 +118,8 @@ def __init__(self, node, window_size, filter_expr=None, use_wtime=False): self.use_wtime = use_wtime # can't have infinite window size due to memory restrictions - if window_size < 0: - window_size = 50000 + if window_size < 0 or window_size > 10000: + window_size = 10000 self.window_size = window_size # Clock that has support for ROS time. @@ -175,7 +175,7 @@ def callback_hz(self, m, topic=None): :param m: Message instance :param topic: Topic name """ - # #694: ignore messages that don't match filter + # ignore messages that don't match filter if self.filter_expr is not None and not self.filter_expr(m): return with self.lock: @@ -200,7 +200,7 @@ def callback_hz(self, m, topic=None): self.set_msg_tn(curr, topic=topic) # only keep statistics for the last 10000 messages so as not to run out of memory - if len(self.get_times(topic=topic)) > 10000: + if len(self.get_times(topic=topic)) > self.window_size - 1: self.get_times(topic=topic).pop(0) def get_hz(self, topic=None):