Skip to content

Commit

Permalink
create the tar file even if some benchmarks have failed (#2309)
Browse files Browse the repository at this point in the history
* create the tar file even if some benchmarks have failed

* refactoring

Co-authored-by: Jeff Handley <[email protected]>
  • Loading branch information
adamsitnik and jeffhandley authored Mar 21, 2022
1 parent 6862773 commit 91da696
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions scripts/benchmarks_monthly.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from argparse import ArgumentParser, ArgumentTypeError
from datetime import datetime
from logging import getLogger
from subprocess import CalledProcessError

import benchmarks_ci
import tarfile
Expand Down Expand Up @@ -97,6 +98,11 @@ def __main(args: list) -> int:
sdkPath = os.path.join(rootPath, 'tools', 'dotnet', args.architecture)

logPrefix = ''
logger = getLogger()
logLevel = logger.getEffectiveLevel()

def log(text: str):
logger.log(logLevel, logPrefix + text)

if args.dry_run:
logPrefix = '[DRY RUN] '
Expand All @@ -109,13 +115,13 @@ def __main(args: list) -> int:
# Delete any preexisting SDK and results, which allows
# multiple versions to be run from a single command
if os.path.isdir(sdkPath):
getLogger().log(getLogger().getEffectiveLevel(), logPrefix + 'rmdir -r ' + sdkPath)
log('rmdir -r ' + sdkPath)

if not args.dry_run:
shutil.rmtree(sdkPath)

if os.path.isdir(resultsPath):
getLogger().log(getLogger().getEffectiveLevel(), logPrefix + 'rmdir -r ' + resultsPath)
log('rmdir -r ' + resultsPath)

if not args.dry_run:
shutil.rmtree(resultsPath)
Expand All @@ -128,13 +134,19 @@ def __main(args: list) -> int:
if args.bdn_arguments:
benchmarkArgs += ['--bdn-arguments', args.bdn_arguments]

getLogger().log(getLogger().getEffectiveLevel(), logPrefix + 'Executing: benchmarks_ci.py ' + str.join(' ', benchmarkArgs))
log('Executing: benchmarks_ci.py ' + str.join(' ', benchmarkArgs))

if not args.dry_run:
benchmarks_ci.__main(benchmarkArgs)
try:
benchmarks_ci.__main(benchmarkArgs)
except CalledProcessError:
log('benchmarks_ci exited with non zero exit code, please check the log and report benchmark failure')
# don't rethrow if some results were produced, as we want to create the tar file with results anyway
if not os.path.isdir(resultsPath):
raise

getLogger().log(getLogger().getEffectiveLevel(), logPrefix + 'Results were created in the following folder:')
getLogger().log(getLogger().getEffectiveLevel(), logPrefix + ' ' + resultsPath)
log('Results were created in the following folder:')
log(' ' + resultsPath)

timestamp = datetime.now().strftime('%Y-%m-%d-%H-%M')

Expand All @@ -150,8 +162,8 @@ def __main(args: list) -> int:
resultsTar.add(resultsPath, arcname=resultsName)
resultsTar.close()

getLogger().log(getLogger().getEffectiveLevel(), logPrefix + 'Results were collected into the following tar archive:')
getLogger().log(getLogger().getEffectiveLevel(), logPrefix + ' ' + resultsTarPath)
log('Results were collected into the following tar archive:')
log(' ' + resultsTarPath)

if __name__ == '__main__':
__main(sys.argv[1:])

0 comments on commit 91da696

Please sign in to comment.