summarylogtreecommitdiffstats
path: root/analyze-shutdown
diff options
context:
space:
mode:
authorJiachen Yang2016-04-24 13:08:04 +0900
committerJiachen Yang2016-04-24 13:08:04 +0900
commit54f54b4234a6f61a1468b2a6bd6b5814a871cdfe (patch)
treee7ae8c6206ce1fe33b4f365330e164fc44dc1c8e /analyze-shutdown
downloadaur-54f54b4234a6f61a1468b2a6bd6b5814a871cdfe.tar.gz
push to aur
Diffstat (limited to 'analyze-shutdown')
-rwxr-xr-xanalyze-shutdown115
1 files changed, 115 insertions, 0 deletions
diff --git a/analyze-shutdown b/analyze-shutdown
new file mode 100755
index 000000000000..40e0919d13e5
--- /dev/null
+++ b/analyze-shutdown
@@ -0,0 +1,115 @@
+#!/bin/bash
+declare -A kill_time
+declare -A exit_time
+declare -a exit_seq
+declare -A pid_comm
+declare -A wait_time
+declare -A killer
+declare -A recv_sig
+
+# ts, pid, signo
+set_kill_time()
+{
+ if [[ "${kill_time[$2]}" ]]; then
+ return
+ fi
+
+ case "$3" in
+ 0 | 1 | 2 | 3 | 6 | 9 | 15)
+ kill_time[$2]=$1
+ ;;
+ esac
+}
+
+# ts, pid
+set_exit_time()
+{
+ if [[ "${exit_time[$2]}" ]]; then
+ return
+ fi
+
+ exit_time[$2]=$1
+ exit_seq+=($pid)
+}
+
+# pid, target_pid, signo
+add_killer()
+{
+ killer[$1]+=" $3>$target_pid"
+}
+
+#ts, pid, signo
+add_signal()
+{
+ recv_sig[$2]+=" $3($1)"
+}
+
+declare -i lineno=0
+while read line; do
+ let lineno++
+ if [[ 0 == ${#line} ]] || [[ '#' == ${line:0:1} ]]; then
+ continue
+ fi
+
+ cols=($line)
+ comm=${cols[0]%-*}
+ pid=${cols[0]#$comm-}
+ ts=${cols[3]%:}
+ ts=${ts//./}
+ func=${cols[4]%(*}
+ func=${func%:}
+
+ if [[ -z "$shut_time" ]]; then
+ shut_time=$ts
+ ts=0
+ else
+ zeros=000000
+ ts=$(($ts-$shut_time))
+ if (( 6 >= ${#ts} )); then
+ ts=${zeros:0:7-${#ts}}$ts
+ fi
+ ts=${ts:0:${#ts}-6}.${ts:${#ts}-6}
+ fi
+
+ case "$func" in
+ sched_process_exit)
+ set_exit_time $ts $pid
+ comm="${cols[5]#comm=}"
+ ;;
+ sys_kill | sys_tgkill)
+ if [[ '->' == "${cols[5]}" ]]; then
+ if [[ '0x0' != "${cols[6]}" ]]; then
+ target_pid=${killer[$pid]##*>}
+ if [[ "$target_pid" ]]; then
+ add_killer $pid $target_pid $signo
+ set_exit_time $ts $target_pid
+ fi
+ fi
+ else
+ let target_pid=0x${cols[5]%,}
+ if [[ 'sys_kill' == "$func" ]]; then
+ let signo=0x${cols[7]%)}
+ else
+ let signo=0x${cols[9]%)}
+ fi
+ set_kill_time $ts $target_pid $signo
+ add_killer $pid $target_pid $signo
+ fi
+ ;;
+ signal_deliver)
+ let signo=${cols[5]#sig=}
+ add_signal $ts $pid $signo
+ ;;
+ sys_exit)
+ set_kill_time $ts $pid -
+ ;;
+ esac
+
+ if [[ -z "${pid_comm[$pid]}" ]] || [[ '<...>' == "${pid_comm[$pid]}" ]]; then
+ pid_comm[$pid]=$comm
+ fi
+done
+
+for pid in "${exit_seq[@]}"; do
+ printf "%15s(%4s) exited at %10ss, got signals: %s\n" ${pid_comm[$pid]} $pid ${exit_time[$pid]} "${recv_sig[$pid]}"
+done