Created
February 23, 2015 10:44
-
-
Save andrewslotin/57753cb80b9223a741a8 to your computer and use it in GitHub Desktop.
Get stats from golang memory allocation trace log
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 | |
function realpath() { | |
local file_path="$1" | |
pushd $(dirname "$file_path") > /dev/null 2>&1 | |
echo `pwd -P`/`basename "$file_path"` | |
popd > /dev/null 2>&1 | |
} | |
function usage() { | |
echo "USAGE: $0 <package_name> <log_file>" >&2 | |
exit 2 | |
} | |
[ $# -ne 2 ] && usage | |
declare PACKAGE_NAME=$(echo $1 | sed 's~\/~\\\/~g'); shift | |
declare INPUT_FILE=$(realpath "$1"); shift | |
declare TEMPDIR=`mktemp -d /tmp/stat_alloc.XXXXXX` || exit 1 | |
pushd $TEMPDIR > /dev/null 2>&1 | |
split -a 5 -p '^\s*$' $INPUT_FILE alloc_ || exit 1 | |
declare -i i=0 | |
declare allfiles=(*) | |
declare -i numfiles=${#allfiles[@]} | |
unset allfiles | |
stats=$(for f in * ; do | |
echo -ne "\rProcessed: $((100*i++/numfiles))%" >&2 | |
awk "/^$PACKAGE_NAME/ { gsub(/\([a-z0-9x,\. ]+\)\$/, \"\"); print \$0; exit }" "$f" | |
done) | |
echo -ne "\r" | |
echo "$stats" | sort | uniq -c | sort -nr | |
popd > /dev/null 2>&1 | |
rm -rf $TEMPDIR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment