3 # Synfig Crash Monitor script
4 # Copyright (c) 2009-2010 Konstantin Dmitriev
6 # This package is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License as
8 # published by the Free Software Foundation; either version 2 of
9 # the License, or (at your option) any later version.
11 # This package is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
21 echo "SynfigStudio Crash Monitor is a tool to collect statistics about synfig crashes."
22 echo "All information is collected locally in ~/.synfig/cph directory."
31 [ ! -d ~/.synfig/cph ] && mkdir -p ~/.synfig/cph || true
33 # Detect if crash monitor is already started
34 PDIR=${0%`basename $0`}
35 LCK_FILE=~/.synfig/cph/`basename $0`.lck
36 if [ -f "${LCK_FILE}" ]; then
37 MYPID=`head -n 1 "${LCK_FILE}"`
38 if ! ( ps -p ${MYPID} | grep ${MYPID} >/dev/null ); then
39 # The process is not running
40 # Echo current PID into lock file
41 echo $$ > "${LCK_FILE}"
43 echo "`basename $0` is already running [${MYPID}]. Aborting."
48 # The process is not running
49 # Echo current PID into lock file
50 echo $$ > "${LCK_FILE}"
52 echo `date +%H:%M` "Synfig Crash Monitor started."
57 if [[ $STARTED != 0 ]]; then
58 if [[ $CRASH == 0 ]]; then
59 echo `date +%H:%M` "Synfig exited normally. Session time: $RUNTIME."
61 echo `date +%H:%M` "Crash detected. Version $VERSION.$RELEASE.$BRANCH, session time: $RUNTIME."
63 if [ -e ~/.synfig/cph/log ]; then
65 CURRENTDATE=`date +%Y-%m-%d`
66 LOGMODDATE=`stat -c %y ~/.synfig/cph/log`
67 LOGMODDATE=${LOGMODDATE%% *}
68 if [[ $LOGMODDATE != $CURRENTDATE ]]; then
73 echo $VERSION/$BRANCH/$RELEASE/$REVISION_ID $RUNTIME $CRASH >> ~/.synfig/cph/log
83 echo `date +%H:%M` 'Dumping stats for previous session...'
84 LOGMODDATE=`stat -c %y ~/.synfig/cph/log`
85 LOGMODDATE=${LOGMODDATE%% *}
90 for VER in $VERSIONS; do
91 if [[ $VER == ${LINE%% *} ]]; then
96 [[ $FOUND == 0 ]] && VERSIONS="$VERSIONS ${LINE%% *}"
97 done < ~/.synfig/cph/log
98 echo " Logged versions: ${VERSIONS}"
99 for VER in $VERSIONS; do
100 #generating random record ID
101 ID=$( echo `date` `ps` | md5sum | md5sum )
103 #summarizing time and counting crashes
107 if [[ ${LINE%% *} == $VER ]]; then
108 TIMECOUNT=`expr $TIMECOUNT + $(echo $LINE| cut -f 2 -d ' ')` || true
109 CRASHCOUNT=`expr $CRASHCOUNT + $(echo $LINE| cut -f 3 -d ' ')` || true
111 done < ~/.synfig/cph/log
112 echo " $LOGMODDATE $ID $VER $TIMECOUNT $CRASHCOUNT"
113 echo "$LOGMODDATE $ID $VER $TIMECOUNT $CRASHCOUNT" >> ~/.synfig/cph/stats
115 rm -f ~/.synfig/cph/log
122 if ( ps --no-headers -f -Csynfigstudio |egrep "^`whoami`" > /dev/null ) ; then
123 #synfigstudio process exist
124 if [[ $STARTED == 0 ]]; then
128 P=$(ps --no-headers -Csynfigstudio -o uid,cmd |egrep "^ *`id -u`" | egrep -v "<defunct>" | tr -s ' ' | sed "s|^ *`id -u` *||" | sed "s|/bin/sh *||" | head -n 1)
134 VERSION=`$P/synfig --info|head -n 1|cut -d '-' -f 2`
135 RELEASE=`$P/synfig --info|egrep "Revision:"|cut -d ' ' -f 2`
136 BRANCH=`$P/synfig --info|egrep "Branch:"|cut -d ' ' -f 2-3`
137 REVISION_ID=`$P/synfig --info|egrep "Revision ID:"|cut -d ' ' -f 3`
138 if [[ $BRANCH == '(no branch)' ]]; then
141 echo `date +%H:%M` "Synfig $VERSION.$RELEASE.$BRANCH.$REVISION_ID started."
142 echo `date +%H:%M` "Assuming Synfig installed in $P."
144 let RUNTIME=$RUNTIME+1
147 #no synfigstudio process exist
148 if [[ $STARTED == 1 ]]; then
150 if [ -e ~/.synfig/fifo ]; then