3 # Synfig Crash Monitor script
4 # Copyright (c) 2009 Konstantin Dmitriev
5 # This package is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU General Public License as
7 # published by the Free Software Foundation; either version 2 of
8 # the License, or (at your option) any later version.
10 # This package is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
20 echo "SynfigStudio Crash Monitor is a tool to collect statistics about synfig crashes."
21 echo "All information is collected locally in ~/.synfig/cph directory."
30 [ ! -d ~/.synfig/cph ] && mkdir -p ~/.synfig/cph || true
32 # Detect if crash monitor is already started
33 PDIR=${0%`basename $0`}
34 LCK_FILE=~/.synfig/cph/`basename $0`.lck
35 if [ -f "${LCK_FILE}" ]; then
36 MYPID=`head -n 1 "${LCK_FILE}"`
37 if ! ( ps -p ${MYPID} | grep ${MYPID} >/dev/null ); then
38 # The process is not running
39 # Echo current PID into lock file
40 echo $$ > "${LCK_FILE}"
42 echo "`basename $0` is already running [${MYPID}]. Aborting."
47 # The process is not running
48 # Echo current PID into lock file
49 echo $$ > "${LCK_FILE}"
51 echo `date +%H:%M` "Synfig Crash Monitor started."
56 if [[ $STARTED != 0 ]]; then
57 if [[ $CRASH == 0 ]]; then
58 echo `date +%H:%M` "Synfig exited normally. Session time: $RUNTIME."
60 echo `date +%H:%M` "Crash detected. Version $VERSION.$RELEASE.$BRANCH, session time: $RUNTIME."
62 if [ -e ~/.synfig/cph/log ]; then
64 CURRENTDATE=`date +%Y-%m-%d`
65 LOGMODDATE=`stat -c %y ~/.synfig/cph/log`
66 LOGMODDATE=${LOGMODDATE%% *}
67 if [[ $LOGMODDATE != $CURRENTDATE ]]; then
72 echo $VERSION/$BRANCH/$RELEASE/$REVISION_ID $RUNTIME $CRASH >> ~/.synfig/cph/log
82 echo `date +%H:%M` 'Dumping stats for previous session...'
83 LOGMODDATE=`stat -c %y ~/.synfig/cph/log`
84 LOGMODDATE=${LOGMODDATE%% *}
89 for VER in $VERSIONS; do
90 if [[ $VER == ${LINE%% *} ]]; then
95 [[ $FOUND == 0 ]] && VERSIONS="$VERSIONS ${LINE%% *}"
96 done < ~/.synfig/cph/log
97 echo " Logged versions: ${VERSIONS}"
98 for VER in $VERSIONS; do
99 #generating random record ID
100 ID=$( echo `date` `ps` | md5sum | md5sum )
102 #summarizing time and counting crashes
106 if [[ ${LINE%% *} == $VER ]]; then
107 TIMECOUNT=`expr $TIMECOUNT + $(echo $LINE| cut -f 2 -d ' ')` || true
108 CRASHCOUNT=`expr $CRASHCOUNT + $(echo $LINE| cut -f 3 -d ' ')` || true
110 done < ~/.synfig/cph/log
111 echo " $LOGMODDATE $ID $VER $TIMECOUNT $CRASHCOUNT"
112 echo "$LOGMODDATE $ID $VER $TIMECOUNT $CRASHCOUNT" >> ~/.synfig/cph/stats
114 rm -f ~/.synfig/cph/log
121 if ( ps --no-headers -f -Csynfigstudio |egrep "^`whoami`" > /dev/null ) ; then
122 #synfigstudio process exist
123 if [[ $STARTED == 0 ]]; then
127 P=$(ps --no-headers -f -Csynfigstudio |egrep "^`whoami`" | tr -s ' '| cut -d ' ' -f 8)
133 VERSION=`$P/synfig --info|head -n 1|cut -d '-' -f 2`
134 RELEASE=`$P/synfig --info|egrep "Revision:"|cut -d ' ' -f 2`
135 BRANCH=`$P/synfig --info|egrep "Branch:"|cut -d ' ' -f 2-3`
136 REVISION_ID=`$P/synfig --info|egrep "Revision ID:"|cut -d ' ' -f 3`
137 if [[ $BRANCH == '(no branch)' ]]; then
140 echo `date +%H:%M` "Synfig $VERSION.$RELEASE.$BRANCH.$REVISION_ID started."
141 echo `date +%H:%M` "Assuming Synfig installed in $P."
143 let RUNTIME=$RUNTIME+1
146 #no synfigstudio process exist
147 if [[ $STARTED == 1 ]]; then
149 if [ -e ~/.synfig/fifo ]; then