aboutsummaryrefslogtreecommitdiff
path: root/postprocessing.py
blob: 1f208c68f7cf992fa8f05218c0d1d2432e04c11c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
#!/usr/bin/env python
#
# Workload Automation v2 for LAVA
#
# Copyright (C) 2014, Linaro Limited.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
#
# Author: Milosz Wasilewski <milosz.wasilewski@linaro.org>
#

import sqlite3
from optparse import OptionParser

ENERGY = 'energy'
TIME = 'time'

results_prepared_statement = """
SELECT spec_id, metric, mean_value(sum(value), count(value)) as mean_value, units, lower_is_better
FROM results
GROUP BY spec_id, metric;
"""

consolidated_prepared_statement = """
SELECT
    spec_id,
    metric,
    relative_value(
        mean_value(sum(value), count(value)),
        (SELECT
            mean_value(sum(value), count(value)) AS ref_mean_value
        FROM results AS ref_results
        WHERE spec_id LIKE ?
            AND metric = ?
            AND workload = ?
        GROUP BY spec_id, metric),
        lower_is_better) as relative_value
FROM results
WHERE metric = ?
AND workload = ?
GROUP BY spec_id, metric;
"""

energy_prepared_statement = """
SELECT spec_id, sum(mean_value) as mean_value
    FROM
        (SELECT spec_id, mean_value(sum(value), count(value)) as mean_value
        FROM results
        WHERE metric IN (%s)
        GROUP BY spec_id, metric)
    GROUP BY spec_id;
"""

def mean_value(total, iterations):
    return float(total)/float(iterations)

def relative_value(value, reference, lower_is_better):
    if lower_is_better:
        return 100*(float(reference)/float(value))
    return 100*(float(value)/float(reference))

if __name__ == '__main__':

    usage = "usage: %prog [OPTIONS]"
    parser = OptionParser(usage=usage)
    parser.add_option("-n", "--job-name", dest="job_name",
                help="Job name to be used as db name in agenda file")
    parser.add_option("-l", "--consolidation-label-list", dest="consolidation_label_list",
                help="Measurement label which is used for consolidating relative results. For example 'Mean Latency'",
                default="Mean Latency")
    parser.add_option("-e", "--energy-label-list", dest="energy_label_list",
                help="List of labels which will be summarizer for power comparison. For example 'arm,vexpress-energy A15 Jcore;arm,vexpress-energy A7 Jcore'. Note execution_time is always used for calculating power from energy numbers",
                default="arm,vexpress-energy A15 Jcore;arm,vexpress-energy A7 Jcore")
    parser.add_option("-w", "--workload", dest="consolidation_workload",
                help="Workflow for which consolidation is performed. For example 'bbench'",
                default="bbench")
    parser.add_option("-m", "--mode", dest="reference_mode",
                help="Reference mode which is used as 100% for relative measurement. Default: a15",
                default="a15")
    parser.add_option("-p", "--path", dest="global_data_path",
                help="Path where results database is located",
                default="/root/db_results/")

    (options, args) = parser.parse_args()

    if not options.job_name:
        parser.error("Job name missing")

    print "job name: %s" % options.job_name
    print "consolidation label list: %s" % options.consolidation_label_list
    print "energy label list: %s" % options.energy_label_list
    print "consolidation workload: %s" % options.consolidation_workload
    print "reference mode: %s" % options.reference_mode
    print "path: %s" % options.global_data_path

    ref_mode = "%%%s%%" % options.reference_mode
    consolidation_label_list = options.consolidation_label_list.split(";")
    energy_label_list = options.energy_label_list.split(";")

    print "opening %s" % (options.global_data_path + options.job_name + ".db")
    conn = sqlite3.connect(options.global_data_path + options.job_name + ".db")
    conn.row_factory = sqlite3.Row
    conn.create_function("mean_value", 2, mean_value)
    conn.create_function("relative_value", 3, relative_value)
    results_cursor = conn.cursor()
    for row in results_cursor.execute(results_prepared_statement):
        print "%s_%s Measurement:%s Units:%s Result:pass" % (
            row['spec_id'],
            row['metric'].replace(" ", "_").replace(",", "_"),
            row['mean_value'],
            row['units'])
    results_cursor.close()

    consolidated_cursor = conn.cursor()
    for label in consolidation_label_list:
        for row in consolidated_cursor.execute(
            consolidated_prepared_statement,
            (ref_mode,
                label,
                options.consolidation_workload,
                label,
                options.consolidation_workload)):
            print "Relative_%s_%s Measurement:%s Units:%% Result:pass" % (
                row['spec_id'],
                row['metric'].replace(" ", "_").replace(",", "_"),
                row['relative_value'])

    consolidated_cursor.close()

    energy_cursor = conn.cursor()
    energy_dict = {}
    ref_energy = None
    ref_time = None
    for row in energy_cursor.execute(energy_prepared_statement % ','.join('?'*len(energy_label_list)), energy_label_list):
        energy_dict[row['spec_id']] = {ENERGY: row['mean_value']}
        if options.reference_mode in row['spec_id']:
            ref_energy = row['mean_value']
    if energy_dict:
        for row in energy_cursor.execute(energy_prepared_statement % ('?'), ("execution_time",)):
            energy_dict[row['spec_id']].update({TIME: row['mean_value']})
            if options.reference_mode in row['spec_id']:
                ref_time = row['mean_value']
    energy_cursor.close()
    if ref_energy and ref_time:
        ref_power = float(ref_energy)/float(ref_time)
        for key, value in energy_dict.iteritems():
            print "Relative_power_%s Measurement:%s Units:%% Result:pass" % (key, 100*((value[ENERGY]/value[TIME])/ref_power))