All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] support/scripts/size-stats: increase number of files that can be linked to a source
@ 2021-02-10 11:05 Daniel Crowe
  2021-02-16 14:06 ` Thomas De Schampheleire
  0 siblings, 1 reply; 4+ messages in thread
From: Daniel Crowe @ 2021-02-10 11:05 UTC (permalink / raw)
  To: buildroot

Signed-off-by: Daniel Crowe <daniel.crowe@resolution.systems>
---
 Makefile                   |  1 +
 support/scripts/size-stats | 76 +++++++++++++++++++++++++++-----------
 2 files changed, 56 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index 14e10223ed..495b5df1ac 100644
--- a/Makefile
+++ b/Makefile
@@ -912,6 +912,7 @@ graph-depends: graph-depends-requirements
 graph-size:
 	$(Q)mkdir -p $(GRAPHS_DIR)
 	$(Q)$(TOPDIR)/support/scripts/size-stats --builddir $(BASE_DIR) \
+		--overlay $(BR2_ROOTFS_OVERLAY) \
 		--graph $(GRAPHS_DIR)/graph-size.$(BR_GRAPH_OUT) \
 		--file-size-csv $(GRAPHS_DIR)/file-size-stats.csv \
 		--package-size-csv $(GRAPHS_DIR)/package-size-stats.csv \
diff --git a/support/scripts/size-stats b/support/scripts/size-stats
index dea3a6007c..e502069208 100755
--- a/support/scripts/size-stats
+++ b/support/scripts/size-stats
@@ -70,8 +70,12 @@ def add_file(filesdict, relpath, abspath, pkg):
 #
 # builddir: path to the Buildroot output directory
 #
-def build_package_dict(builddir):
+# overlays: list of paths to the rootfs overlays
+#
+def build_package_dict(builddir, overlays):
     filesdict = {}
+
+    # populate from packages-file-list.txt
     with open(os.path.join(builddir, "build", "packages-file-list.txt")) as f:
         for l in f.readlines():
             pkg, fpath = l.split(",", 1)
@@ -79,26 +83,36 @@ def build_package_dict(builddir):
             fpath = fpath.strip()[2:]
             fullpath = os.path.join(builddir, "target", fpath)
             add_file(filesdict, fpath, fullpath, pkg)
+
+            # account for python file compilation
+            if fpath.endswith('.py'):
+                add_file(filesdict, fpath + 'c', fullpath + 'c', pkg)
+
+    # populate files from overlays
+    for overlay in overlays:
+        build_package_dict_from_dir(filesdict, overlay, os.path.join(builddir, "..", overlay))
+
+    # populate any files left over
+    build_package_dict_from_dir(filesdict, "unknown", os.path.join(builddir, "target"))
+
     return filesdict
 
 
 #
-# This function builds a dictionary that contains the name of a
-# package as key, and the size of the files installed by this package
-# as the value.
+# This function walks 'dir' and adds each file found to 'filesdict'.
 #
-# filesdict: dictionary with the name of the files as key, and as
-# value a tuple containing the name of the package to which the files
-# belongs, and the size of the file. As returned by
-# build_package_dict.
+# filesdict: a dict where each key is the path of a file in
+# the root filesystem, and the value is a tuple containing two
+# elements: the name of the package to which this file belongs and the
+# size of the file.
 #
-# builddir: path to the Buildroot output directory
+# pkg: name of the pkg for each file found
 #
-def build_package_size(filesdict, builddir):
-    pkgsize = collections.defaultdict(int)
-
+# dir: path to the directory to walk
+#
+def build_package_dict_from_dir(filesdict, pkg, dir):
     seeninodes = set()
-    for root, _, files in os.walk(os.path.join(builddir, "target")):
+    for root, _, files in os.walk(dir):
         for f in files:
             fpath = os.path.join(root, f)
             if os.path.islink(fpath):
@@ -111,14 +125,31 @@ def build_package_size(filesdict, builddir):
             else:
                 seeninodes.add(st.st_ino)
 
-            frelpath = os.path.relpath(fpath, os.path.join(builddir, "target"))
-            if frelpath not in filesdict:
+            frelpath = os.path.relpath(fpath, dir)
+            if frelpath in filesdict:
+                continue
+
+            if pkg == "unknown":
                 print("WARNING: %s is not part of any package" % frelpath)
-                pkg = "unknown"
-            else:
-                pkg = filesdict[frelpath][0]
 
-            pkgsize[pkg] += st.st_size
+            add_file(filesdict, frelpath, fpath, pkg)
+
+
+#
+# This function builds a dictionary that contains the name of a
+# package as key, and the size of the files installed by this package
+# as the value.
+#
+# filesdict: dictionary with the name of the files as key, and as
+# value a tuple containing the name of the package to which the files
+# belongs, and the size of the file. As returned by
+# build_package_dict.
+#
+def build_package_size(filesdict):
+    pkgsize = collections.defaultdict(int)
+
+    for pkg, size in filesdict.values():
+        pkgsize[pkg] += size
 
     return pkgsize
 
@@ -265,6 +296,8 @@ def main():
 
     parser.add_argument("--builddir", '-i', metavar="BUILDDIR", required=True,
                         help="Buildroot output directory")
+    parser.add_argument("--overlay", '-o', metavar="OVERLAYS", nargs="*",
+                        help="rootfs overlay directories")
     parser.add_argument("--graph", '-g', metavar="GRAPH",
                         help="Graph output file (.pdf or .png extension)")
     parser.add_argument("--file-size-csv", '-f', metavar="FILE_SIZE_CSV",
@@ -291,10 +324,11 @@ def main():
         Config.size_limit = args.size_limit
 
     # Find out which package installed what files
-    pkgdict = build_package_dict(args.builddir)
+    overlays = [path for paths in args.overlay for path in paths.split(" ")]
+    pkgdict = build_package_dict(args.builddir, overlays)
 
     # Collect the size installed by each package
-    pkgsize = build_package_size(pkgdict, args.builddir)
+    pkgsize = build_package_size(pkgdict)
 
     if args.graph:
         draw_graph(pkgsize, args.graph)
-- 
2.17.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH 1/1] support/scripts/size-stats: increase number of files that can be linked to a source
  2021-02-10 11:05 [Buildroot] [PATCH 1/1] support/scripts/size-stats: increase number of files that can be linked to a source Daniel Crowe
@ 2021-02-16 14:06 ` Thomas De Schampheleire
  2021-02-16 21:10   ` Thomas Petazzoni
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas De Schampheleire @ 2021-02-16 14:06 UTC (permalink / raw)
  To: buildroot

Hi Daniel,

El mi?, 10 feb 2021 a las 12:13, Daniel Crowe
(<daniel.crowe@resolution.systems>) escribi?:
>
> Signed-off-by: Daniel Crowe <daniel.crowe@resolution.systems>
> ---
>  Makefile                   |  1 +
>  support/scripts/size-stats | 76 +++++++++++++++++++++++++++-----------
>  2 files changed, 56 insertions(+), 21 deletions(-)
>

Please extend your commit message with more information: what is the
problem you're fixing, and how are you fixing it.
Right now, we can only guess what it is doing based on the code.

It looks like the change is extending the size information to
rootfs-overlays, while today only real packages are considered.
But if that is correct, then the title "increase number of files that
can be linked to a source" is confusing to me.

Thanks,
Thomas

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH 1/1] support/scripts/size-stats: increase number of files that can be linked to a source
  2021-02-16 14:06 ` Thomas De Schampheleire
