Skip to content

Instantly share code, notes, and snippets.

@mitchhentges
Last active March 24, 2021 15:50
Show Gist options
  • Save mitchhentges/629fa4fb90171186f7164ed91d8f2dfe to your computer and use it in GitHub Desktop.
Save mitchhentges/629fa4fb90171186f7164ed91d8f2dfe to your computer and use it in GitHub Desktop.
Diff directories to see which files are contributing to file size regressions
#!/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