blob: 3c8b88b8ba2331f8029b89627f6f0445dbeb9093 [file] [log] [blame]
Ahmad Sharif4467f002012-12-20 12:09:49 -08001#!/usr/bin/python
2#
3# Copyright 2012 Google Inc. All Rights Reserved.
4"""Parse perf report data for tabulator."""
5
6import os
7
8from utils import perf_diff
9
Luis Lozanof81680c2013-03-15 14:44:13 -070010
Ahmad Sharif4467f002012-12-20 12:09:49 -080011def ParsePerfReport(perf_file):
12 """It should return a dict."""
13
14 return {"cycles": {"foo": 10, "bar": 20},
15 "cache_miss": {"foo": 20, "bar": 10}}
16
17
18class PerfTable(object):
19 """The class to generate dicts for tabulator."""
20
21 def __init__(self, experiment, label_names):
22 self._experiment = experiment
23 self._label_names = label_names
24 self.perf_data = {}
25 self.GenerateData()
Luis Lozanof81680c2013-03-15 14:44:13 -070026
27 # {benchmark:{perf_event1:[[{func1:number, func2:number,
28 # rows_to_show: number}
29 # {func1: number, func2: number
30 # rows_to_show: number}]], ...},
Ahmad Sharif4467f002012-12-20 12:09:49 -080031 # benchmark2:...}
Luis Lozanof81680c2013-03-15 14:44:13 -070032 # The rows_to_show is temp data recording how many
33 # rows have over 1% running time.
34 self.row_info = {}
35 self.GetRowsToShow()
Ahmad Sharif4467f002012-12-20 12:09:49 -080036
37 def GenerateData(self):
38 for label in self._label_names:
39 for benchmark in self._experiment.benchmarks:
40 for i in range(1, benchmark.iterations+1):
41 dir_name = label + benchmark.name + str(i)
42 dir_name = filter(str.isalnum, dir_name)
43 perf_file = os.path.join(self._experiment.results_directory,
44 dir_name,
45 "perf.data.report.0")
46 self.ReadPerfReport(perf_file, label, benchmark.name, i - 1)
47
48 def ReadPerfReport(self, perf_file, label, benchmark_name, iteration):
49 """Add the data from one run to the dict."""
Luis Lozanof81680c2013-03-15 14:44:13 -070050 if os.path.isfile(perf_file):
51 perf_of_run = perf_diff.GetPerfDictFromReport(perf_file)
52 else:
53 perf_of_run = {}
Ahmad Sharif4467f002012-12-20 12:09:49 -080054 if benchmark_name not in self.perf_data:
55 self.perf_data[benchmark_name] = {}
56 for event in perf_of_run:
57 self.perf_data[benchmark_name][event] = []
58 ben_data = self.perf_data[benchmark_name]
59
60 label_index = self._label_names.index(label)
61 for event in ben_data:
62 while len(ben_data[event]) <= label_index:
63 ben_data[event].append([])
64 data_for_label = ben_data[event][label_index]
65 while len(data_for_label) <= iteration:
66 data_for_label.append({})
Luis Lozanof81680c2013-03-15 14:44:13 -070067 if perf_of_run:
68 data_for_label[iteration] = perf_of_run[event]
69 else:
70 data_for_label[iteration] = {}
71
72 def GetRowsToShow(self):
73 for benchmark in self.perf_data:
74 if benchmark not in self.row_info:
75 self.row_info[benchmark] = {}
76 for event in self.perf_data[benchmark]:
77 rows = 0
78 for run in self.perf_data[benchmark][event]:
79 for iteration in run:
80 if perf_diff.ROWS_TO_SHOW in iteration:
81 rows = max(iteration[perf_diff.ROWS_TO_SHOW], rows)
82 # delete the temp data which stores how many rows of
83 # the perf data have over 1% running time.
84 del iteration[perf_diff.ROWS_TO_SHOW]
85 self.row_info[benchmark][event] = rows