How to check the size of the folder where logs are saved in ROS

Publisher:bln898Latest update time:2023-09-14 Source: 古月居Author: Lemontree Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Check the space occupied by the log folder

The launch package is also responsible for checking how big the folder where the log is saved is. In the main function of the ros_comm-noet-develtoolsroslaunchsrcroslaunch_ init _.py file, there is the following statement.

You can tell what it does by looking at the name.

rlul.check_log_disk_usage()

Open rlutil.py in the same path again and find that it calls the get_disk_usage function in the rosclean package.

We found that the upper limit of comparison is directly written into this function: disk_usage > 1073741824. Of course, this is not good and should be changed to configurable.

The number 1073741824 is in bytes, which is exactly 1GB (102 4 3 1024^31024 3by).

If we want to change the upper limit of the log folder alarm, just change this value.

def check_log_disk_usage():
    """
    Check size of log directory. If high, print warning to user
    """
    try:
        d = rospkg.get_log_dir()
        roslaunch.core.printlog("Checking log directy for disk usage. This may take a while.nPress Ctrl-C to interrupt") 
        disk_usage = rosclean.get_disk_usage(d)
        # warn if over a gig
        if disk_usage > 1073741824:
            roslaunch.core.printerrlog("WARNING: disk usage in log directory [%s] is over 1GB.nIt's mended that you use the 'rosclean' command."%d)
        else:
            roslaunch.core.printlog("Done checking log file disk usage. Usage is < 1GB.")            
    except:
        pass

Let's dig deeper and find out how rosclean.get_disk_usage(d) is implemented.

The rosclean package is not included in ros_comm and needs to be installed separately.

After opening it, I found that this package is cross-platform and provides implementations for Windows and .

If it is a Windows system, use the os.path.getsize function to get the size of the file, and use the os.walk function to traverse all files, and the total is the size of the folder.

If it is a Linux system, use the du -sb command in Linux to get the size of the folder. Hey, not only do you have to learn Python, but you also have to be familiar with Linux. Is it easy?

The master node will obtain the URI address and number listed in the ROS_MASTER_URI variable set by the user (the default is the current local IP and port number 11311).

Reference address:How to check the size of the folder where logs are saved in ROS

Previous article:Dependencies between ROS files
Next article:How is the node manager master started in ROS?

Latest robot Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号