Module: synfig
Branch: zelgadis_master
Commit: e8e10402449a7a1850dd5f4ab3e0e72d04af3f84
URL:    
http://synfig.git.sourceforge.net/git/gitweb.cgi?p=synfig;a=commit;h=e8e10402449a7a1850dd5f4ab3e0e72d04af3f84

Author: Konstantin Dmitriev <ksee.zelga...@gmail.com>
Date:   Thu Jul 16 23:38:58 2009 +0700

Synfig Studio Crash Monitor.

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 |  138 ++++++++++++++++++++++++++
 1 files changed, 138 insertions(+), 0 deletions(-)

diff --git a/synfig-studio/trunk/synfigstudio-cph-monitor 
b/synfig-studio/trunk/synfigstudio-cph-monitor
new file mode 100755
index 0000000..02fc18a
--- /dev/null
+++ b/synfig-studio/trunk/synfigstudio-cph-monitor
@@ -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


------------------------------------------------------------------------------
Enter the BlackBerry Developer Challenge  
This is your chance to win up to $100,000 in prizes! For a limited time, 
vendors submitting new applications to BlackBerry App World(TM) will have
the opportunity to enter the BlackBerry Developer Challenge. See full prize  
details at: http://p.sf.net/sfu/Challenge
_______________________________________________
Synfig-devl mailing list
Synfig-devl@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/synfig-devl

Reply via email to