2017-10-31 04:41:46 +03:00
|
|
|
#!/usr/bin/python2
|
2015-11-20 20:18:12 +03:00
|
|
|
#
|
|
|
|
# Copyright 2015 The ANGLE Project Authors. All rights reserved.
|
|
|
|
# Use of this source code is governed by a BSD-style license that can be
|
|
|
|
# found in the LICENSE file.
|
|
|
|
#
|
|
|
|
# perf_test_runner.py:
|
|
|
|
# Helper script for running and analyzing perftest results. Runs the
|
2018-10-30 22:14:52 +03:00
|
|
|
# tests in an infinite batch, printing out the mean and coefficient of
|
|
|
|
# variation of the population continuously.
|
2015-11-20 20:18:12 +03:00
|
|
|
#
|
|
|
|
|
2018-08-07 22:27:49 +03:00
|
|
|
import glob
|
2015-11-20 20:18:12 +03:00
|
|
|
import subprocess
|
|
|
|
import sys
|
|
|
|
import os
|
2015-12-17 18:10:02 +03:00
|
|
|
import re
|
|
|
|
|
|
|
|
base_path = os.path.abspath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'))
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2018-08-07 22:27:49 +03:00
|
|
|
# Might have to add lower case "release" in some configurations.
|
|
|
|
perftests_paths = glob.glob('out/*Release*')
|
2018-11-15 00:24:25 +03:00
|
|
|
metric = 'wall_time'
|
|
|
|
max_experiments = 10
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2017-05-05 11:41:29 +03:00
|
|
|
binary_name = 'angle_perftests'
|
|
|
|
if sys.platform == 'win32':
|
|
|
|
binary_name += '.exe'
|
2016-04-21 21:13:53 +03:00
|
|
|
|
2015-11-20 20:18:12 +03:00
|
|
|
scores = []
|
|
|
|
|
|
|
|
# Danke to http://stackoverflow.com/a/27758326
|
|
|
|
def mean(data):
|
|
|
|
"""Return the sample arithmetic mean of data."""
|
|
|
|
n = len(data)
|
|
|
|
if n < 1:
|
|
|
|
raise ValueError('mean requires at least one data point')
|
|
|
|
return float(sum(data))/float(n) # in Python 2 use sum(data)/float(n)
|
|
|
|
|
2018-10-30 22:14:52 +03:00
|
|
|
def sum_of_square_deviations(data, c):
|
2015-11-20 20:18:12 +03:00
|
|
|
"""Return sum of square deviations of sequence data."""
|
|
|
|
ss = sum((float(x)-c)**2 for x in data)
|
|
|
|
return ss
|
|
|
|
|
2018-10-30 22:14:52 +03:00
|
|
|
def coefficient_of_variation(data):
|
|
|
|
"""Calculates the population coefficient of variation."""
|
2015-11-20 20:18:12 +03:00
|
|
|
n = len(data)
|
|
|
|
if n < 2:
|
|
|
|
raise ValueError('variance requires at least two data points')
|
2018-10-30 22:14:52 +03:00
|
|
|
c = mean(data)
|
|
|
|
ss = sum_of_square_deviations(data, c)
|
2015-11-20 20:18:12 +03:00
|
|
|
pvar = ss/n # the population variance
|
2018-10-30 22:14:52 +03:00
|
|
|
stddev = (pvar**0.5) # population standard deviation
|
|
|
|
return stddev / c
|
2015-11-20 20:18:12 +03:00
|
|
|
|
|
|
|
def truncated_list(data, n):
|
|
|
|
"""Compute a truncated list, n is truncation size"""
|
|
|
|
if len(data) < n * 2:
|
|
|
|
raise ValueError('list not large enough to truncate')
|
|
|
|
return sorted(data)[n:-n]
|
|
|
|
|
|
|
|
def truncated_mean(data, n):
|
2018-10-30 22:14:52 +03:00
|
|
|
"""Compute a truncated mean, n is truncation size"""
|
2015-11-20 20:18:12 +03:00
|
|
|
return mean(truncated_list(data, n))
|
|
|
|
|
2018-10-30 22:14:52 +03:00
|
|
|
def truncated_cov(data, n):
|
|
|
|
"""Compute a truncated coefficient of variation, n is truncation size"""
|
|
|
|
return coefficient_of_variation(truncated_list(data, n))
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2016-04-21 21:13:53 +03:00
|
|
|
# Find most recent binary
|
|
|
|
newest_binary = None
|
|
|
|
newest_mtime = None
|
2015-11-20 20:18:12 +03:00
|
|
|
|
|
|
|
for path in perftests_paths:
|
2016-04-21 21:13:53 +03:00
|
|
|
binary_path = os.path.join(base_path, path, binary_name)
|
|
|
|
if os.path.exists(binary_path):
|
2016-11-17 21:00:39 +03:00
|
|
|
binary_mtime = os.path.getmtime(binary_path)
|
2016-04-21 21:13:53 +03:00
|
|
|
if (newest_binary is None) or (binary_mtime > newest_mtime):
|
|
|
|
newest_binary = binary_path
|
|
|
|
newest_mtime = binary_mtime
|
|
|
|
|
|
|
|
perftests_path = newest_binary
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2016-11-17 21:00:39 +03:00
|
|
|
if perftests_path == None or not os.path.exists(perftests_path):
|
2017-05-05 11:41:29 +03:00
|
|
|
print('Cannot find Release %s!' % binary_name)
|
2015-11-20 20:18:12 +03:00
|
|
|
sys.exit(1)
|
|
|
|
|
2017-05-05 11:41:29 +03:00
|
|
|
if sys.platform == 'win32':
|
|
|
|
test_name = 'DrawCallPerfBenchmark.Run/d3d11_null'
|
|
|
|
else:
|
|
|
|
test_name = 'DrawCallPerfBenchmark.Run/gl'
|
2015-11-20 20:18:12 +03:00
|
|
|
|
|
|
|
if len(sys.argv) >= 2:
|
|
|
|
test_name = sys.argv[1]
|
|
|
|
|
2015-12-17 19:37:16 +03:00
|
|
|
print('Using test executable: ' + perftests_path)
|
|
|
|
print('Test name: ' + test_name)
|
|
|
|
|
2018-11-15 00:24:25 +03:00
|
|
|
def get_results(metric, extra_args=[]):
|
|
|
|
process = subprocess.Popen([perftests_path, '--gtest_filter=' + test_name] + extra_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
2017-08-31 21:39:13 +03:00
|
|
|
output, err = process.communicate()
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2018-11-15 00:24:25 +03:00
|
|
|
m = re.search(r'Running (\d+) tests', output)
|
2015-12-17 18:10:02 +03:00
|
|
|
if m and int(m.group(1)) > 1:
|
|
|
|
print("Found more than one test result in output:")
|
|
|
|
print(output)
|
|
|
|
sys.exit(3)
|
|
|
|
|
2018-11-15 00:24:25 +03:00
|
|
|
pattern = metric + r'= ([0-9.]+)'
|
|
|
|
m = re.findall(pattern, output)
|
|
|
|
if m is None:
|
|
|
|
print("Did not find the metric '%s' in the test output:" % metric)
|
|
|
|
print(output)
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
return [float(value) for value in m]
|
|
|
|
|
|
|
|
# Calibrate the number of steps
|
|
|
|
steps = get_results("steps", ["--calibration"])[0]
|
|
|
|
print("running with %d steps." % steps)
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2018-11-15 00:24:25 +03:00
|
|
|
# Loop 'max_experiments' times, running the tests.
|
|
|
|
for experiment in range(max_experiments):
|
|
|
|
experiment_scores = get_results(metric, ["--steps", str(steps)])
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2018-11-15 00:24:25 +03:00
|
|
|
for score in experiment_scores:
|
|
|
|
sys.stdout.write("%s: %.2f" % (metric, score))
|
|
|
|
scores.append(score)
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2018-11-15 00:24:25 +03:00
|
|
|
if (len(scores) > 1):
|
|
|
|
sys.stdout.write(", mean: %.2f" % mean(scores))
|
|
|
|
sys.stdout.write(", variation: %.2f%%" % (coefficient_of_variation(scores) * 100.0))
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2018-11-15 00:24:25 +03:00
|
|
|
if (len(scores) > 7):
|
|
|
|
truncation_n = len(scores) >> 3
|
2018-11-16 15:32:02 +03:00
|
|
|
sys.stdout.write(", truncated mean: %.2f" % truncated_mean(scores, truncation_n))
|
|
|
|
sys.stdout.write(", variation: %.2f%%" % (truncated_cov(scores, truncation_n) * 100.0))
|
2015-11-20 20:18:12 +03:00
|
|
|
|
2018-11-15 00:24:25 +03:00
|
|
|
print("")
|