View Single Post
Posts: 118 | Thanked: 59 times | Joined on May 2007
#3
Originally Posted by prankster View Post
battery drainage is more concerned with Xorg though if some one could work on that as well.nice work though and to prove that need testers .
This is very much a case of treating the symptoms rather than trying to cure the underlying problem. But I'm happy with it, so far. Battery life has improved. (Note: all the disclaimers from the original post still apply!)

The version I'm currently using incorporates a few changes. It still checks the hildon-home load every 60 seconds, but now kills the process if two of the last three checks have reported a value over the threshhold.

Code:
#!/bin/sh
#Kill runaway hildon-home processes.
#Checks processor load of hildon-home every 60 seconds, except when screen is unlocked.
#Kills hildon-home if two of three successive checks show load over threshhold
#Contains some leftover code from earlier versions

if [ -e /home/user/hhkills-prev ] #delete backup log, if it exists
then
	rm /home/user/hhkills-prev
fi

if [ -e /home/user/hhkills ] #rename most recent log to backup, if it exists
then
	mv /home/user/hhkills /home/user/hhkills-prev
fi

echo "Start: " `date` > /home/user/hhkills #start new log

#initialize values
HH1=0
HH2=0
HHTHRESH=50  #Threshhold: hildon-home processor loads above this value will be considered excessive
HHPAUSE=60   #Pause between cycles: the script waits this many seconds between checks

#start loop
while 'true'
do
	#shift previous values down
	HH3=$HH2
	HH2=$HH1

	#get screen lock status
	SCRSTAT=`dbus-send --system --type=method_call --dest="com.nokia.mce" --print-reply "/com/nokia/mce/request" com.nokia.mce.request.get_tklock_mode|awk -F "\"" '/g/ {print $2}'`

	if [ "$SCRSTAT" = "unlocked" ]
	then
		HH1=0 #if the screen is unlocked, clear HH1 and HH2; do nothing else this cycle
		HH2=0
	else
		#get processor load of hildon-home
		HHSTAT=`top -n1 | grep hildon-home | awk '{print $7}'` # | awk -F "." '{print $1}'`  #final part truncates value to integer; moved below
		#echo $HHSTAT #used while debugging: sends HHSTAT as float to stdout
		#truncate HHSTAT to integer
		HHSTAT=`echo $HHSTAT  | awk -F "." '{print $1}'`
		#compare HHSTAT to threshhold, set HH1 if above, clear it otherwise
		if [ "$HHSTAT" -gt "$HHTHRESH" ]
		then 
			HH1=1
			echo "hh  $HHSTAT " `date` >> /home/user/hhkills #writes all above-threshhold values to log. Useful when debugging, but makes for very large log.
		else
			HH1=0
		fi
		HHSUM=`expr $HH1 + $HH2 + $HH3`
		#echo $HHSUM #sometimes useful when debugging: sends sum to stdout
		#check if HH1, HH2 and HH3 have all been set. If so, kill hildon-home and log the kill
		if [ "$HHSUM" -ge "2"  ]
		then
			#kill hildon-home and log the kill
			killall hildon-home
			echo "Kill: " `date` >> /home/user/hhkills
			HH1=0  #clear these values and give hildon-home a minute to restart and stabilize
			HH2=0
			sleep 60 
		fi
	fi

	#pause before next cycle
	sleep "$HHPAUSE"

done