forked from jkacur/rteval
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrteval-cmd
executable file
·439 lines (381 loc) · 18.9 KB
/
rteval-cmd
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
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
#!/usr/bin/python3 -tt
# -*- coding: utf-8 -*-
# SPDX-License-Identifier: GPL-2.0-or-later
#
# rteval - script for evaluating platform suitability for RT Linux
#
# This program is used to determine the suitability of
# a system for use in a Real Time Linux environment.
# It starts up various system loads and measures event
# latency while the loads are running. A report is generated
# to show the latencies encountered during the run.
#
# Copyright 2009 - 2013 Clark Williams <williams@redhat.com>
# Copyright 2009 - 2013 David Sommerseth <davids@redhat.com>
# Copyright 2012 - 2013 Raphaël Beamonte <raphael.beamonte@gmail.com>
#
""" Main module of the rteval program """
import sys
import os
import time
import re
import shutil
import argparse
import tempfile
import requests
import lxml.etree
from rteval.Log import Log
from rteval import RtEval, rtevalConfig
from rteval.modules.loads import LoadModules
from rteval.modules.measurement import MeasurementModules
from rteval import cpupower
from rteval.version import RTEVAL_VERSION
from rteval.systopology import SysTopology, parse_cpulist_from_config
from rteval.modules.loads.kcompile import ModuleParameters
import rteval.cpulist_utils as cpulist_utils
compress_cpulist = cpulist_utils.compress_cpulist
expand_cpulist = cpulist_utils.expand_cpulist
collapse_cpulist = cpulist_utils.collapse_cpulist
def summarize(repfile, xslt):
""" Summarize an already existing XML report """
isarchive = False
summaryfile = repfile
if repfile.endswith(".tar.bz2"):
import tarfile
try:
t = tarfile.open(repfile)
except:
print(f"Don't know how to summarize {repfile} (tarfile open failed)")
return
element = None
for f in t.getnames():
if f.find('summary.xml') != -1:
element = f
break
if element is None:
print(f"No summary.xml found in tar archive {repfile}")
return
tmp = tempfile.gettempdir()
t.extract(element, path=tmp)
summaryfile = os.path.join(tmp, element)
isarchive = True
# Load the XSLT template
with open(xslt, "r") as xsltfp:
xsltdoc = lxml.etree.parse(xsltfp)
xsltprs = lxml.etree.XSLT(xsltdoc)
# Load the summay.xml report - with some simple sanity checks
with open(summaryfile, "r") as xmlfp:
xmldoc = lxml.etree.parse(xmlfp)
if xmldoc.docinfo.root_name != 'rteval':
raise RuntimeError("The report doesn't seem like a rteval summary report")
# Parse and print the report through the XSLT template - preserve proper encoding
resdoc = xsltprs(xmldoc)
print(str(resdoc))
# Clean up
del resdoc
del xmldoc
del xsltprs
del xsltdoc
if isarchive:
os.unlink(summaryfile)
def parse_options(cfg, parser, cmdargs):
'''parse the command line arguments'''
rtevcfg = cfg.GetSection('rteval')
#
# All the destination variables here should go into the 'rteval' section,
# thus they are prefixed with 'rteval___'.
# See rteval/rtevalConfig::UpdateFromOptionParser() method for more info
#
parser.add_argument("-d", "--duration", dest="rteval___duration",
type=str, default=rtevcfg.duration, metavar="DURATION",
help=f"specify length of test run (default: {rtevcfg.duration})")
parser.add_argument("-v", "--verbose", dest="rteval___verbose",
action="store_true", default=rtevcfg.verbose,
help=f"turn on verbose prints (default: {rtevcfg.verbose})")
parser.add_argument("-q", "--quiet", dest="rteval___quiet",
action="store_true", default=rtevcfg.quiet,
help=f"turn on quiet mode (default: {rtevcfg.quiet})")
parser.add_argument("-w", "--workdir", dest="rteval___workdir",
type=str, default=rtevcfg.workdir, metavar="DIRECTORY",
help=f"top directory for rteval data (default: {rtevcfg.workdir})")
parser.add_argument("-l", "--loaddir", dest="rteval___srcdir",
type=str, default=rtevcfg.srcdir, metavar="DIRECTORY",
help=f"directory for load source tarballs (default: {rtevcfg.srcdir})")
parser.add_argument("-i", "--installdir", dest="rteval___installdir",
type=str, default=rtevcfg.installdir, metavar="DIRECTORY",
help=f"place to locate installed templates (default: {rtevcfg.installdir})")
parser.add_argument("-s", "--sysreport", dest="rteval___sysreport",
action="store_true", default=rtevcfg.sysreport,
help=f'run sysreport to collect system data (default: {rtevcfg.sysreport})')
parser.add_argument("-D", '--debug', dest='rteval___debugging',
action='store_true', default=rtevcfg.debugging,
help=f'turn on debug prints (default: {rtevcfg.debugging})')
parser.add_argument("-Z", '--summarize', dest='rteval___summarize',
action='store_true', default=False,
help='summarize an already existing XML report')
parser.add_argument("-H", '--raw-histogram', dest='rteval___rawhistogram',
action='store_true', default=False,
help='Generate raw histogram data for an already existing XML report')
parser.add_argument("-f", "--inifile", dest="rteval___inifile",
type=str, default=None, metavar="FILE",
help="initialization file for configuring loads and behavior")
parser.add_argument("-a", "--annotate", dest="rteval___annotate",
type=str, default=None, metavar="STRING",
help="Add a little annotation which is stored in the report")
parser.add_argument("-L", "--logging", dest="rteval___logging",
action='store_true', default=False,
help='log the output of the loads in the report directory')
parser.add_argument("-O", "--onlyload", dest="rteval___onlyload",
action='store_true', default=False,
help="only run the loads (don't run measurement threads)")
parser.add_argument("-V", "--version", dest="rteval___version",
action='store_true', default=False,
help='print rteval version and exit')
parser.add_argument("-S", "--source-download", nargs="*", dest="rteval___srcdownload",
type=str, default=None, metavar="KERNEL_VERSION",
help='download a source kernel from kernel.org and exit')
parser.add_argument("--noload", dest="rteval___noload",
action="store_true", default=False,
help="only run the measurements (don't run loads)")
if not cmdargs:
cmdargs = ["--help"]
# if -Z/--summarize is specified, add the files to be summarized to cmd_args, and add -Z to cmd_opts
cmd_args = []
if (sys.argv.count('-Z')+sys.argv.count('--summarize')) > 0:
try:
ind = cmdargs.index('-Z')
except ValueError:
ind = cmdargs.index('--summarize')
cmd_args = cmdargs[ind+1:]
cmdargs = cmdargs[:ind+1]
# if -H/--raw-histogram is specified, add the files to be summarized to cmd_args, and add -H to cmd_opts
elif (sys.argv.count('-H')+sys.argv.count('--raw-histogram')) > 0:
try:
ind = cmdargs.index('-H')
except ValueError:
ind = cmdargs.index('--raw-histogram')
cmd_args = cmdargs[ind+1:]
cmdargs = cmdargs[:ind+1]
cmd_opts = parser.parse_args(args=cmdargs)
# if no kernel version was provided for --source-download, set version to default
if (sys.argv.count('-S')+sys.argv.count('--source-download')) > 0:
if cmd_opts.rteval___srcdownload == []:
cmd_opts.rteval___srcdownload = ModuleParameters()["source"]["default"].replace(".tar.xz", "")
else:
cmd_opts.rteval___srcdownload = cmd_opts.rteval___srcdownload[0]
if cmd_opts.rteval___version:
print(f"rteval version {RTEVAL_VERSION}")
sys.exit(0)
if cmd_opts.rteval___duration:
mult = 1.0
v = cmd_opts.rteval___duration.lower()
if v.endswith('s'):
v = v[:-1]
elif v.endswith('m'):
v = v[:-1]
mult = 60.0
elif v.endswith('h'):
v = v[:-1]
mult = 3600.0
elif v.endswith('d'):
v = v[:-1]
mult = 3600.0 * 24.0
cmd_opts.rteval___duration = float(v) * mult
# Update the config object with the parsed arguments
cfg.UpdateFromOptionParser(cmd_opts)
return cmd_args
def remove_offline(cpulist):
""" return cpulist in collapsed compressed form with only online cpus """
tmplist = expand_cpulist(cpulist)
tmplist = SysTopology().online_cpulist(tmplist)
return collapse_cpulist(tmplist)
if __name__ == '__main__':
from rteval.sysinfo import dmi
# set LD_BIND_NOW to resolve shared library symbols
# note: any string will do, nothing significant about 'rteval'
os.environ['LD_BIND_NOW'] = 'rteval'
try:
# Prepare logging
logger = Log()
logger.SetLogVerbosity(Log.NONE)
# setup initial configuration
config = rtevalConfig.rtevalConfig(logger=logger)
# Before really parsing options, see if we have been given a config file in the args
# and load it - just so that default values are according to the config file
try:
cfgfile = sys.argv[sys.argv.index('-f')+1]
config.Load(cfgfile)
except IndexError:
# Missing file argument
raise RuntimeError('The -f option requires a file name to the configuration file')
except ValueError:
# No configuration file given, load defaults
config.Load()
if not config.HasSection('loads'):
config.AppendConfig('loads', {
'kcompile' : 'module',
'hackbench' : 'module',
'stressng' : 'module'})
if not config.HasSection('measurement'):
config.AppendConfig('measurement', {
'cyclictest' : 'module',
'sysstat' : 'module'})
# Prepare log levels before loading modules, not to have unwanted log messages
rtevcfg = config.GetSection('rteval')
if (sys.argv.count('-v')+sys.argv.count('--verbose')) > 0:
rtevcfg.verbose = True
if (sys.argv.count('-D')+sys.argv.count('--debug')) > 0:
rtevcfg.debugging = True
if (sys.argv.count('-q')+sys.argv.count('--quiet')) > 0:
rtevcfg.quiet = True
loglev = (not rtevcfg.quiet and (Log.ERR | Log.WARN)) \
| (rtevcfg.verbose and Log.INFO) \
| (rtevcfg.debugging and Log.DEBUG)
logger.SetLogVerbosity(loglev)
# check if cpupower is being used
if sys.argv.count('--idle-set') > 0:
rtevcfg.update({'usingCpupower': True})
# Load modules
loadmods = LoadModules(config, logger=logger)
measuremods = MeasurementModules(config, logger=logger)
# parse command line options
parser = argparse.ArgumentParser()
loadmods.SetupModuleOptions(parser)
measuremods.SetupModuleOptions(parser)
cmd_args = parse_options(config, parser, sys.argv[1:])
if rtevcfg.noload:
if rtevcfg.onlyload:
# Make up your mind!
raise RuntimeError('The --noload and --onlyload options are incompatible.')
loadmods = None
# download kernel tarball
if rtevcfg.srcdownload:
logger.log(Log.DEBUG, f"Kernel Version to download = {rtevcfg.srcdownload}")
# handle a kernel version like linux-5.19-rc5
if 'rc' in rtevcfg.srcdownload:
kernel_prefix = re.search(r"\d{1,2}\.\d{1,3}\-[a-z]*\d{1,2}", rtevcfg.srcdownload).group(0)
url = "https://git.kernel.org/torvalds/t/"
else:
kernel_prefix = re.search(r"(\d{1,2}\.\d{1,3}\.\d{1,3})|(\d{1,2}\.\d{1,3})", rtevcfg.srcdownload).group(0)
major_version = re.search(r"\d{1,2}", kernel_prefix).group(0)
url = "https://kernel.org/pub/linux/kernel/v" + major_version + ".x/"
file_ext = rtevcfg.srcdownload.split(kernel_prefix)[-1]
if file_ext and file_ext not in ('.tar.xz', '.tar.gz'):
sys.exit("Invalid file extension for the kernel source. Exiting")
if rtevcfg.srcdownload.endswith(".gz") or 'rc' in rtevcfg.srcdownload:
rtevcfg.srcdownload = "linux-" + kernel_prefix + ".tar.gz"
else:
rtevcfg.srcdownload = "linux-" + kernel_prefix + ".tar.xz"
tarfl = os.path.join(rtevcfg.srcdir, rtevcfg.srcdownload)
# if default kernel packages with rteval-loads exists, do not download/overwrite
default_kernel_file = ModuleParameters().get('source').get('default')
if os.path.exists(tarfl):
if rtevcfg.srcdownload == default_kernel_file:
sys.exit("Default kernel already exists, will not download")
prompt = input("Kernel already exists, download and overwrite anyway? (y/n) ")
prompt = prompt.lower()
if prompt in ('no', 'n'):
sys.exit("Exiting")
elif prompt in ('yes','y'):
# backup the existing kernel in case it needs to be restored later
shutil.move(tarfl, tarfl + ".bkup")
else:
sys.exit("Invalid option. Exiting")
url = url + rtevcfg.srcdownload
print(f"Downloading kernel {url}")
downloaded_file = requests.get(url)
if downloaded_file.status_code != 200:
# restore the kernel file if it exists
if os.path.exists(tarfl + ".bkup"):
shutil.move(tarfl + ".bkup", tarfl)
sys.exit(f"Could not download tar file {rtevcfg.srcdownload}, status code {downloaded_file.status_code}")
with open(tarfl, 'wb') as fd:
fd.write(downloaded_file.content)
logger.log(Log.DEBUG, f"Kernel source {rtevcfg.srcdownload} downloaded successfully")
logger.log(Log.DEBUG, f"Downloaded to directory location: {rtevcfg.srcdir}")
# download was successful, delete the backup file if it exists
if os.path.exists(tarfl + ".bkup"):
os.remove(tarfl + ".bkup")
sys.exit(0)
ldcfg = config.GetSection('loads')
msrcfg = config.GetSection('measurement')
# Remember if cpulists were explicitly set by the user before running
# parse_cpulist_from_config, which generates default value for them
msrcfg_cpulist_present = msrcfg.cpulist != ""
ldcfg_cpulist_present = ldcfg.cpulist != ""
# Parse cpulists using parse_cpulist_from_config to account for
# run-on-isolcpus and relative cpusets
cpulist = parse_cpulist_from_config(msrcfg.cpulist, msrcfg.run_on_isolcpus)
if msrcfg_cpulist_present and not cpulist_utils.is_relative(msrcfg.cpulist) and msrcfg.run_on_isolcpus:
logger.log(Log.WARN, "ignoring --measurement-run-on-isolcpus, since cpulist is specified")
msrcfg.cpulist = collapse_cpulist(cpulist)
cpulist = parse_cpulist_from_config(ldcfg.cpulist)
ldcfg.cpulist = collapse_cpulist(cpulist)
# if we only specified one set of cpus (loads or measurement)
# default the other to the inverse of the specified list
if not ldcfg_cpulist_present and msrcfg_cpulist_present:
tmplist = expand_cpulist(msrcfg.cpulist)
tmplist = SysTopology().invert_cpulist(tmplist)
tmplist = cpulist_utils.online_cpulist(tmplist)
ldcfg.cpulist = collapse_cpulist(tmplist)
if not msrcfg_cpulist_present and ldcfg_cpulist_present:
tmplist = expand_cpulist(ldcfg.cpulist)
tmplist = SysTopology().invert_cpulist(tmplist)
tmplist = cpulist_utils.online_cpulist(tmplist)
msrcfg.cpulist = collapse_cpulist(tmplist)
if ldcfg_cpulist_present:
logger.log(Log.DEBUG, f"loads cpulist: {ldcfg.cpulist}")
# if --onlyload is specified msrcfg.cpulist is unused
if msrcfg_cpulist_present and not rtevcfg.onlyload:
logger.log(Log.DEBUG, f"measurement cpulist: {msrcfg.cpulist}")
logger.log(Log.DEBUG, f"workdir: {rtevcfg.workdir}")
# if --summarize was specified then just parse the XML, print it and exit
if rtevcfg.summarize or rtevcfg.rawhistogram:
if len(cmd_args) < 1:
raise RuntimeError("Must specify at least one XML file with --summarize!")
for x in cmd_args:
if rtevcfg.summarize:
summarize(x, rtevcfg.xslt_report)
elif rtevcfg.rawhistogram:
summarize(x, rtevcfg.xslt_histogram)
sys.exit(0)
if os.getuid() != 0:
print("Must be root to run rteval!")
sys.exit(-1)
logger.log(Log.DEBUG, f'''rteval options:
workdir: {rtevcfg.workdir}
loaddir: {rtevcfg.srcdir}
reportdir: {rtevcfg.reportdir}
verbose: {rtevcfg.verbose}
debugging: {rtevcfg.debugging}
logging: {rtevcfg.logging}
duration: {rtevcfg.duration}
sysreport: {rtevcfg.sysreport}''')
if not os.path.isdir(rtevcfg.workdir):
raise RuntimeError(f"work directory {rtevcfg.workdir} does not exist")
# if idle-set has been specified, enable the idle state via cpupower
if msrcfg.idlestate:
cpupower_controller = cpupower.Cpupower(msrcfg.cpulist, msrcfg.idlestate, logger=logger)
cpupower_controller.enable_idle_state()
rteval = RtEval(config, loadmods, measuremods, logger)
rteval.Prepare(rtevcfg.onlyload)
if rtevcfg.onlyload:
# If --onlyload were given, just kick off the loads and nothing more
# No reports will be created.
loadmods.Start()
nthreads = loadmods.Unleash()
logger.log(Log.INFO, f"Started {nthreads} load threads - will run for {rtevcfg.duration} seconds")
logger.log(Log.INFO, "No measurements will be performed, due to the --onlyload option")
time.sleep(rtevcfg.duration)
loadmods.Stop()
ec = 0
else:
# ... otherwise, run the full measurement suite with loads
ec = rteval.Measure()
logger.log(Log.DEBUG, f"exiting with exit code: {ec}")
# restore previous idle state settings
if msrcfg.idlestate:
cpupower_controller.restore_idle_states()
sys.exit(ec)
except KeyboardInterrupt:
sys.exit(0)