~exarkun/+junk/twisted-benchmarks

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
"""
Evaluate one or more benchmarks and upload the results to a Speedcenter server.
"""

from __future__ import division

from sys import argv, stdout
from os import uname
from sys import executable
from datetime import datetime
from urllib import urlopen, urlencode

import pysvn

import twisted
from twisted.python.filepath import FilePath
from twisted.python.usage import UsageError

from all import allBenchmarks
from benchlib import BenchmarkOptions, Driver


class SpeedcenterOptions(BenchmarkOptions):
    optParameters = [
        ('url', None, None, 'Location of Speedcenter to which to upload results.'),
        ]

    def postOptions(self):
        if not self['url']:
            raise UsageError("The Speedcenter URL must be provided.")



class SpeedcenterDriver(Driver):
    def benchmark_report(self, acceptCount, duration, name):
        print name, acceptCount, duration
        stdout.flush()
        self.results.setdefault(name, []).append((acceptCount, duration))



def reportEnvironment():
    revision = twisted.version.short().split('r', 1)[1]

    client = pysvn.Client()
    [entry] = client.log(
        FilePath(twisted.__file__).parent().path,
        pysvn.Revision(pysvn.opt_revision_kind.number, int(revision)),
        limit=1)
    date = str(datetime.fromtimestamp(entry['date']))

    return {
        'project': 'Twisted',
        'executable': executable,
        'environment': uname()[1],
        'commitid': revision,
        'revision_date': date,
        'result_date': str(datetime.now()),
        }



def main():
    options = SpeedcenterOptions()
    try:
        options.parseOptions(argv[1:])
    except UsageError, e:
        raise SystemExit(str(e))

    driver = SpeedcenterDriver()
    driver.results = {}
    driver.run_jobs(
        allBenchmarks,
        options['duration'], options['iterations'], options['warmup'])

    environment = reportEnvironment()

    for (name, results) in sorted(driver.results.items()):
        rates = [count / duration for (count, duration) in results]
        totalCount = sum([count for (count, duration) in results])
        totalDuration = sum([duration for (count, duration) in results])

        stats = environment.copy()
        stats['benchmark'] = name
        stats['result_value'] = totalCount / totalDuration
        stats['min'] = min(rates)
        stats['max'] = max(rates)

        # Please excuse me.
        fObj = urlopen(options['url'], urlencode(stats))
        print name, fObj.read()
        fObj.close()


if __name__ == '__main__':
    main()