Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
| 3 | # Copyright 2011 Google Inc. All Rights Reserved. |
| 4 | |
| 5 | |
| 6 | class ResultSorter(object): |
| 7 | def __init__(self, benchmark_runs): |
| 8 | self.table = {} |
| 9 | for benchmark_run in benchmark_runs: |
| 10 | benchmark_name = benchmark_run.benchmark_name |
| 11 | label_name = benchmark_run.label_name |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 12 | if not benchmark_run.result: |
| 13 | continue |
Ahmad Sharif | 5ae8a5c | 2012-05-18 10:59:51 -0700 | [diff] [blame] | 14 | for autotest_key in benchmark_run.result.keyvals: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 15 | result_tuple = (benchmark_name, autotest_key, label_name) |
| 16 | if result_tuple not in self.table: |
| 17 | self.table[result_tuple] = [] |
| 18 | |
| 19 | cell = self.table[result_tuple] |
| 20 | index = benchmark_run.iteration - 1 |
| 21 | while index >= len(cell): |
| 22 | cell.append(None) |
| 23 | |
Ahmad Sharif | 5ae8a5c | 2012-05-18 10:59:51 -0700 | [diff] [blame] | 24 | result_value = benchmark_run.result.keyvals[autotest_key] |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 25 | try: |
| 26 | result_value = float(result_value) |
| 27 | except ValueError: |
| 28 | pass |
| 29 | |
| 30 | cell[index] = result_value |
| 31 | |
| 32 | self.autotest_keys = {} |
| 33 | for benchmark_run in benchmark_runs: |
| 34 | benchmark_name = benchmark_run.benchmark_name |
| 35 | if benchmark_name not in self.autotest_keys: |
| 36 | self.autotest_keys[benchmark_name] = {} |
Ahmad Sharif | f395c26 | 2012-10-09 17:48:09 -0700 | [diff] [blame] | 37 | if not benchmark_run.result: |
| 38 | continue |
Ahmad Sharif | 5ae8a5c | 2012-05-18 10:59:51 -0700 | [diff] [blame] | 39 | for autotest_key in benchmark_run.result.keyvals: |
Ahmad Sharif | 0dcbc4b | 2012-02-02 16:37:18 -0800 | [diff] [blame] | 40 | self.autotest_keys[benchmark_name][autotest_key] = True |
| 41 | |
| 42 | def GetAutotestKeys(self, benchmark_name): |
| 43 | return self.autotest_keys[benchmark_name].keys() |
| 44 | |
| 45 | def GetResults(self, benchmark_name, autotest_key, label_name): |
| 46 | try: |
| 47 | return self.table[(benchmark_name, autotest_key, label_name)] |
| 48 | except KeyError: |
| 49 | return [] |