~exarkun/twisted-benchmarks/trunk

« back to all changes in this revision

Viewing changes to speedcenter.py

  • Committer: Jean-Paul Calderone
  • Date: 2011-07-22 11:00:08 UTC
  • Revision ID: exarkun@divmod.com-20110722110008-mdd0c3bmb6pmn0qt
A lot of hacks to get speedcenter multiprocess operation working

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
 
6
6
from __future__ import division
7
7
 
8
 
from sys import argv, stdout
 
8
if __name__ == '__main__':
 
9
    from sys import argv
 
10
    from all import allBenchmarks
 
11
    from speedcenter import SpeedcenterDriver
 
12
    print SpeedcenterDriver().multidriver(allBenchmarks, argv[1:])
 
13
    raise SystemExit()
 
14
 
9
15
from os import uname
10
16
from sys import executable
11
17
from datetime import datetime
15
21
from twisted.python.filepath import FilePath
16
22
from twisted.python.usage import UsageError
17
23
 
18
 
from all import allBenchmarks
19
24
from benchlib import BenchmarkOptions, Driver
20
25
 
21
26
# Unfortunately, benchmark name is the primary key for speedcenter
31
36
    }
32
37
 
33
38
 
34
 
class SpeedcenterOptions(BenchmarkOptions):
35
 
    optParameters = [
36
 
        ('url', None, None, 'Location of Speedcenter to which to upload results.'),
37
 
        ]
38
 
 
39
 
    def postOptions(self):
40
 
        if not self['url']:
41
 
            raise UsageError("The Speedcenter URL must be provided.")
42
 
 
43
 
 
44
 
 
45
 
class SpeedcenterDriver(Driver):
46
 
    def benchmark_report(self, acceptCount, duration, name):
47
 
        print name, acceptCount, duration
48
 
        stdout.flush()
49
 
        self.results.setdefault(name, []).append((acceptCount, duration))
50
 
 
51
 
 
52
 
 
53
39
def reportEnvironment():
54
40
    revision = twisted.version.short().split('r', 1)[1]
55
41
 
80
66
        }
81
67
 
82
68
 
83
 
 
84
 
def main():
85
 
    options = SpeedcenterOptions()
86
 
    try:
87
 
        options.parseOptions(argv[1:])
88
 
    except UsageError, e:
89
 
        raise SystemExit(str(e))
90
 
 
 
69
class SpeedcenterOptions(BenchmarkOptions):
 
70
    optParameters = [
 
71
        ('url', None, None,
 
72
         'Location of Speedcenter to which to upload results.'),
 
73
        ]
 
74
 
 
75
    def postOptions(self):
 
76
        if not self['url']:
 
77
            raise UsageError("The Speedcenter URL must be provided.")
 
78
 
 
79
 
 
80
 
 
81
class SpeedcenterDriver(Driver):
 
82
    options = SpeedcenterOptions
 
83
 
 
84
    def __init__(self):
 
85
        super(SpeedcenterDriver, self).__init__()
 
86
        self.results = {}
 
87
 
 
88
 
 
89
    def benchmark_report(self, acceptCount, duration, name):
 
90
        self.results.setdefault(name, []).append((acceptCount, duration))
 
91
 
 
92
 
 
93
    def multidriver(self, benchmarks, argv):
 
94
        raw = super(SpeedcenterDriver, self).multidriver(benchmarks, argv)
 
95
        results = {}
 
96
        for (name, stringValue) in raw.iteritems():
 
97
            name = name.split('.')[0]
 
98
            value = eval(stringValue).values()[0]
 
99
            results[name] = value
 
100
 
 
101
        environment = reportEnvironment()
 
102
 
 
103
        for (name, values) in sorted(results.items()):
 
104
            rates = [count / duration for (count, duration) in values]
 
105
            totalCount = sum([count for (count, duration) in values])
 
106
            totalDuration = sum([duration for (count, duration) in values])
 
107
 
 
108
            name = SPEEDCENTER_NAMES.get(name, name)
 
109
            stats = environment.copy()
 
110
            stats['benchmark'] = name
 
111
            stats['result_value'] = totalCount / totalDuration
 
112
            stats['min'] = min(rates)
 
113
            stats['max'] = max(rates)
 
114
 
 
115
            # Please excuse me.
 
116
            fObj = urlopen(self.options['url'], urlencode(stats))
 
117
            print name, fObj.read()
 
118
            fObj.close()
 
119
 
 
120
def main(argv):
91
121
    driver = SpeedcenterDriver()
92
 
    driver.results = {}
93
 
    driver.run_jobs(
94
 
        allBenchmarks,
95
 
        options['duration'], options['iterations'], options['warmup'])
96
 
 
97
 
    environment = reportEnvironment()
98
 
 
99
 
    for (name, results) in sorted(driver.results.items()):
100
 
        rates = [count / duration for (count, duration) in results]
101
 
        totalCount = sum([count for (count, duration) in results])
102
 
        totalDuration = sum([duration for (count, duration) in results])
103
 
 
104
 
        name = SPEEDCENTER_NAMES.get(name, name)
105
 
        stats = environment.copy()
106
 
        stats['benchmark'] = name
107
 
        stats['result_value'] = totalCount / totalDuration
108
 
        stats['min'] = min(rates)
109
 
        stats['max'] = max(rates)
110
 
 
111
 
        # Please excuse me.
112
 
        fObj = urlopen(options['url'], urlencode(stats))
113
 
        print name, fObj.read()
114
 
        fObj.close()
115
 
 
116
 
 
117
 
if __name__ == '__main__':
118
 
    main()
 
122
    driver.main(argv)
 
123
    print driver.results