Last active
June 2, 2017 18:24
-
-
Save dwilkins/ed3a3c0b033cafdfb281b5934a926645 to your computer and use it in GitHub Desktop.
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 | |
# Process a compressed rails log file and sort the SQL | |
# statements by frequency | |
# Requires - gzip, ansifilter, sed | |
echo $ARGC | |
COMMANDNAME=`basename $0` | |
if [ $# -lt "1" ] | |
then | |
echo "Usage: $COMMANDNAME COMPRESSEDLOGFILETOPROCESS > OUTPUTFILE" | |
else | |
gzip -dc $1 | ansifilter | grep ' DEBUG --' | cut -d: -f 4-100 | grep -o -E '(CACHE |)\([0-9.]*.ms\) *(SELECT|UPDATE|INSERT|DELETE) [^[]*' | sed "s/CACHE \(([0-9.]*ms)\) /\1 CACHED/g;s/'[^']\+'/'%'/g;s/(\('%',* *\)\+\('%'\)*)/('%','%')/g" | sed "s/\([^$]\)\([0-9]\+\)/\1#/g;s/\(#, \)\+#/#,#/g" | sort | uniq -c | sort -k 1nr | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment