1 |
commit: 4dc6f7494af1bcb6a051add9abb827087fd9e9e7 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Aug 24 12:46:04 2017 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Aug 28 06:23:43 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=4dc6f749 |
7 |
|
8 |
__dyn_install: improve reporting of build and image sizes |
9 |
|
10 |
Prior to this commit, the reported sizes would look like: |
11 |
|
12 |
* Final size of build directory: 34942 KiB |
13 |
* Final size of installed tree: 5627 KiB |
14 |
|
15 |
Because the sizes aren't aligned, it is hard to (visually) compare them. |
16 |
On top of this, because the numbers are sometimes bigger, print a human |
17 |
friendly size after the KiB size if applicable, like so: |
18 |
|
19 |
* Final size of build directory: 1906 KiB (1.8 MiB) |
20 |
* Final size of installed tree: 7 KiB |
21 |
|
22 |
It should be noted that in case both sizes have a human-readable |
23 |
variant, they are also aligned. |
24 |
|
25 |
The helper functions are defined and used in a subshell to avoid |
26 |
pollution of the caller's environment. |
27 |
|
28 |
Reviewed-by: Zac Medico <zmedico <AT> gentoo.org> |
29 |
|
30 |
bin/phase-functions.sh | 53 ++++++++++++++++++++++++++++++++++++++++++++++---- |
31 |
1 file changed, 49 insertions(+), 4 deletions(-) |
32 |
|
33 |
diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh |
34 |
index dfd8733c8..ce174ba91 100644 |
35 |
--- a/bin/phase-functions.sh |
36 |
+++ b/bin/phase-functions.sh |
37 |
@@ -598,10 +598,55 @@ __dyn_install() { |
38 |
|
39 |
# record build & installed size in build log |
40 |
if type -P du &>/dev/null; then |
41 |
- local sz=( $(du -ks "${WORKDIR}") ) |
42 |
- einfo "Final size of build directory: ${sz[0]} KiB" |
43 |
- sz=( $(du -ks "${D}") ) |
44 |
- einfo "Final size of installed tree: ${sz[0]} KiB" |
45 |
+ local nsz=( $(du -ks "${WORKDIR}") ) |
46 |
+ local isz=( $(du -ks "${D}") ) |
47 |
+ |
48 |
+ # subshell to avoid polluting the caller env with the helper |
49 |
+ # functions below |
50 |
+ ( |
51 |
+ # align $1 to the right to the width of the widest of $1 and $2 |
52 |
+ padl() { |
53 |
+ local s1=$1 |
54 |
+ local s2=$2 |
55 |
+ local width=${#s1} |
56 |
+ [[ ${#s2} -gt ${width} ]] && width=${#s2} |
57 |
+ printf "%*s" ${width} "${s1}" |
58 |
+ } |
59 |
+ |
60 |
+ # transform number in KiB into MiB, GiB or TiB based on size |
61 |
+ human() { |
62 |
+ local s1=$1 |
63 |
+ local units=( KiB MiB GiB TiB ) |
64 |
+ |
65 |
+ s1=$((s1 * 10)) |
66 |
+ while [[ ${s1} -gt 10240 && ${#units[@]} -gt 1 ]] ; do |
67 |
+ s1=$((s1 / 1024 )) |
68 |
+ units=( ${units[@]:1} ) |
69 |
+ done |
70 |
+ |
71 |
+ local r=${s1: -1} |
72 |
+ s1=$((s1 / 10)) |
73 |
+ printf "%s.%s %s" "${s1}" "${r}" "${units[0]}" |
74 |
+ } |
75 |
+ |
76 |
+ size() { |
77 |
+ local s1=$1 |
78 |
+ local s2=$2 |
79 |
+ local out="$(padl "${s1}" "${s2}") KiB" |
80 |
+ |
81 |
+ if [[ ${s1} -gt 1024 ]] ; then |
82 |
+ s1=$(human ${s1}) |
83 |
+ if [[ ${s2} -gt 1024 ]] ; then |
84 |
+ s2=$(human ${s2}) |
85 |
+ s1=$(padl ${s1} ${s2}) |
86 |
+ fi |
87 |
+ out+=" (${s1})" |
88 |
+ fi |
89 |
+ echo "${out}" |
90 |
+ } |
91 |
+ einfo "Final size of build directory: $(size ${nsz[0]} ${isz[0]})" |
92 |
+ einfo "Final size of installed tree: $(size ${isz[0]} ${nsz[0]})" |
93 |
+ ) |
94 |
__vecho |
95 |
fi |