source: hudson/performance/process @ 2572

Revision 2572, 3.0 KB checked in by wehart, 3 years ago (diff)

Further updates

  • Property svn:executable set to *
Line 
1#!/usr/bin/env python
2
3import os
4import glob
5import sys
6import csv
7import subprocess
8import string
9
10#
11# Add the scripts directory to the Python PATH
12#
13currdir = os.path.dirname(os.path.abspath(__file__))+os.sep
14sys.path.insert(0, currdir)
15
16def read_csv(filename):
17    reader = csv.reader(open(filename, 'rb'))
18    res = []
19    for line in reader:
20       res.append(line)
21    del reader
22    return res
23
24def write_csv(filename, db):
25    writer = csv.writer(open(filename, 'wb'))
26    writer.writerows(db)
27    del writer
28
29def write_tables(db):
30    if not os.path.exists('results'):
31        os.mkdir('results')
32    # Organize the data by build
33    index = set()
34    build = {}
35    for data in db[1:]:
36        if not data[0] in build:
37            build[data[0]] = {}
38        index.add(data[1])
39        test = '.'.join(data[3:6])
40        #test = '.'.join(data[2:6])
41        test = string.replace(test, ' ', '_')
42        if not test in build[data[0]]:
43            build[data[0]][test] = {}
44        build[data[0]][test][data[1]] = data[6]
45    ##print db[0]
46    ##print db[1]
47    ##print build
48    #
49    # Create files
50    #
51    ikeys = list(index)
52    ikeys.sort()
53    for key in build:
54        table = []
55        tests = build[key].keys()
56        tests.sort()
57        table.append( ['build']+tests )
58        for ikey in ikeys:
59            row = [ikey]
60            for test in tests:
61                row.append(build[key][test].get(ikey, ''))
62            table.append(row)
63        filename = 'results/'+key+'.csv'
64        print "Creating results file %s" % filename
65        writer = csv.writer(open(filename, 'wb'))
66        writer.writerows(table)
67    del writer
68
69#
70# MAIN
71#
72#
73# Install Python if it isn't installed
74#
75cwd = os.getcwd()
76os.chdir(currdir)
77if not os.path.exists('python'):
78    rc = subprocess.call(['pyutilib.virtualenv/scripts/vpy_install','python'])
79    sys.stdout.flush()
80    if rc != 0:
81        raise IOError, "Problem installing with virtualenv"
82    rc = subprocess.call(['python/bin/easy_install','numpy'])
83    sys.stdout.flush()
84    if rc != 0:
85        raise IOError, "Problem installing numpy"
86    rc = subprocess.call(['python/bin/easy_install','matplotlib'])
87    sys.stdout.flush()
88    if rc != 0:
89        raise IOError, "Problem installing matplotlib"
90os.chdir(cwd)
91#
92# Load the DB CSV file
93#
94if os.path.exists('db.csv'):
95    db = read_csv('db.csv')
96else:
97    db = []
98db_init = len(db)
99#
100# Process the database
101#
102index = set()
103for item in db:
104    index.add( tuple(item[:2]) )
105#
106for file in sys.argv[1:]:
107    print "Processing file '%s'" % file
108    fdata = read_csv(file)
109    if len(fdata) == 0:
110        print "Empty file!"
111        continue
112    if tuple(fdata[1][:2]) in index:
113        print "Redundant record:", tuple(fdata[1][:2])
114        print "Skipping!"
115        continue
116    if len(db) == 0:
117        db = fdata
118    else:
119        db = db + fdata[1:]
120#
121# Write the file
122#
123if db_init != len(db):
124    write_csv('db.csv',db)
125#
126# Create table
127#
128write_tables(db)
129#
130# Create figures
131#
132cmd = ['performance/python/bin/python','performance/figure.py'] + list(glob.glob('results/*.csv'))
133subprocess.call(cmd)
134
Note: See TracBrowser for help on using the repository browser.