aboutsummaryrefslogtreecommitdiff
path: root/postprocessing.py
blob: 713e0b3823612afd4135d118603b25d1f6ec63a5 (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
#!/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 copy import deepcopy
from numpy import array, mean
from optparse import OptionParser

SQLITE_DB_GLOBAL_PATH = "/root/db_results/"
VALUE = 'value'
UNIT = 'unit'

modes_prepares_statement = "select distinct(id) from workload_specs;"
metric_prepared_statement = """
SELECT label as workload, metric, value, units, wsr.spec_id
FROM metrics AS m INNER JOIN (
SELECT ws.OID as spec_oid, ws.id as spec_id, uuid, label
FROM workload_specs AS ws INNER JOIN runs AS r ON ws.run_oid = r.OID
) AS wsr ON wsr.spec_oid = m.spec_oid
WHERE spec_id = ?;"""

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")
    (options, args) = parser.parse_args()

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

    conn = sqlite3.connect(SQLITE_DB_GLOBAL_PATH + options.job_name + ".db")
    modes_cursor = conn.cursor()
    metrics = {}
    for mode_row in modes_cursor.execute(modes_prepares_statement):
        metric_cursor = conn.cursor()
        metrics[mode_row[0]] = {}
        for metric_row in metric_cursor.execute(
            metric_prepared_statement, 
            (mode_row[0], )):
            print metric_row
            if metric_row[1] in metrics[mode_row[0]]:
                metrics[mode_row[0]][metric_row[1]][VALUE].append(
                    float(metric_row[2]))
            else:
                metrics[mode_row[0]][metric_row[1]] = {
                    VALUE: [float(metric_row[2])], 
                    UNIT: metric_row[3]}
        metric_cursor.close()
    modes_cursor.close()
    conn.close()
    for key in metrics.iterkeys():
        for metric in metrics[key].iterkeys():
            print "%s_%s Measurement:%s Units:%s Result:pass" % (
                key,
                metric.replace(" ", "_").replace(",", "_"),
                mean(array(metrics[key][metric][VALUE])),
                metrics[key][metric][UNIT])