potential divide by zero in support/scripts/size-stats
I see a divide by zero exception in support/scripts/size-stats when I use the graph-size target, the package of size zero causing this is skeleton-init-systemd which I worked out by catching the exception. Is this package erroneously of size zero or should that be OK?
--- support/scripts/size-stats | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
support/scripts/size-stats +6 -3
@@ -178,9 +178,12 @@ def gen_files_csv(filesdict, pkgsizes, outputf): "File size in system (%)"]) for f, (pkgname, filesize) in filesdict.items(): pkgsize = pkgsizes[pkgname] - wr.writerow([f, pkgname, filesize, pkgsize, - "%.1f" % (float(filesize) / pkgsize * 100), - "%.1f" % (float(filesize) / total * 100)]) + try: + wr.writerow([f, pkgname, filesize, pkgsize, + "%.1f" % (float(filesize) / pkgsize * 100), + "%.1f" % (float(filesize) / total * 100)]) + except ZeroDivisionError: + print('WARNING: \"%s\" is size 0!' % pkgname) #
Signature · 1 line
2.9.5
Hello,
Quoted 4 lines · Andrey Yurovsky
I see a divide by zero exception in support/scripts/size-stats when I use the graph-size target, the package of size zero causing this is skeleton-init-systemd which I worked out by catching the exception. Is this package erroneously of size zero or should that be OK?
Thanks for reporting this bug and proposing a fix! I have some comments on the implementation, but first about the format: the commit log should contain a Signed-off-by line with your name and e-mail, and the commit log should not be formatted as a personal message, but rather as a description of what is being changed/fixed. Also the first line should look like: "support/scripts/size-stats: ..."
Quoted 7 lines
support/scripts/size-stats +0
-0@@ -178,9 +178,12 @@ def gen_files_csv(filesdict, pkgsizes, outputf): "File size in system (%)"]) for f, (pkgname, filesize) in filesdict.items():
support/scripts/size-stats def gen_files_csv(filesdict, pkgsizes, outputf): · line 186
Quoted 10 lines
support/scripts/size-stats +6
-3pkgsize = pkgsizes[pkgname] - wr.writerow([f, pkgname, filesize, pkgsize, - "%.1f" % (float(filesize) / pkgsize * 100), - "%.1f" % (float(filesize) / total * 100)]) + try: + wr.writerow([f, pkgname, filesize, pkgsize, + "%.1f" % (float(filesize) / pkgsize * 100), + "%.1f" % (float(filesize) / total * 100)]) + except ZeroDivisionError: + print('WARNING: \"%s\" is size 0!' % pkgname)
I don't think we want to skip files from zero-sized packages: we want to see them in the CSV. So perhaps something like:
if pkgsize != 0:
percent_pkg = float(filesize) / pkgsize * 100
else:
percent_pkg = 0
percent_total = float(filesize) / total * 100
wr.writerow([f, pkgname, filesize, pkgsize,
"%.1f" % percent_pkg, "%.1f" % percent_total])
Could you test it, and resubmit as a new patch, with your Signed-off-by?
Thanks a lot!
Thomas Petazzoni
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux and Kernel engineering http://free-electrons.com
PATCH 1/1 support/scripts/size-stats: avoid divide-by-zero
Some packages (ex: skeleton-init-systemd) have a zero size so we cannot divide by the package size. In that case make their percent zero explicitly and avoid a ZeroDivisionError exception.
--- support/scripts/size-stats | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
support/scripts/size-stats +10 -2
@@ -178,9 +178,17 @@ def gen_files_csv(filesdict, pkgsizes, outputf): "File size in system (%)"]) for f, (pkgname, filesize) in filesdict.items(): pkgsize = pkgsizes[pkgname] + + if pkgsize == 0: + percent_pkg = 0 + else: + percent_pkg = float(filesize) / pkgsize * 100 + + percent_total = float(filesize) / total * 100 + wr.writerow([f, pkgname, filesize, pkgsize, - "%.1f" % (float(filesize) / pkgsize * 100), - "%.1f" % (float(filesize) / total * 100)]) + "%.1f" % percent_pkg, + "%.1f" % percent_total]) #
Signature · 1 line
2.14.3
PATCH 1/1 support/scripts/size-stats: avoid divide-by-zero
Andrey, Thomas, All,
On 2017-11-27 19:37 -0800, Andrey Yurovsky spake thusly:
Quoted 5 lines
Some packages (ex: skeleton-init-systemd) have a zero size so we cannot divide by the package size. In that case make their percent zero explicitly and avoid a ZeroDivisionError exception.
Signed-off-by Andrey Yurovsky <[email protected]>
Regards,
Yann E. MORIN.
Quoted 35 lines
--- support/scripts/size-stats | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)support/scripts/size-stats +10
-2@@ -178,9 +178,17 @@ def gen_files_csv(filesdict, pkgsizes, outputf): "File size in system (%)"]) for f, (pkgname, filesize) in filesdict.items(): pkgsize = pkgsizes[pkgname] + + if pkgsize == 0: + percent_pkg = 0 + else: + percent_pkg = float(filesize) / pkgsize * 100 + + percent_total = float(filesize) / total * 100 + wr.writerow([f, pkgname, filesize, pkgsize, - "%.1f" % (float(filesize) / pkgsize * 100), - "%.1f" % (float(filesize) / total * 100)]) + "%.1f" % percent_pkg, + "%.1f" % percent_total]) #Signature · 6 lines
2.14.3 _______________________________________________ buildroot mailing list buildroot at busybox.net http://lists.busybox.net/mailman/listinfo/buildroot
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------. | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: | | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ | | +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no | | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. | '------------------------------^-------^------------------^--------------------'
Thomas Petazzoni
AppliedPATCH 1/1 support/scripts/size-stats: avoid divide-by-zero
In reply to Andrey YurovskyHello,
Quoted 8 lines · Andrey Yurovsky
Some packages (ex: skeleton-init-systemd) have a zero size so we cannot divide by the package size. In that case make their percent zero explicitly and avoid a ZeroDivisionError exception.
Signed-off-by Andrey Yurovsky <[email protected]>--- support/scripts/size-stats | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
Applied to master, thanks.
Thomas
Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons Embedded Linux, Kernel and Android engineering http://free-electrons.com
PATCH 1/1 support/scripts/size-stats: avoid divide-by-zero
In reply to Andrey YurovskyQuoted 7 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
"Andrey" == Andrey Yurovsky <[email protected]> writes:
Some packages (ex: skeleton-init-systemd) have a zero size so we cannot divide by the package size. In that case make their percent zero explicitly and avoid a ZeroDivisionError exception.
Signed-off-by Andrey Yurovsky <[email protected]>
Committed to 2017.02.x, thanks.
Signature · 1 line
Bye, Peter Korsgaard