Ask Your Question

Using rosbag to get size of each topic

asked 2019-03-17 10:47:07 -0500

Escontrela gravatar image

I'm trying to remove unnecessary topics from a rosbag file to make it easier to distribute. In doing so, i'd like to know the size of each topic, not just the size of the bag file as a whole. However, running rosbag info example_bag.bag only provides me with the size of the bag file and not the size of individual topics.

Is there any way to use the rosbag command line tool to obtain the size of individual topics within the bag file?

edit retag flag offensive close merge delete


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

simbha gravatar image simbha  ( 2019-03-19 16:10:05 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted

answered 2019-05-20 05:11:38 -0500

MumboJumbo gravatar image

updated 2019-05-30 17:23:19 -0500

lucasw gravatar image

I had the same issue and wrote a python script to solve it.

#!/usr/bin/env python
# Print total cumulative serialized msg size per topic
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])
for topic, size in topic_size:
  print(topic, size)

And to explain to simbha why this is useful and needed: I have 102 topics generated by 40+ nodes. Hundreds of thousands of message. I'm not familiar with any of these nodes. But one of them is causing excessive size of bags. As a system administrator/data warehouse guy I want to quickly find out which one exactly so I can contact the responsible developer to fix the issue.

edit flag offensive delete link more


And if you get "UnicodeEncodeError", add lines belows

import sys
raucha gravatar image raucha  ( 2019-06-19 08:14:55 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2019-03-17 10:47:07 -0500

Seen: 1,757 times

Last updated: May 30 '19