@ 2021-02-16 21:10   ` Thomas Petazzoni
  2021-02-16 22:57     ` Daniel Crowe
  0 siblings, 1 reply; 4+ messages in thread
From: Thomas Petazzoni @ 2021-02-16 21:10 UTC (permalink / raw)
  To: buildroot

On Tue, 16 Feb 2021 15:06:39 +0100
Thomas De Schampheleire <patrickdepinguin@gmail.com> wrote:

> Please extend your commit message with more information: what is the
> problem you're fixing, and how are you fixing it.
> Right now, we can only guess what it is doing based on the code.
> 
> It looks like the change is extending the size information to
> rootfs-overlays, while today only real packages are considered.
> But if that is correct, then the title "increase number of files that
> can be linked to a source" is confusing to me.

The change is not just about the rootfs overlay, but also about taking
into account .pyc files compiled from .py files:

+            # account for python file compilation
+            if fpath.endswith('.py'):
+                add_file(filesdict, fpath + 'c', fullpath + 'c', pkg)

This should at least be separated in another patch. I'm not a huge fan
of this approach, but I don't really have a good suggestion. Ideally,
we should byte-compile each package independently, so that it's part of
the install step of the package. But that would be vastly less
efficient than just byte-compiling everything in one go at the end of
the build, like we're doing.

