Last active
March 24, 2021 15:50
-
-
Save mitchhentges/629fa4fb90171186f7164ed91d8f2dfe to your computer and use it in GitHub Desktop.
Diff directories to see which files are contributing to file size regressions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
if [[ -z "$1" || -z "$2" ]]; then | |
echo "usage: ./diff-city.sh new old" | |
exit 1 | |
fi | |
old=$1 | |
new=$2 | |
mkdir -p /tmp/diff-city/ | |
cd $old | |
find . -type f -exec du -ka {} + > /tmp/diff-city/du-old | |
cd .. | |
cd $new | |
find . -type f -exec du -ka {} + > /tmp/diff-city/du-new | |
cd .. | |
rm -f /tmp/diff-city/report.tmp | |
old_total_lines=$(wc -l < /tmp/diff-city/du-old | xargs) | |
count=0 | |
while read line; do | |
((count+=1)) | |
echo "processing $old manifest: $count / $old_total_lines" | |
IFS=$'\t' read old_size file <<< $line | |
IFS=$'\t' read new_size trash <<< $(cat /tmp/diff-city/du-new | grep "\t$file\$") | |
if [ -z "$new_size" ]; then | |
echo "[$file] -${old_size}k (DELETED)" >> /tmp/diff-city/report.tmp | |
continue | |
fi | |
size_diff=$(($new_size-$old_size)) | |
if [ "$new_size" -eq "$old_size" ]; then | |
continue | |
fi | |
echo "[$file] ${size_diff}k" >> /tmp/diff-city/report.tmp | |
done < /tmp/diff-city/du-old | |
new_total_lines=$(wc -l < /tmp/diff-city/du-new | xargs) | |
count=0 | |
while read line; do | |
((count+=1)) | |
echo "processing $new manifest: $count / $new_total_lines" | |
IFS=$'\t' read size file <<< $line | |
IFS=$'\t' read exists_before <<< $(cat /tmp/diff-city/du-old | { grep "\t$file\$" || true; }) | |
if [ -z "$exists_before" ]; then | |
echo "[$file] ${size}k (NEW)" >> /tmp/diff-city/report.tmp | |
fi | |
done < /tmp/diff-city/du-new | |
sort -k2 -n -r /tmp/diff-city/report.tmp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment