From 8118efa675e75400e9272ac88a00b6faa00ce83e Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Fri, 24 Nov 2017 16:23:28 -0500 Subject: lsinitcpio: Attempt to estimate only decompression time Read time is constant between compression methods and we can't possibly estimate this accurately since reading the image from disk doesn't happen with kernel userland functions, but instead UEFI or 16-bit realmode capabilities. ref: https://bugs.archlinux.org/task/56417 --- lsinitcpio | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lsinitcpio b/lsinitcpio index 7be0649..bcb4a19 100755 --- a/lsinitcpio +++ b/lsinitcpio @@ -150,11 +150,15 @@ analyze_image() { # fallback in case tput failed us columns=${columns:-80} - zsize=$(stat -c %s "$_image") + # instead of reading the size from the inode, insist on reading the entire + # image to ensure that it's in the cache when we decompress. This avoids + # variance in timing and makes the time spent reading from storage roughly + # constant. + zsize=$(wc -c <"$_image") # calculate compression ratio - decomptime=$(TIMEFORMAT=%R; { time decomp "$_image" >/dev/null; } 2>&1) if [[ $_compress ]]; then + decomptime=$(TIMEFORMAT=%R; { time decomp "$_image" >/dev/null; } 2>&1) fullsize=$(decomp "$_image" | wc -c) ratio=.$(( zsize * 1000 / fullsize % 1000 )) fi @@ -162,13 +166,9 @@ analyze_image() { # decompress the image since we need to read from it multiple times. decomp "$_image" | bsdtar -C "$workdir" -xf - || die 'Failed to decompress image' - # collect stats - kernver=("$workdir"/usr/lib/modules/*/) - kernver=${kernver%/} - kernver=${kernver##*/} - - modules=("$workdir/usr/lib/modules/$kernver"/kernel/*.ko*) + modules=("$workdir/usr/lib/modules"/*/kernel/*.ko*) if [[ -f ${modules[0]} ]]; then + IFS=/ read -r _ _ _ kernver _ <<<"${modules[0]#$workdir/}" modules=("${modules[@]##*/}") modules=("${modules[@]%.ko*}") else @@ -182,7 +182,7 @@ analyze_image() { read -r version < "$workdir/VERSION" - # source and read config + # shellcheck disable=SC1090 . "$workdir/config" explicitmod=($MODULES) @@ -198,8 +198,8 @@ analyze_image() { if [[ $_compress ]]; then msg 'Compressed with: %s' "$_compress" msg2 'Uncompressed size: %s (%s ratio)' "$(size_to_human "$fullsize")" "$ratio" + msg2 'Estimated decompression time: %ss' "$decomptime" fi - msg2 'Estimated extraction time: %ss' "$decomptime" printf '\n' if (( ${#modules[*]} )); then -- cgit v1.2.3-24-g4f1b