Daniel: could you rework your patch a bit, splitting it into several
patches, with a slightly improved commit log ? I think it makes a lot
of sense to have these improvements to size-stats.

Thanks a lot!

Thomas
-- 
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Buildroot] [PATCH 1/1] support/scripts/size-stats: increase number of files that can be linked to a source
  2021-02-16 21:10   ` Thomas Petazzoni
@ 2021-02-16 22:57     ` Daniel Crowe
  0 siblings, 0 replies; 4+ messages in thread
From: Daniel Crowe @ 2021-02-16 22:57 UTC (permalink / raw)
  To: buildroot

Thanks for the feedback. Happy to rework it as suggested.


On Wed, 17 Feb 2021 at 07:40, Thomas Petazzoni <thomas.petazzoni@bootlin.com>
wrote:

> On Tue, 16 Feb 2021 15:06:39 +0100
> Thomas De Schampheleire <patrickdepinguin@gmail.com> wrote:
>
> > Please extend your commit message with more information: what is the
> > problem you're fixing, and how are you fixing it.
> > Right now, we can only guess what it is doing based on the code.
> >
> > It looks like the change is extending the size information to
> > rootfs-overlays, while today only real packages are considered.
> > But if that is correct, then the title "increase number of files that
> > can be linked to a source" is confusing to me.
>
> The change is not just about the rootfs overlay, but also about taking
> into account .pyc files compiled from .py files:
>
> +            # account for python file compilation
> +            if fpath.endswith('.py'):
> +                add_file(filesdict, fpath + 'c', fullpath + 'c', pkg)
>
> This should at least be separated in another patch. I'm not a huge fan
> of this approach, but I don't really have a good suggestion. Ideally,
> we should byte-compile each package independently, so that it's part of
> the install step of the package. But that would be vastly less
> efficient than just byte-compiling everything in one go at the end of
> the build, like we're doing.
>
> Daniel: could you rework your patch a bit, splitting it into several
> patches, with a slightly improved commit log ? I think it makes a lot
> of sense to have these improvements to size-stats.
>
> Thanks a lot!
>
> Thomas
> --
> Thomas Petazzoni, CTO, Bootlin
> Embedded Linux and Kernel engineering
> https://bootlin.com
>


-- 
*Daniel Crowe | Senior Embedded Developer*

Resolution Systems Pty Ltd | L1 214 Greenhill Road, Eastwood South
Australia, 5063, Australia
m. +61 400 014 688
e. daniel.crowe at resolution.systems | www.resolution.systems
[image: Resolution Systems]
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.busybox.net/pipermail/buildroot/attachments/20210217/80cfd2ed/attachment.html>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-02-16 22:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-10 11:05 [Buildroot] [PATCH 1/1] support/scripts/size-stats: increase number of files that can be linked to a source Daniel Crowe
2021-02-16 14:06 ` Thomas De Schampheleire
2021-02-16 21:10   ` Thomas Petazzoni
2021-02-16 22:57     ` Daniel Crowe

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.