Improved code

pull/257/head
Anna Kogan 12 years ago
parent e1331b44f5
commit f57d692cd7
  1. 46
      modules/ts/misc/perf_tests_timing.py

@ -7,28 +7,24 @@ from operator import itemgetter, attrgetter
from summary import getSetName, alphanum_keyselector from summary import getSetName, alphanum_keyselector
if __name__ == "__main__": if __name__ == "__main__":
usage = "%prog <log_name>.xml" usage = "%prog <log_name>.xml [...]"
parser = OptionParser(usage = usage) parser = OptionParser(usage = usage)
for arg in sys.argv: parser.add_option("-o", "--output", dest = "format",
print arg help = "output results in text format (can be 'txt', 'html' or 'auto' - default)",
metavar = 'FMT', default = 'auto')
parser.add_option("-o", "--output", dest="format",
help="output results in text format (can be 'txt', 'html' or 'auto' - default)",
metavar="FMT", default="auto")
(options, args) = parser.parse_args() (options, args) = parser.parse_args()
options.generateHtml = detectHtmlOutputType(options.format)
if 1 != len(args): if 1 != len(args):
parser.print_help() parser.print_help()
exit(0) exit(0)
options.generateHtml = detectHtmlOutputType(options.format)
# expand wildcards and filter duplicates # expand wildcards and filter duplicates
file = os.path.abspath(args[0]) file = os.path.abspath(args[0])
if not os.path.isfile(file): if not os.path.isfile(file):
print 'Incorrect file name!' sys.stderr.write("IOError reading \"" + file + "\" - " + str(err) + os.linesep)
parser.print_help() parser.print_help()
exit(0) exit(0)
@ -71,7 +67,8 @@ if __name__ == "__main__":
groupName = next(c for c in cases if c).shortName() groupName = next(c for c in cases if c).shortName()
if groupName != prevGroupName: if groupName != prevGroupName:
if prevGroupName != None: if prevGroupName != None:
testsuits.append((prevGroupName, suit_time, has_failed)) testsuits.append({'name': prevGroupName, 'time': suit_time, \
'failed': has_failed})
has_failed = False has_failed = False
suit_time = 0 suit_time = 0
prevGroupName = groupName prevGroupName = groupName
@ -79,29 +76,30 @@ if __name__ == "__main__":
for i in range(setsCount): for i in range(setsCount):
case = cases[i] case = cases[i]
if not case is None: if not case is None:
if case.get("status") == "run": if case.get('status') == 'run':
suit_time += case.get("time") suit_time += case.get('time')
if case.get("status") == "failed": if case.get('status') == 'failed':
has_failed = True has_failed = True
tbl = table() tbl = table()
# header # header
tbl.newColumn("name", "Name", align = "left", cssclass = "col_name") tbl.newColumn('name', 'Name of testsuit', align = 'left', cssclass = 'col_name')
tbl.newColumn("time", "Time (ms)", align = "left", cssclass = "col_name") tbl.newColumn('time', 'Time (ms)', align = 'left', cssclass = 'col_name')
tbl.newColumn("failed", "Failed tests", align = "center", cssclass = "col_name") tbl.newColumn('failed', 'Failed tests', align = 'center', cssclass = 'col_name')
# rows # rows
for suit in sorted(testsuits, key=lambda suit: suit[1], reverse=True): for suit in sorted(testsuits, key = lambda suit: suit['time'], reverse = True):
tbl.newRow() tbl.newRow()
tbl.newCell("name", suit[0]) tbl.newCell('name', suit['name'])
tbl.newCell("time", formatValue(suit[1], "", ""), suit[1]) tbl.newCell('time', formatValue(suit['time'], '', ''), suit['time'])
if (suit[2]): if (suit['failed']):
tbl.newCell("failed", "Yes") tbl.newCell('failed', 'Yes')
else:
tbl.newCell('failed', ' ')
# output table # output table
if options.generateHtml: if options.generateHtml:
htmlPrintHeader(sys.stdout, "Timings of %s tests from %s test logs" % (len(test_cases), setsCount))
tbl.htmlPrintTable(sys.stdout) tbl.htmlPrintTable(sys.stdout)
htmlPrintFooter(sys.stdout) htmlPrintFooter(sys.stdout)
else: else:

Loading…
Cancel
Save