script for capturing thread stack traces with gdb
authorVictor Kirhenshtein <victor@netxms.org>
Thu, 26 May 2016 15:40:07 +0000 (18:40 +0300)
committerVictor Kirhenshtein <victor@netxms.org>
Thu, 26 May 2016 15:40:07 +0000 (18:40 +0300)
tools/capture_netxmsd_threads.sh [new file with mode: 0755]

diff --git a/tools/capture_netxmsd_threads.sh b/tools/capture_netxmsd_threads.sh
new file mode 100755 (executable)
index 0000000..49a253d
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/sh
+exec='netxmsd'
+if [ "x$1" != "x" ]; then
+       exec="$1"
+fi
+pid=`ps -ax | grep netxmsd | grep -v grep | grep -v capture_netxmsd_threads | awk '{ print $1; }'`
+ts=`date +%Y%m%d-%H%M%S`
+cmdfile="/tmp/capture_netxmsd_threads.gdb"
+echo "set height 0" > $cmdfile
+echo "set logging file /tmp/netxmsd-threads.$pid.$ts" >> $cmdfile
+echo "set logging on" >> $cmdfile
+echo "attach $pid" >> $cmdfile
+echo "thread apply all bt" >> $cmdfile
+echo "detach" >> $cmdfile
+echo "quit" >> $cmdfile
+gdb --batch-silent --command=$cmdfile "$exec"
+rm $cmdfile