diff mbox series

[meta-oe,2/2] buildstats: support of custom disk usage command

Message ID 20240117080754.16123-3-ubely@ilbers.de
State New
Headers show
Series Buildstats improvements for using in Isar. | expand

Commit Message

Uladzimir Bely Jan. 17, 2024, 8:07 a.m. UTC
This helps to make buildstats code usage easier in third-party projects
like Isar (https://github.com/ilbers/isar/). In Isar, rootfs is created
with 'sudo' privileges and some subpaths like '/proc' may be mounted at
build time. So, using "du -sh" on rootfs may produces multiple
'Permission denied' warnings.

Customizable disk usage command allows to deal with these issues
(e.g., by adding "-x" option or "sudo" can be added).

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 meta/classes/buildstats.bbclass | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/meta/classes/buildstats.bbclass b/meta/classes/buildstats.bbclass
index b417929b61..94e48bfcb8 100644
--- a/meta/classes/buildstats.bbclass
+++ b/meta/classes/buildstats.bbclass
@@ -8,6 +8,8 @@  BUILDSTATS_BASE = "${TMPDIR}/buildstats/"
 #
 ################################################################################
 
+BUILDSTATS_DISK_USAGE_CMD ??= "du -sh"
+
 def get_buildprocess_cputime(pid):
     with open("/proc/%d/stat" % pid, "r") as f:
         fields = f.readline().rstrip().split()
@@ -246,7 +248,8 @@  python run_buildstats () {
                 rootfs = d.getVar('IMAGE_ROOTFS')
                 if os.path.isdir(rootfs):
                     try:
-                        rootfs_size = subprocess.check_output(["du", "-sh", rootfs],
+                        rootfs_size = subprocess.check_output(
+                                d.getVar('BUILDSTATS_DISK_USAGE_CMD').split() + [rootfs],
                                 stderr=subprocess.STDOUT).decode('utf-8')
                         f.write("Uncompressed Rootfs size: %s" % rootfs_size)
                     except subprocess.CalledProcessError as err: