Date: Wed, 20 Jun 2012 16:50:50 +0000 From: rudot@FreeBSD.org To: svn-soc-all@FreeBSD.org Subject: socsvn commit: r238010 - soc2012/rudot/aux Message-ID: <20120620165050.722FA106564A@hub.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: rudot Date: Wed Jun 20 16:50:49 2012 New Revision: 238010 URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238010 Log: scripts for visualising and collecting pcpu usage Added: soc2012/rudot/aux/plot.gnuplot soc2012/rudot/aux/psSum.sh (contents, props changed) Added: soc2012/rudot/aux/plot.gnuplot ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/rudot/aux/plot.gnuplot Wed Jun 20 16:50:49 2012 (r238010) @@ -0,0 +1,5 @@ +set term postscript eps enhanced color +set style line 1 lt 1 lw 1 +set xlabel "CPU percentage" +set ylabel "frequency" +plot "dataSorted.txt" using 1:2 with imp ls 1 title '' Added: soc2012/rudot/aux/psSum.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ soc2012/rudot/aux/psSum.sh Wed Jun 20 16:50:49 2012 (r238010) @@ -0,0 +1,45 @@ +FILE_UNSORTED=data.txt +FILE_SORTED=dataSorted.txt + +if [ -z "$1" ]; then + echo "Usage: $0 user" + exit 1 +else + USER=$1 +fi + +user_pcpu() +{ + ps -U "$1" -o %cpu= | awk 'BEGIN{total = 0}{total = total + $1}END{print total}' +} + +sort_results() +{ + cat $FILE_UNSORTED | tr : "\t" | sort > $FILE_SORTED + rm $FILE_UNSORTED + exit 0 +} + +trap sort_results SIGINT + +echo "Type [Ctrl + c] to exit" +echo "Scanning..." + +while : +do + PCPU=`user_pcpu "$USER"` + LINE=`cat $FILE_UNSORTED 2> /dev/null | grep "^${PCPU}:"` + + if [ -n "$LINE" ]; then + CNT=`echo "$LINE" | cut -d : -f 2` + NEW_CNT=`expr "$CNT" + 1` + ed -s data.txt <<-EOF + ,s/${PCPU}:${CNT}/${PCPU}:${NEW_CNT}/ + wq + EOF + else + echo "$PCPU:1" >> $FILE_UNSORTED + fi + + sleep 1 +done
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120620165050.722FA106564A>