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
|
#!/usr/bin/env python
"""Script to upload benchmark results to an s3 location."""
import argparse
import os
from datetime import datetime
from subprocess import check_call
REPO_ROOT = os.path.dirname(
os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
)
WORKDIR = os.environ.get('PERF_WORKDIR', os.path.join(REPO_ROOT, 'workdir'))
DEFAULT_BUCKET = os.environ.get('PERF_RESULTS_BUCKET')
DATE_FORMAT = "%Y-%m-%d-%H-%M-%S-"
def main(args):
source = get_latest_results_directory(args.directory)
run_id = source.split(os.sep)[-1]
destination = '%s/%s' % (args.bucket, run_id)
check_call(f'aws s3 cp --recursive {source} {destination}', shell=True)
def s3_uri(value):
if not value.startswith('s3://'):
return 's3://' + value
return value
def get_latest_results_directory(parent):
# Check to see if the given directory is a valid directory
if _is_result_dir_format(os.path.split(parent)[-1]):
return parent
# Find the latest valid subdirectory
for d in sorted(os.listdir(parent), reverse=True):
directory = os.path.join(parent, d)
if os.path.isdir(directory) and _is_result_dir_format(d):
return directory
raise ValueError("No valid result directories found in %s" % parent)
def _is_result_dir_format(directory):
try:
datetime.strptime(directory[:20], DATE_FORMAT)
int(directory[20:])
return True
except Exception:
return False
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
'-d',
'--directory',
default=os.path.join(WORKDIR, 'results'),
help='A directory containing multiple test runs or a single test '
'run directory. If this is a directory with multiple test runs, '
'the latest will be uploaded.',
)
parser.add_argument(
'-b',
'--bucket',
default=DEFAULT_BUCKET,
type=s3_uri,
required=DEFAULT_BUCKET is None,
help='An s3uri to upload the results to. This can also be set with '
'the environment variable PERF_RESULTS_BUCKET. If the '
'environment variable is not set, then this argument is '
'required.',
)
main(parser.parse_args())
|