I modified MumboJumbo code to give human readable output:
To run: python rosbag_size_by_topic.py BAG_FILE_PATH
or
rosrun PACKAGE rosbag_size_by_topic.py BAG_FILE_PATH
rosbag_size_by_topic.py:
#!/usr/bin/env python
# Prints total cumulative serialized msg size in bytes per topic
# Calculation takes approximately 1sec/GB
# Usage: python rosbag_size_by_topic.py BAG_FILE_PATH
import rosbag
import sys
topic_size_dict = {}
for topic, msg, time in rosbag.Bag(sys.argv[1], "r").read_messages(raw=True):
topic_size_dict[topic] = topic_size_dict.get(topic, 0) + len(msg[1])
topic_size = list(topic_size_dict.items())
topic_size.sort(key=lambda x: x[1], reverse=False)
for topic, size in topic_size:
if size < 1000:
print("{:7d}B {}".format(size, topic))
elif size >= 1000000000000:
print("{:7.2f}T {}".format(size/1000000000000, topic))
elif size >= 1000000000:
print("{:7.2f}G {}".format(size/1000000000, topic))
elif size >= 1000000:
print("{:7.2f}M {}".format(size/1000000, topic))
elif size >= 1000:
print("{:7.2f}K {}".format(size/1000, topic))
Example of output:
86B /tf_static
775B /move_base/global_costmap/inflater_layer/parameter_descriptions
775B /move_base/local_costmap/inflater_layer/parameter_descriptions
1.01K /mobile_base_controller/parameter_descriptions
1.33K /move_base/goal
1.88K /voxel_grid/parameter_descriptions
866.76K /move_base/GlobalPlanner/plan
921.19K /path_planner/visualization_marker
1.10M /move_base/TebLocalPlannerROS/local_plan
1.18M /imu/mag
1.19M /move_base/TebLocalPlannerROS/teb_markers
19.89M /tf
284.01M /move_base/GlobalPlanner/potential
19.54G /move_base/global_costmap/obstacles_layer/voxel_grid
What do you mean by size of topics? You can get the number of messages in the particular topic and data type using rosbag info