Skip to content

Commit c860b17

Browse files
committed
calculate-cache.sh: add DEBUG=1 to save collected information as yaml
Signed-off-by: Norio Nomura <[email protected]>
1 parent ba431c2 commit c860b17

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

hack/calculate-cache.sh

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# implementation in https://github.com/lima-vm/lima/pull/2508
44
#
55
# Answer to the question in https://github.com/lima-vm/lima/pull/2508#discussion_r1699798651
6+
7+
# usage: [DEBUG=1] ./hack/calculate-cache.sh
8+
# DEBUG=1 will save the collected information in .calculate-cache-collected-info-{before,after}.yaml
9+
610
set -u -o pipefail
711

812
required_commands=(gh jq limactl sha256sum xxd yq)
@@ -175,13 +179,17 @@ for cache_method in before after; do
175179
"${key}" "${template}" "${location}" "${digest}" "${size}"
176180
done
177181
)
178-
cat <<<"${output_yaml}" >".calculate-cache-collected-info-${cache_method}.yaml"
179-
output_json=$(yq -o=j . <<<"${output_yaml}" | tee ".calculate-cache-collected-info-${cache_method}.json")
182+
output_json=$(yq -o=j . <<<"${output_yaml}")
180183

181184
# print size key
182185
jq --argjson actual_size "${actual_cache_sizes}" -r 'unique_by(.key)|sort_by(.key)|.[]|[.size, $actual_size[.key] // 0, .key]|@tsv' <<<"${output_json}" | size_to_mib
183186
# total
184187
echo "------------"
185188
jq '[unique_by(.key)|.[]|.size]|add' <<<"${output_json}" | size_to_mib
189+
# save the collected information as yaml if DEBUG is set
190+
if [[ -n "${DEBUG:+1}" ]]; then
191+
cat <<<"${output_yaml}" >".calculate-cache-collected-info-${cache_method}.yaml"
192+
echo "Saved the collected information in .calculate-cache-collected-info-${cache_method}.yaml"
193+
fi
186194
echo ""
187195
done

0 commit comments

Comments
 (0)