add frontend matrix for performance benchmarks

Signed-off-by: Martin J. Bligh <mbligh@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@694 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/tko/db.py b/tko/db.py
index f696a42..32b02b4 100644
--- a/tko/db.py
+++ b/tko/db.py
@@ -41,21 +41,24 @@
 			sys.stderr.write('SQL: ' + str(value) + '\n')
 
 
-	def select(self, fields, table, where):
+	def select(self, fields, table, where, distinct = False):
 		"""\
 			select fields from table where {dictionary}
 		"""
-		cmd = 'select %s from %s' % (fields, table)
-		values = []
+		cmd = ['select']
+		if distinct:
+			cmd.append('distinct')
+		cmd += [fields, 'from', table]
 
+		values = []
 		if where:
 			keys = [field + '=%s' for field in where.keys()]
 			values = [where[field] for field in where.keys()]
 
-			cmd = cmd + ' where ' + ' and '.join(keys)
+			cmd.append(' where ' + ' and '.join(keys))
 
-		self.dprint('%s %s' % (cmd,values))
-		self.cur.execute(cmd, values)
+		self.dprint('%s %s' % (' '.join(cmd),values))
+		self.cur.execute(' '.join(cmd), values)
 		return self.cur.fetchall()
 
 
diff --git a/tko/frontend.py b/tko/frontend.py
index d08fd80..3bd4c86 100755
--- a/tko/frontend.py
+++ b/tko/frontend.py
@@ -31,11 +31,11 @@
 
 class test:
 	@classmethod
-	def select(klass, db, where = {}):
+	def select(klass, db, where = {}, distinct = False):
 		fields = ['test_idx', 'job_idx', 'test', 'subdir', 
 			  'kernel_idx', 'status', 'reason', 'machine']
 		tests = []
-		for row in db.select(','.join(fields), 'tests', where):
+		for row in db.select(','.join(fields), 'tests', where, distinct):
 			tests.append(klass(db, *row))
 		return tests
 
diff --git a/tko/machine_benchmark.cgi b/tko/machine_benchmark.cgi
new file mode 100755
index 0000000..f279343
--- /dev/null
+++ b/tko/machine_benchmark.cgi
@@ -0,0 +1,61 @@
+#!/usr/bin/python
+
+import cgi, cgitb, os, sys, re
+cgitb.enable()
+
+tko = os.path.dirname(os.path.realpath(os.path.abspath(sys.argv[0])))
+sys.path.insert(0, tko)
+import db, display, frontend
+
+html_root = 'http://test.kernel.org/google/'
+db = db.db()
+
+benchmark_key = {
+'kernbench' : 'elapsed',
+'dbench' : 'throughput',
+}
+
+def main():
+	print "Content-type: text/html\n"
+	sys.stdout.flush()
+
+	rows = db.select('test', 'tests', {}, distinct = True)
+	benchmarks = []
+	for row in rows:
+		benchmark = row[0]
+		testname = re.sub(r'\..*', '', benchmark)
+		if not benchmark_key.has_key(testname):
+			continue
+		benchmarks.append(benchmark)
+	benchmarks = display.sort_tests(benchmarks)
+
+	rows = db.select('machine', 'jobs', {}, distinct = True)
+	machines = [row[0] for row in rows]
+
+	print '<h1>Performance</h1>'
+
+	header_row =  [ display.box('Benchmark', header=True) ]
+	header_row += [ display.box(benchmark, header=True) for benchmark in benchmarks ]
+	
+	matrix = [header_row]
+	for machine in machines:
+		row = [display.box(machine)]
+		for benchmark in benchmarks:
+			where = { 'machine' : machine, 'subdir' : benchmark }
+			rows = db.select('count(test_idx)', 'tests', where)
+			count = rows[0][0]
+			if not count:
+				row.append(display.box(None))
+				continue
+			testname = re.sub(r'\..*', '', benchmark)
+			url = 'machine_test_attribute_graph.cgi'
+			url += '?machine=%s&benchmark=%s&key=%s' % \
+				(machine, benchmark, benchmark_key[testname])
+			html = '<a href="%s">%d</a>' % (url, count)
+			row.append(display.box(html))
+		matrix.append(row)
+	matrix.append(header_row)
+
+	display.print_table(matrix)
+
+main()