Skip to content

Instantly share code, notes, and snippets.

@ross-newman
Created July 9, 2021 05:24
Show Gist options
  • Save ross-newman/0763c6614d9015a6340407abd0e08193 to your computer and use it in GitHub Desktop.
Save ross-newman/0763c6614d9015a6340407abd0e08193 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
import subprocess
import os
import sys
SECONDS=5
if len(sys.argv) > 1:
print("Recording topics...", )
topics = ["/an_device/sync/Imu", \
"/lidar_1/sync/cloud_1", \
"/cam1/left/camera_info", \
"/cam1/stereo_camera_info", \
"/cam1/sync/disparity_map", \
"/cam1/sync/left_image", \
"/cam1/sync/point_cloud", \
"/tf" ]
else:
print("Recording all topics...")
output = subprocess.getoutput("rostopic list")
topics = output.splitlines()
file = open("bench_topics.csv",'w')
speeds = []
for topic in topics:
FILENAME = "topic_" + topic + ".bag"
FILENAME= FILENAME.replace("/", "-")
# print ("Recording " + FILENAME)
COMMAND = "rosbag record -O " + FILENAME + " --duration=" + str(SECONDS) + " " + topic
# print(COMMAND)
output = subprocess.getoutput(COMMAND)
size = os.path.getsize(FILENAME)
KB = (size/1024/SECONDS)
print(topic + " has datarate %.2f Kb/Sec" % (KB))
file.write(" " + topic + ", " + str(KB) + "\n")
speeds.append(KB)
total=0
for speed in speeds:
total += speed;
total_gb = total / 1024
print("Total bandwidth = %.2f Kb/Sec (%.2f Mb/Sec)" % (total, total_gb))
file.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment