Skip to content

Instantly share code, notes, and snippets.

@dwilkins
Last active June 2, 2017 18:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dwilkins/ed3a3c0b033cafdfb281b5934a926645 to your computer and use it in GitHub Desktop.
Save dwilkins/ed3a3c0b033cafdfb281b5934a926645 to your computer and use it in GitHub Desktop.
#!/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