1 #!/usr/bin/python 2 3 # http://test.kernel.org/perf/kernbench.elm3b6.png 4 5 import cgi, cgitb, os, sys, re, subprocess 6 cgitb.enable() 7 Popen = subprocess.Popen 8 9 import common 10 from autotest_lib.tko import db, display, frontend, plotgraph 11 from autotest_lib.client.common_lib import kernel_versions 12 13 released_kernel = re.compile('2\.\d\.\d+(-smp-)[0-9]{3}\.[0-9]$') 14 rc_kernel = re.compile('2\.\d\.\d+(-smp-)[0-9]{3}\.[0-9]_rc[0-9]$') 15 db = db.db() 16 17 def main(): 18 form = cgi.FieldStorage() 19 20 if form.has_key("benchmark_key"): 21 benchmark_key = form["benchmark_key"].value 22 # input is a list of benchmark:key values -- benchmark1:key1,... 23 # this loop separates this out into two lists 24 benchmark_idx = [] 25 key_idx = [] 26 for benchmark_key_pair in benchmark_key.split(','): 27 (benchmark, key) = benchmark_key_pair.split(':') 28 benchmark_idx.append(benchmark) 29 key_idx.append(key) 30 elif form.has_key("benchmark") and form.has_key("key"): 31 benchmarks = form["benchmark"].value 32 keys = form["key"].value 33 34 benchmark_idx = benchmarks.split(',') 35 key_idx = keys.split(',') 36 else: 37 # Ignore this for by setting benchmark_idx and key_idx to be 38 # empty lists. 39 benchmark_idx = [] 40 key_idx = [] 41 42 machine_idx = form["machine"].value 43 kernel = form["kernel"].value 44 if kernel == "released": 45 kernel = released_kernel 46 if kernel == "rc": 47 kernel = rc_kernel 48 49 machine = frontend.machine.select(db, {'hostname' : machine_idx})[0] 50 51 #get the machine type from machinename 52 for line in open('machines', 'r'): 53 words = line.rstrip().split('\t') 54 if words[0] == machine.hostname: 55 title = '%s (%s)' % (words[-1], machine.hostname) 56 else: 57 title = '%s' % machine.hostname 58 59 graph = plotgraph.gnuplot(title, 'Kernel', 'normalized throughput (%)', xsort = sort_kernels, size = "600,500") 60 for benchmark, key in zip(benchmark_idx, key_idx): 61 reference_value = None 62 data = {} 63 where = { 'subdir' : benchmark, 'machine_idx' : machine.idx , 'status' : 6} 64 65 #select the corresponding kernels and sort by the release version 66 kernels = set([]) 67 kernels_sort = set([]) 68 kernels_idx = set([]) 69 for test in frontend.test.select(db, where): 70 if kernel == "all": 71 kernels.add(test.kernel().printable) 72 kernels_idx.add(str(test.kernel().idx)) 73 74 elif kernel == "experimental": 75 if not re.match(released_kernel, test.kernel().printable)\ 76 and not re.match(rc_kernel, test.kernel().printable): 77 kernels.add(test.kernel().printable) 78 kernels_idx.add(str(test.kernel().idx)) 79 else: 80 if re.match(kernel, test.kernel().printable): 81 kernels.add(test.kernel().printable) 82 kernels_idx.add(str(test.kernel().idx)) 83 kernels_sort = sort_kernels(list(kernels)) 84 85 #get the base value for each benchmark 86 kernel_base = frontend.kernel.select(db, {'printable' : kernels_sort[0]})[0] 87 for test in frontend.test.select(db, { 'subdir' : benchmark, 'machine_idx' : machine.idx, 'kernel_idx' : kernel_base.idx}): 88 iterations = test.iterations() 89 if iterations.has_key(key): 90 reference_value = sum(iterations[key])/len(iterations[key]) 91 break 92 93 wherein = { 'kernel_idx' : kernels_idx } 94 for test in frontend.test.select(db, where, wherein): 95 iterations = test.iterations() 96 if iterations.has_key(key): 97 # Maintain a list of every test result in data. 98 # Initialize this list, if it does not exist. 99 if not data.has_key(test.kernel().printable): 100 data[test.kernel().printable] = list() 101 102 if benchmark == "kernbench": 103 results = [((reference_value / i - 1)*100) for i in iterations[key]] 104 else: 105 results = [((i / reference_value - 1)*100) for i in iterations[key]] 106 data[test.kernel().printable].extend(results) 107 108 graph.add_dataset(benchmark+' ( '+key+' ) ',data) 109 110 graph.plot(cgi_header = True) 111 112 113 def sort_kernels(kernels): 114 return sorted(kernels, key = kernel_versions.version_encode) 115 116 main() 117