Skip to content

Instantly share code, notes, and snippets.

@aniketbhatnagar
Created February 15, 2019 23:58
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 aniketbhatnagar/13014f963cf8e9781b834992770aedda to your computer and use it in GitHub Desktop.
Save aniketbhatnagar/13014f963cf8e9781b834992770aedda to your computer and use it in GitHub Desktop.
#!/bin/sh
# Usage: ./profile.sh pid output.txt
PROFILED_PID=$1
OUTPUT_FILE=$2
echo "Getting stacktraces from process $PROFILED_PID... Will stop on ^C or when the process exits."
rm -f "$OUTPUT_FILE"
while true; do
jstack "$PROFILED_PID" >> "$OUTPUT_FILE" && sleep 0.5 || break
done
echo
echo "Done! Stacks saved to $OUTPUT_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment