Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Jun 2012 22:02:05 +0000
From:      rudot@FreeBSD.org
To:        svn-soc-all@FreeBSD.org
Subject:   socsvn commit: r238107 - soc2012/rudot/aux
Message-ID:  <20120621220205.033331065674@hub.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: rudot
Date: Thu Jun 21 22:02:04 2012
New Revision: 238107
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238107

Log:
  plotting of collected data

Deleted:
  soc2012/rudot/aux/plot.gnuplot
Modified:
  soc2012/rudot/aux/psSum.sh

Modified: soc2012/rudot/aux/psSum.sh
==============================================================================
--- soc2012/rudot/aux/psSum.sh	Thu Jun 21 21:47:08 2012	(r238106)
+++ soc2012/rudot/aux/psSum.sh	Thu Jun 21 22:02:04 2012	(r238107)
@@ -10,17 +10,47 @@
 
 user_pcpu()
 {
-	ps -U "$1" -o %cpu= | awk 'BEGIN{total = 0}{total = total + $1}END{print total}'
+	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
+}
+
+finalize()
+{
+	sort_results
+	command -v gnuplot > /dev/null && plot_graph
 	exit 0
 }
 
-trap sort_results SIGINT
+plot_graph()
+{
+	XLIMITA=`echo $PCPU_MIN | awk '
+		{
+			if (int($1) == $1) print int($1) - 1;
+			else print int($1)
+		}'`
+
+	XLIMITB=`echo $PCPU_MAX | awk '{print int($1) + 1}'`
+
+	gnuplot > plot.eps <<-EOF
+		set term postscript eps enhanced color
+		set style line 1 lt 1 lw 1
+		set xlabel "CPU percentage"
+		set ylabel "frequency"
+		set yrange [0:]
+		set xrange [${XLIMITA}:${XLIMITB}]
+		plot "$FILE_SORTED" using 1:2 with imp ls 1 title ''
+	EOF
+}
+
+trap finalize SIGINT
 
 echo "Type [Ctrl + c] to exit"
 echo "Scanning..."
@@ -28,6 +58,19 @@
 while :
 do
 	PCPU=`user_pcpu "$USER"`
+
+	[ -z "$PCPU_MIN" ] && PCPU_MIN=$PCPU
+	[ -z "$PCPU_MAX" ] && PCPU_MAX=$PCPU
+	PCPU_MIN_MAX=`echo $PCPU_MIN $PCPU_MAX $PCPU | awk '
+		{
+			if ($1 < $3) min = $1; else min = $3;
+			if ($2 > $3) max = $2; else max = $3;
+			print min ":" max
+		}'`
+	read PCPU_MIN PCPU_MAX <<-EOF
+		`IFS=:; echo $PCPU_MIN_MAX`
+	EOF
+
 	LINE=`cat $FILE_UNSORTED 2> /dev/null | grep "^${PCPU}:"`
 
 	if [ -n "$LINE" ]; then



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20120621220205.033331065674>