From 69ad07d60d4ebbdebca8afd9e312ebb1e559c4c8 Mon Sep 17 00:00:00 2001
From: David Kaufmann <astra@ionic.at>
Date: Mon, 30 Jan 2012 15:56:07 +0100
Subject: [PATCH] graph generator added

---
 merge/parseDat.py     | 53 +++++++++++++++++++++++++++++++++++++++++++
 merge/test_threads.sh | 16 +++++++------
 2 files changed, 62 insertions(+), 7 deletions(-)
 create mode 100755 merge/parseDat.py

diff --git a/merge/parseDat.py b/merge/parseDat.py
new file mode 100755
index 0000000..9570440
--- /dev/null
+++ b/merge/parseDat.py
@@ -0,0 +1,53 @@
+#!/usr/bin/env python2
+
+import os, subprocess
+
+def listtofile(listing, file):
+	fd = open(file, 'r')
+	for i in listing:
+		fd.write(i+"\n")
+	fd.close()
+
+def makeGraphs(graphs, graphtitle = "Title", xlabel = "Size of array", ylabel = "Time needed for calculation"):
+	gendir = "stats/generated/"
+	subprocess.call(["mkdir", "-p", gendir])
+	p = subprocess.Popen(['gnuplot'],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
+	# now do the plots
+	for graphfile in graphs:
+		# set output 'filename'
+		p.stdin.write("set terminal png font arial 8 #size 600,300\n")
+		p.stdin.write("set grid\n")
+		p.stdin.write("set datafile separator ';'\n")
+		p.stdin.write("set title 'Timing of each "+graphtitle+"'\n")
+		p.stdin.write("set xlabel '"+xlabel+"'\n")
+		p.stdin.write("set ylabel '"+ylabel+"'\n")
+		p.stdin.write("set output '"+gendir+graphfile+"'\n")
+		# plot 'filename' using 1:2 title 'algorithm' with lines, 'filename2' using 1:2 title 'algo2' with lines
+		plots = []
+		for title, file, cols in graphs[graphfile]:
+			plots.append("'"+file+"' using "+cols+" title '"+title+"' with lines")
+		plotcommand = ", ".join(plots)
+		#print gendir+graphfile
+		p.stdin.write("plot "+plotcommand+"\n")
+	p.communicate()[0]
+	p.stdin.close()
+
+statsdir = 'stats/raw/'
+runs = os.listdir(statsdir)
+#print runs
+
+gendir = "stats/generated/"
+graphs = []
+outpng = 'merge.png'
+subprocess.call(["mkdir", "-p", gendir])
+for i in runs:
+	runfiles = os.listdir(statsdir+i)
+#	print runfiles
+	for file in runfiles:
+#		print "File: %s%s/%s" % (statsdir, i, file)
+		splitfilename = file.split('.')
+		dict = {}
+		dict['arrsize'] = splitfilename[1]
+		graphs.append((splitfilename[1], statsdir+i+'/'+file, '1:2'))
+
+makeGraphs({outpng: graphs}, "merge")
diff --git a/merge/test_threads.sh b/merge/test_threads.sh
index 9bc3012..85c9792 100755
--- a/merge/test_threads.sh
+++ b/merge/test_threads.sh
@@ -2,20 +2,22 @@
 
 STATFILE=merge
 
-rm $STATFILE.*.dat
-for num in 3 4 5 6 7
+STARTTS="`date --iso-8601=minutes`"
+mkdir -p stats/raw/${STARTTS}
+EXPO="3 4 5 6 7"
+PARTS="1 2 4 5 10 20 25 50 100"
+for num in $EXPO
 do
 	./generate_random.sh $num
 	make clean
 	make
-	for i in 1 2 4 5 10 20 25 50 100
+	for i in $PARTS
 	do
-		SORTMSG=`./sort -t $i`
-		echo "$i:" $SORTMSG
-		echo $SORTMSG | sed "s/took \([0-9]*\.[0-9]*\) seconds\./${i},\1/" >> $STATFILE.$num.dat
+		foo=`expr 10**$num`
+		./sort -t $i | sed "s/took \([0-9]*\.[0-9]*\) seconds\./${i};\1/" | tee -a stats/raw/$STARTTS/$STATFILE.$foo.dat
 	done
 done
 
 if [ $DISPLAY ]; then
-	gnuplot merge.plt && display merge.png
+	./parseDat.py
 fi
-- 
2.43.0