Synfig Studio Crash Monitor.
authorKonstantin Dmitriev <ksee.zelgadis@gmail.com>
Thu, 16 Jul 2009 16:38:58 +0000 (23:38 +0700)
committerKonstantin Dmitriev <ksee.zelgadis@gmail.com>
Thu, 16 Jul 2009 16:38:58 +0000 (23:38 +0700)
If it's run in background it collects synfig runtime and crashes statistics.
All information collected in ~/.synfig/cph.
Later we will use that information to calculate CPH (crash per hour) index
and detect commits producing unstability.

synfig-studio/trunk/synfigstudio-cph-monitor [new file with mode: 0755]

diff --git a/synfig-studio/trunk/synfigstudio-cph-monitor b/synfig-studio/trunk/synfigstudio-cph-monitor
new file mode 100755 (executable)
index 0000000..02fc18a
--- /dev/null
@@ -0,0 +1,138 @@
+#!/bin/bash
+
+# Synfig Crash Monitor script
+# Copyright (c) 2009 Konstantin Dmitriev
+#      This package is free software; you can redistribute it and/or
+#      modify it under the terms of the GNU General Public License as
+#      published by the Free Software Foundation; either version 2 of
+#      the License, or (at your option) any later version.
+#
+#      This package is distributed in the hope that it will be useful,
+#      but WITHOUT ANY WARRANTY; without even the implied warranty of
+#      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+#      General Public License for more details.
+
+set -e
+trap writelog INT
+
+init()
+{
+echo `date +%H:%M` "Synfig Crash Monitor started."
+STARTED=0
+RUNTIME=0
+VERSION=''
+RELEASE=''
+BRANCH=''
+CRASH=0
+[ ! -d ~/.synfig/cph ] && mkdir -p ~/.synfig/cph || true
+}
+
+writelog()
+{
+       if [[ $STARTED != 0 ]]; then
+               if [[ $CRASH == 0 ]]; then
+                       echo `date +%H:%M` "Synfig exited normally. Session time: $RUNTIME."
+               else
+                       echo `date +%H:%M` "Crash detected. Version $VERSION.$RELEASE.$BRANCH, session time: $RUNTIME."
+               fi
+               if [ -e ~/.synfig/cph/log ]; then
+                       #check if dump needed
+                       CURRENTDATE=`date +%Y-%m-%d`
+                       LOGMODDATE=`stat -c %y ~/.synfig/cph/log`
+                       LOGMODDATE=${LOGMODDATE%% *}
+                       if [[ $LOGMODDATE != $CURRENTDATE ]]; then
+                               dumpstats
+                       fi
+               fi
+               #write log
+               echo $VERSION/$BRANCH/$RELEASE $RUNTIME $CRASH >> ~/.synfig/cph/log
+               CRASH=0
+               RUNTIME=0
+       else
+               echo
+       fi
+}
+
+dumpstats()
+{
+       echo `date +%H:%M` 'Dumping stats for previous session...'
+       LOGMODDATE=`stat -c %y ~/.synfig/cph/log`
+       LOGMODDATE=${LOGMODDATE%% *}
+       #get versions
+       VERSIONS=''
+       while read LINE; do
+               FOUND=0
+               for VER in $VERSIONS; do
+                       if [[ $VER == ${LINE%% *} ]]; then
+                               FOUND=1
+                               break
+                       fi
+               done
+               [[ $FOUND == 0 ]] && VERSIONS="$VERSIONS ${LINE%% *}"
+       done < ~/.synfig/cph/log
+       echo "   Logged versions: ${VERSIONS}"
+       for VER in $VERSIONS; do
+               #generating random record ID
+               ID=$( echo `date` `ps` | md5sum | md5sum )
+               ID="${ID:2:16}"
+               #summarizing time and counting crashes
+               CRASHCOUNT=0
+               TIMECOUNT=0
+               while read LINE; do
+                       if [[ ${LINE%% *} == $VER ]]; then
+                               TIMECOUNT=`expr $TIMECOUNT + $(echo $LINE| cut -f 2 -d ' ')` || true
+                               CRASHCOUNT=`expr $CRASHCOUNT + $(echo $LINE| cut -f 3 -d ' ')` || true
+                       fi
+               done < ~/.synfig/cph/log
+               echo "   $LOGMODDATE $ID $VER $TIMECOUNT $CRASHCOUNT"
+               echo "$LOGMODDATE $ID $VER $TIMECOUNT $CRASHCOUNT" >> ~/.synfig/cph/stats
+       done
+       rm -f ~/.synfig/cph/log
+       echo '   Done.'
+}
+
+mainloop()
+{
+       while true; do
+               if ( ps -f -u `whoami`|egrep "synfigstudio$" >/dev/null ) ; then
+                       #synfigstudio process exist
+                       if [[ $STARTED == 0 ]]; then
+                               STARTED=1
+                               RUNTIME=0
+                               #get version
+                               P=$(ps -f -u `whoami`|egrep "synfigstudio$"| tr -s ' '| cut -d ' ' -f 8)
+                               echo 
+                               if [ ! -e $P ]; then
+                                       P=`which $P`
+                               fi
+                               echo $P
+                               P=`dirname $P`
+                               echo "   Assuming synfig installed in $P."
+                               VERSION=`$P/synfig --info|head -n 1|cut -d '-' -f 2`
+                               RELEASE=`$P/synfig --info|egrep "Development version:"|cut -d ' ' -f 3`
+                               BRANCH=`$P/synfig --info|egrep "Branch:"|cut -d ' ' -f 2`
+                               if [[ $BRANCH == '(no branch)' ]]; then
+                                       BRANCH=`$P/synfig --info|egrep "Revision ID:"|cut -d ' ' -f 3`
+                               fi
+                               echo `date +%H:%M` "Synfig $VERSION.$RELEASE.$BRANCH started."
+                       else
+                               let RUNTIME=$RUNTIME+1
+                       fi
+               else
+                       #no synfigstudio process exist
+                       if [[ $STARTED == 1 ]]; then
+                               #detect crash
+                               if [ -e ~/.synfig/fifo ]; then
+                                       CRASH=1
+                               fi
+                               writelog
+                               CRASH=0
+                               STARTED=0
+                       fi
+               fi
+               sleep 1
+       done
+}
+
+init
+mainloop