* [Buildroot] potential divide by zero in support/scripts/size-stats
@ 2017-11-12 2:17 Andrey Yurovsky
2017-11-27 21:08 ` Thomas Petazzoni
0 siblings, 1 reply; 6+ messages in thread
From: Andrey Yurovsky @ 2017-11-12 2:17 UTC (permalink / raw)
To: buildroot
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(-)
diff --git a/support/scripts/size-stats b/support/scripts/size-stats
index af45000..3cd6838 100755
--- a/support/scripts/size-stats
+++ b/support/scripts/size-stats
@@ -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)
#
--
2.9.5
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Buildroot] potential divide by zero in support/scripts/size-stats
2017-11-12 2:17 [Buildroot] potential divide by zero in support/scripts/size-stats Andrey Yurovsky
@ 2017-11-27 21:08 ` Thomas Petazzoni
2017-11-28 3:37 ` [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero Andrey Yurovsky
0 siblings, 1 reply; 6+ messages in thread
From: Thomas Petazzoni @ 2017-11-27 21:08 UTC (permalink / raw)
To: buildroot
Hello,
On Sat, 11 Nov 2017 18:17:36 -0800, Andrey Yurovsky wrote:
> 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: ..."
> diff --git a/support/scripts/size-stats b/support/scripts/size-stats
> index af45000..3cd6838 100755
> --- a/support/scripts/size-stats
> +++ b/support/scripts/size-stats
> @@ -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)
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
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero
2017-11-27 21:08 ` Thomas Petazzoni
@ 2017-11-28 3:37 ` Andrey Yurovsky
2017-11-28 10:09 ` Yann E. MORIN
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Andrey Yurovsky @ 2017-11-28 3:37 UTC (permalink / raw)
To: buildroot
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 <yurovsky@gmail.com>
---
support/scripts/size-stats | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/support/scripts/size-stats b/support/scripts/size-stats
index af45000359..3ff2a1ce18 100755
--- a/support/scripts/size-stats
+++ b/support/scripts/size-stats
@@ -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])
#
--
2.14.3
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero
2017-11-28 3:37 ` [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero Andrey Yurovsky
@ 2017-11-28 10:09 ` Yann E. MORIN
2017-11-29 20:36 ` Thomas Petazzoni
2017-12-20 20:52 ` Peter Korsgaard
2 siblings, 0 replies; 6+ messages in thread
From: Yann E. MORIN @ 2017-11-28 10:09 UTC (permalink / raw)
To: buildroot
Andrey, Thomas, All,
On 2017-11-27 19:37 -0800, Andrey Yurovsky spake thusly:
> 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 <yurovsky@gmail.com>
Acked-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
Regards,
Yann E. MORIN.
> ---
> support/scripts/size-stats | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
>
> diff --git a/support/scripts/size-stats b/support/scripts/size-stats
> index af45000359..3ff2a1ce18 100755
> --- a/support/scripts/size-stats
> +++ b/support/scripts/size-stats
> @@ -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])
>
>
> #
> --
> 2.14.3
>
> _______________________________________________
> buildroot mailing list
> buildroot at busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
--
.-----------------.--------------------.------------------.--------------------.
| 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. |
'------------------------------^-------^------------------^--------------------'
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero
2017-11-28 3:37 ` [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero Andrey Yurovsky
2017-11-28 10:09 ` Yann E. MORIN
@ 2017-11-29 20:36 ` Thomas Petazzoni
2017-12-20 20:52 ` Peter Korsgaard
2 siblings, 0 replies; 6+ messages in thread
From: Thomas Petazzoni @ 2017-11-29 20:36 UTC (permalink / raw)
To: buildroot
Hello,
On Mon, 27 Nov 2017 19:37:07 -0800, Andrey Yurovsky wrote:
> 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 <yurovsky@gmail.com>
> ---
> support/scripts/size-stats | 12 ++++++++++--
> 1 file changed, 10 insertions(+), 2 deletions(-)
Applied to master, thanks.
Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero
2017-11-28 3:37 ` [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero Andrey Yurovsky
2017-11-28 10:09 ` Yann E. MORIN
2017-11-29 20:36 ` Thomas Petazzoni
@ 2017-12-20 20:52 ` Peter Korsgaard
2 siblings, 0 replies; 6+ messages in thread
From: Peter Korsgaard @ 2017-12-20 20:52 UTC (permalink / raw)
To: buildroot
>>>>> "Andrey" == Andrey Yurovsky <yurovsky@gmail.com> 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 <yurovsky@gmail.com>
Committed to 2017.02.x, thanks.
--
Bye, Peter Korsgaard
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2017-12-20 20:52 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-11-12 2:17 [Buildroot] potential divide by zero in support/scripts/size-stats Andrey Yurovsky
2017-11-27 21:08 ` Thomas Petazzoni
2017-11-28 3:37 ` [Buildroot] [PATCH] support/scripts/size-stats: avoid divide-by-zero Andrey Yurovsky
2017-11-28 10:09 ` Yann E. MORIN
2017-11-29 20:36 ` Thomas Petazzoni
2017-12-20 20:52 ` Peter Korsgaard
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox