Skip to content

Instantly share code, notes, and snippets.

@rghose
Created July 18, 2017 14:12
Show Gist options
  • Save rghose/ac5d5bdbc42b19f22768b15e534654ff to your computer and use it in GitHub Desktop.
Save rghose/ac5d5bdbc42b19f22768b15e534654ff to your computer and use it in GitHub Desktop.
Generate stack trace of a running process on OS X
# Written by Cheng Zhao(zcbenz@gmail.com).
# Published under Public Domain.
# Usage: stackshot.sh pid
# Path to stackshot tool.
STACKSHOT='/usr/libexec/stackshot'
# Path to symbolicated report.
TRACEFILE='/Library/Logs/stackshot-syms.log'
if [ -z $1 ]; then
echo "Usage: $0 pid"
exit 1
elif [ $EUID != 0 ]; then
echo 'Please run this script as root user'
exit 2
elif [ ${OSTYPE%%[0-9.]*} != 'darwin' ]; then
echo 'This script can only run on OS X'
exit 3
fi
# Run stackshot.
rm $TRACEFILE
$STACKSHOT -p $1 -i -u || exit $?
# Print report.
cat $TRACEFILE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment