Gentoo Archives: gentoo-portage-dev

From: Fabian Groffen <grobian@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Fabian Groffen <grobian@g.o>
Subject: [gentoo-portage-dev] [PATCH] __dyn_install: improve reporting of build and image sizes
Date: Thu, 24 Aug 2017 13:02:27
Message-Id: 20170824130221.9128-1-grobian@gentoo.org
1 Prior to this commit, the reported sizes would look like:
2
3 * Final size of build directory: 34942 KiB
4 * Final size of installed tree: 5627 KiB
5
6 Because the sizes aren't aligned, it is hard to (visually) compare them.
7 On top of this, because the numbers are sometimes bigger, print a human
8 friendly size after the KiB size if applicable, like so:
9
10 * Final size of build directory: 1906 KiB (1.8 MiB)
11 * Final size of installed tree: 7 KiB
12
13 It should be noted that in case both sizes have a human-readable
14 variant, they are also aligned.
15 ---
16 bin/phase-functions.sh | 49 +++++++++++++++++++++++++++++++++++++++++++++----
17 1 file changed, 45 insertions(+), 4 deletions(-)
18
19 diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
20 index dfd8733c8..af45a0d49 100644
21 --- a/bin/phase-functions.sh
22 +++ b/bin/phase-functions.sh
23 @@ -598,10 +598,51 @@ __dyn_install() {
24
25 # record build & installed size in build log
26 if type -P du &>/dev/null; then
27 - local sz=( $(du -ks "${WORKDIR}") )
28 - einfo "Final size of build directory: ${sz[0]} KiB"
29 - sz=( $(du -ks "${D}") )
30 - einfo "Final size of installed tree: ${sz[0]} KiB"
31 + local nsz=( $(du -ks "${WORKDIR}") )
32 + local isz=( $(du -ks "${D}") )
33 +
34 + # align $1 to the right to the width of the widest of $1 and $2
35 + padl() {
36 + local s1=$1
37 + local s2=$2
38 + local width=${#s1}
39 + [[ ${#s2} -gt ${width} ]] && width=${#s2}
40 + printf "%*s" ${width} "${s1}"
41 + }
42 +
43 + # transform number in KiB into MiB, GiB or TiB based on size
44 + human() {
45 + local s1=$1
46 + local units=( KiB MiB GiB TiB )
47 +
48 + s1=$((s1 * 10))
49 + while [[ ${s1} -gt 10240 && ${#units[@]} -gt 1 ]] ; do
50 + s1=$((s1 / 1024 ))
51 + units=( ${units[@]:1} )
52 + done
53 +
54 + local r=${s1: -1}
55 + s1=$((s1 / 10))
56 + printf "%s.%s %s" "${s1}" "${r}" "${units[0]}"
57 + }
58 +
59 + size() {
60 + local s1=$1
61 + local s2=$2
62 + local out="$(padl "${s1}" "${s2}") KiB"
63 +
64 + if [[ ${s1} -gt 1024 ]] ; then
65 + s1=$(human ${s1})
66 + if [[ ${s2} -gt 1024 ]] ; then
67 + s2=$(human ${s2})
68 + s1=$(padl ${s1} ${s2})
69 + fi
70 + out+=" (${s1})"
71 + fi
72 + echo "${out}"
73 + }
74 + einfo "Final size of build directory: $(size ${nsz[0]} ${isz[0]})"
75 + einfo "Final size of installed tree: $(size ${isz[0]} ${nsz[0]})"
76 __vecho
77 fi
78
79 --
80 2.14.1

Replies