forked from distcc/distcc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.py
executable file
·236 lines (189 loc) · 8.1 KB
/
benchmark.py
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
#! /usr/bin/python
# benchmark -- automated system for testing distcc correctness
# and performance on various source trees.
# Copyright (C) 2002, 2003, 2004 by Martin Pool
# Copyright 2008 Google Inc.
#
# 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.
# Unlike the main distcc test suite, this program *does* require you
# to manually set up servers on your choice of machines on the
# network, and make sure that they all have appropriate compilers
# installed. The performance measurements obviously depend on the
# network and hardware available.
# It also depends on you having the necessary dependencies to build
# the software. If you regularly build software on Linux you should
# be OK. Some things (the GIMP) will be harder than others.
# On some platforms, it may be impossible to build some targets -- for
# example, Linux depends on having a real-mode x86 assembler, which
# probably isn't installed on Solaris.
# Note that running this program will potentially download many
# megabytes of test data.
# TODO: Support applying patches after unpacking, before building.
# For example, they might be needed to fix -j bugs in the Makefile.
# TODO: In stats, show ratio of build time to slowest build time. (Or
# to first one run?)
# TODO: Allow choice of which compiler and make options to use.
# TODO: Perhaps add option to do "make clean" -- this might be faster
# than unzipping and configuring every time. But perhaps also less
# reproducible.
# TODO: Add option to run tests on different sets or orderings of
# machines.
import os
import re
import sys
import time
from getopt import getopt
from Summary import Summary
from Project import Project, trees
from compiler import CompilerSpec
from Build import Build
import actions, compiler
import ProjectDefs # this adds a lot of definitions to 'trees'
def error(msg):
sys.stderr.write(msg + "\n")
def list_projects():
names = trees.keys()
names.sort()
for n in names:
print n
def find_project(name):
"""
Return the nearest unique match for name.
"""
best_match = None
for pn in trees.keys():
if pn.startswith(name):
if best_match:
raise ValueError, "ambiguous prefix %s" % name
else:
best_match = pn
if not best_match:
raise ValueError, "nothing matches %s" % name
else:
return trees[best_match]
def show_help():
print """Usage: benchmark.py [OPTION]... [PROJECT]...
Test distcc relative performance building different projects.
By default, all known projects are built.
Options:
--help show brief help message
--list-projects show defined projects
--cc=PATH specify base value of CC to pass to configure
--cxx=PATH specify base value of CXX to pass to configure
--output=FILE print final summary to FILE in addition to stdout
-c, --compiler=COMPILER specify one compiler to use; format is
{local|dist|lzo|pump},h<NUMHOSTS>,j<NUMJOBS>
-n N repeat compilation N times
-a, --actions=ACTIONS comma-separated list of action phases
to perform
-f N, --force=N If set to 0, skip download, unpack, and
configure actions if they've already been
successfully performed; if set to 1 (the
default), only skip the download action;
if set to 2, do not skip any action
The C and C++ compiler versions used can be set with the --cc and --cxx
options.
Use of distcc features is set with the -c/--compiler option. The argument
to -c/--compiler has three components, separated by commas. The first
component specifies which distcc features to enabled: "local" means
run cc locally, "distcc" means use plain distcc, "lzo" means enabled
compression, and "pump" means to enable pump mode and compression.
The second component specifies how many distcc hosts to use. The third
component specifies how many jobs to run (the -j/--jobs option to "make").
Multiple -c/--compiler options specify different scenarios to measure.
The default is to measure a few reasonable scenarios.
"""
actions.action_help()
# -a is for developer use only and not documented; unless you're
# careful the results will just be confusing.
######################################################################
def main():
"""Run the benchmark per arguments"""
# Ensure that stdout and stderr are line buffered, rather than
# block buffered, as might be the default when running with
# stdout/stderr redirected to a file; this ensures that the
# output is prompt, even when the script takes a long time for
# a single step, and it also avoids confusing intermingling of
# stdout and stderr.
sys.stdout = os.fdopen(1, "w", 1)
sys.stderr = os.fdopen(2, "w", 1)
sum = Summary()
options, args = getopt(sys.argv[1:], 'a:c:n:f:',
['list-projects', 'actions=', 'help', 'compiler=',
'cc=', 'cxx=', 'output=', 'force='])
opt_actions = actions.default_actions
opt_cc = 'cc'
opt_cxx = 'c++'
opt_output = None
opt_compilers = []
opt_repeats = 1
opt_force = 1
for opt, optarg in options:
if opt == '--help':
show_help()
return
elif opt == '--list-projects':
list_projects()
return
elif opt == '--actions' or opt == '-a':
opt_actions = actions.parse_opt_actions(optarg)
elif opt == '--cc':
opt_cc = optarg
elif opt == '--cxx':
opt_cxx = optarg
elif opt == '--output':
opt_output = optarg
elif opt == '--compiler' or opt == '-c':
opt_compilers.append(optarg)
elif opt == '-n':
opt_repeats = int(optarg)
elif opt == '-f' or opt == '--force':
opt_force = int(optarg)
if opt_compilers:
set_compilers = [compiler.parse_compiler_opt(c, cc=opt_cc, cxx=opt_cxx)
for c in opt_compilers]
else:
set_compilers = compiler.default_compilers(cc=opt_cc, cxx=opt_cxx)
# Find named projects, or run all by default
if args:
chosen_projects = [find_project(name) for name in args]
else:
chosen_projects = trees.values()
for proj in chosen_projects:
# Ignore actions we did in a previous benchmark run, absent -f.
# We only run the project's pre-actions if one of the builds
# needs it because it hasn't successfully run 'configure' yet.
project_actions, _ = actions.remove_unnecessary_actions(
opt_actions, opt_force, proj.did_download(), 0)
proj.pre_actions(project_actions)
for comp in set_compilers:
build = Build(proj, comp, opt_repeats)
_, build_actions = actions.remove_unnecessary_actions(
opt_actions, opt_force,
proj.did_download(), build.did_configure())
build.build_actions(build_actions, sum)
sum.print_table()
# If --output was specified, print the table to the output-file too
if opt_output:
old_stdout = sys.stdout
sys.stdout = open(opt_output, 'w')
try:
sum.print_table()
finally:
sys.stdout.close()
sys.stdout = old_stdout
if __name__ == '__main__':
main()