def __init__(self): startupdir = 'startup' self.reportjson = os.path.join(TRACEDIR, 'perf-lab-report.json') if helixpayload() and os.path.exists(os.path.join(helixpayload(), startupdir)): self._setstartuppath(os.path.join(helixpayload(), startupdir)) elif helixworkitempayload() and os.path.exists(os.path.join(helixworkitempayload(), startupdir)): self._setstartuppath(os.path.join(helixworkitempayload(), startupdir)) else: relpath = os.path.join(get_artifacts_directory(), startupdir) startupproj = os.path.join('..', '..', 'tools', 'ScenarioMeasurement', 'Startup', 'Startup.csproj') startup = CSharpProject(CSharpProjFile(startupproj, sys.path[0]), os.path.join(os.path.dirname(startupproj), os.path.join(get_artifacts_directory(), startupdir))) if not os.path.exists(relpath): startup.restore(get_packages_directory(), True, getruntimeidentifier()) startup.publish('Release', relpath, True, get_packages_directory(), None, getruntimeidentifier(), None, '--no-restore' ) self._setstartuppath(startup.bin_path)
def __init__(self): if helixpayload() and os.path.exists(os.path.join(helixpayload(), 'SOD')): self._setsodpath(os.path.join(helixpayload(), 'SOD')) elif helixworkitempayload() and os.path.exists(os.path.join(helixworkitempayload(), 'SOD')): self._setsodpath(os.path.join(helixworkitempayload(), 'SOD')) else: relpath = os.path.join(get_artifacts_directory(), 'SOD') sodproj = os.path.join('..', '..', 'tools', 'ScenarioMeasurement', 'SizeOnDisk', 'SizeOnDisk.csproj') sod = CSharpProject(CSharpProjFile(sodproj, sys.path[0]), os.path.join(os.path.dirname(sodproj), os.path.join(get_artifacts_directory(), 'SOD'))) if not os.path.exists(relpath): sod.restore(get_packages_directory(), True, getruntimeidentifier()) sod.publish('Release', relpath, True, get_packages_directory(), None, getruntimeidentifier(), None, '--no-restore' ) self._setsodpath(sod.bin_path)
def upload_results(container_path: str, verbose: bool) -> None: if os.getenv('PERFLAB_UPLOAD_TOKEN') and os.getenv( "HELIX_CORRELATION_ID"): # first find if we have any files at all files = glob(path.join(get_artifacts_directory(), '**', '*perf-lab-report.json'), recursive=True) if files: getLogger().info("Found {0} files".format(len(files))) for file in files: getLogger().info("file: {0}".format(file)) # since we do, we will rename them to include the correlation ID for file in files: directory_name = path.dirname(file) filename = path.basename(file) newname = "{0}-{1}".format( path.join(directory_name, os.getenv('HELIX_CORRELATION_ID')), filename) getLogger().info("copying \n\t{0}\nto\n\t{1}".format( file, newname)) try: os.rename(file, newname) except (FileNotFoundError, OSError) as err: getLogger().error( "Failed to copy {0}, err was: {1}".format( file, err.errno)) if path.isfile(file): getLogger().info( "File still seems to exist, trying with shorter name" ) newname = path.join( directory_name, "{0}-perf-lab-report.json".format( randint(1000, 9999))) getLogger().info( "copying \n\t{0}\nto\n\t{1}".format( file, newname)) try: os.rename(file, newname) except (FileNotFoundError, OSError) as err: getLogger().error( "Still failed to copy {0}".format(file)) renamed_files = glob(path.join(get_artifacts_directory(), '**', '*perf-lab-report.json'), recursive=True) dirname = path.dirname(renamed_files[0]) if len(renamed_files) == 1: # need to work around a bug in azcopy which loses file name if # there is only one file. # https://github.com/Azure/azure-storage-azcopy/issues/410 container_path = path.join(container_path, path.basename(renamed_files[0])) AzCopy(os.environ['PERFLAB_UPLOAD_TOKEN'], container_path, verbose).upload_files( path.join(dirname, '*perf-lab-report.json'))
def __main(args: list) -> int: validate_supported_runtime() args = __process_arguments(args) verbose = not args.quiet setup_loggers(verbose=verbose) if not args.frameworks: raise Exception("Framework version (-f) must be specified.") target_framework_monikers = dotnet \ .FrameworkAction \ .get_target_framework_monikers(args.frameworks) # Acquire necessary tools (dotnet) init_tools(architecture=args.architecture, dotnet_versions=args.dotnet_versions, target_framework_monikers=target_framework_monikers, verbose=verbose) # WORKAROUND # The MicroBenchmarks.csproj targets .NET Core 2.1, 3.0, 3.1 and 5.0 # to avoid a build failure when using older frameworks (error NETSDK1045: # The current .NET SDK does not support targeting .NET Core $XYZ) # we set the TFM to what the user has provided. os.environ['PERFLAB_TARGET_FRAMEWORKS'] = ';'.join( target_framework_monikers) # dotnet --info dotnet.info(verbose=verbose) BENCHMARKS_CSPROJ = dotnet.CSharpProject(project=args.csprojfile, bin_directory=args.bin_directory) if not args.run_only: # .NET micro-benchmarks # Restore and build micro-benchmarks micro_benchmarks.build(BENCHMARKS_CSPROJ, args.configuration, target_framework_monikers, args.incremental, verbose) # Run micro-benchmarks if not args.build_only: upload_container = UPLOAD_CONTAINER try: for framework in args.frameworks: micro_benchmarks.run(BENCHMARKS_CSPROJ, args.configuration, framework, verbose, args) globpath = os.path.join( get_artifacts_directory() if not args.bdn_artifacts else args.bdn_artifacts, '**', '*perf-lab-report.json') except CalledProcessError: getLogger().info("Run failure registered") # rethrow the caught CalledProcessError exception so that the exception being bubbled up correctly. raise dotnet.shutdown_server(verbose) if args.upload_to_perflab_container: import upload upload.upload(globpath, upload_container, UPLOAD_QUEUE, UPLOAD_TOKEN_VAR, UPLOAD_STORAGE_URI)
def __main(args: list) -> int: validate_supported_runtime() args = __process_arguments(args) verbose = not args.quiet setup_loggers(verbose=verbose) target_framework_monikers = micro_benchmarks \ .FrameworkAction \ .get_target_framework_monikers(args.frameworks) # Acquire necessary tools (dotnet) init_tools(architecture=args.architecture, dotnet_versions=args.dotnet_versions, target_framework_monikers=target_framework_monikers, verbose=verbose) # WORKAROUND # The MicroBenchmarks.csproj targets .NET Core 2.0, 2.1, 2.2 and 3.0 # to avoid a build failure when using older frameworks (error NETSDK1045: # The current .NET SDK does not support targeting .NET Core $XYZ) # we set the TFM to what the user has provided. os.environ['PERFLAB_TARGET_FRAMEWORKS'] = ';'.join( target_framework_monikers) # dotnet --info dotnet.info(verbose=verbose) BENCHMARKS_CSPROJ = dotnet.CSharpProject(project=args.csprojfile, bin_directory=args.bin_directory) if not args.run_only: # .NET micro-benchmarks # Restore and build micro-benchmarks micro_benchmarks.build(BENCHMARKS_CSPROJ, args.configuration, target_framework_monikers, args.incremental, verbose) # Run micro-benchmarks if not args.build_only: for framework in args.frameworks: micro_benchmarks.run(BENCHMARKS_CSPROJ, args.configuration, framework, verbose, args) dotnet.shutdown_server(verbose) if args.upload_to_perflab_container: import upload globpath = os.path.join( get_artifacts_directory() if not args.bdn_artifacts else args.bdn_artifacts, '**', '*perf-lab-report.json') #No queue insertion upload.upload(globpath, UPLOAD_CONTAINER, None, UPLOAD_TOKEN_VAR, UPLOAD_STORAGE_URI) #With queue insertion upload.upload(globpath, 'resultsandbox', UPLOAD_QUEUE, UPLOAD_TOKEN_VAR, UPLOAD_STORAGE_URI)
def __init__(self): payload = helixpayload() if payload: self._setstartuppath(os.path.join(payload, 'Startup')) else: startupproj = os.path.join('..', '..', 'tools', 'ScenarioMeasurement', 'Startup', 'Startup.csproj') startup = CSharpProject( CSharpProjFile(startupproj, sys.path[0]), os.path.join( os.path.dirname(startupproj), os.path.join(get_artifacts_directory(), 'startup'))) startup.restore(get_packages_directory(), True, getruntimeidentifier()) startup.publish('Release', os.path.join(get_artifacts_directory(), 'startup'), True, get_packages_directory(), None, getruntimeidentifier(), '--no-restore') self._setstartuppath(startup.bin_path)
def __init__(self): payload_startup = os.path.join(helixpayload(), 'Startup') workitem_startup = os.path.join(helixworkitempayload(), 'Startup') if os.path.exists(payload_startup): self._setstartuppath(payload_startup) elif os.path.exists(workitem_startup): self._setstartuppath(workitem_startup) else: relpath = os.path.join(get_artifacts_directory(), 'startup') startupproj = os.path.join('..', '..', 'tools', 'ScenarioMeasurement', 'Startup', 'Startup.csproj') startup = CSharpProject( CSharpProjFile(startupproj, sys.path[0]), os.path.join( os.path.dirname(startupproj), os.path.join(get_artifacts_directory(), 'startup'))) if not os.path.exists(relpath): startup.restore(get_packages_directory(), True, getruntimeidentifier()) startup.publish('Release', relpath, True, get_packages_directory(), None, getruntimeidentifier(), '--no-restore') self._setstartuppath(startup.bin_path)
def __init__(self): payload = helixpayload() if payload: self._setstartuppath(os.path.join(payload, 'Startup')) else: startupproj = os.path.join('..', '..', 'tools', 'ScenarioMeasurement', 'Startup', 'Startup.csproj') startup = CSharpProject( CSharpProjFile(startupproj, sys.path[0]), os.path.join( os.path.dirname(startupproj), os.path.join(get_artifacts_directory(), 'startup'))) startup.restore(get_packages_directory(), True) startup.build(configuration='Release', verbose=True, packages_path=get_packages_directory(), output_to_bindir=True) self._setstartuppath(startup.bin_path)
def build(BENCHMARKS_CSPROJ: dotnet.CSharpProject, configuration: str, target_framework_monikers: list, incremental: str, run_isolated: bool, verbose: bool) -> None: '''Restores and builds the benchmarks''' packages = get_packages_directory() if incremental == 'no': __log_script_header("Removing packages, bin and obj folders.") binary_folders = [ packages, path.join(BENCHMARKS_CSPROJ.bin_path), ] for binary_folder in binary_folders: remove_directory(path=binary_folder) # dotnet restore __log_script_header("Restoring .NET micro benchmarks") BENCHMARKS_CSPROJ.restore(packages_path=packages, verbose=verbose) # dotnet build build_title = "Building .NET micro benchmarks for '{}'".format( ' '.join(target_framework_monikers)) __log_script_header(build_title) BENCHMARKS_CSPROJ.build( configuration=configuration, target_framework_monikers=target_framework_monikers, output_to_bindir=run_isolated, verbose=verbose, packages_path=packages) # When running isolated, artifacts/obj/{project_name} will still be # there, and would interfere with any subsequent builds. So, remove # that if run_isolated: objDir = path.join(get_artifacts_directory(), 'obj', BENCHMARKS_CSPROJ.project_name) remove_directory(objDir)
def upload_results(container_path: str, artifacts_path: str, verbose: bool) -> None: getLogger().info("Starting upload process") if os.getenv('PERFLAB_UPLOAD_TOKEN') and os.getenv( "HELIX_WORKITEM_ID"): globpath = path.join( get_artifacts_directory() if not artifacts_path else artifacts_path, '**', '*perf-lab-report.json') getLogger().info("Searching in {0}".format(globpath)) # first find if we have any files at all files = glob(globpath, recursive=True) if files: getLogger().info("Found {0} files".format(len(files))) for file in files: getLogger().info("file: {0}".format(file)) # since we do, we will rename them to include the correlation ID rename_upload_files(files, os.getenv('HELIX_WORKITEM_ID')) renamed_files = glob(globpath, recursive=True) dirname = path.dirname(renamed_files[0]) if len(renamed_files) == 1: # need to work around a bug in azcopy which loses file name if # there is only one file. # https://github.com/Azure/azure-storage-azcopy/issues/410 container_path = path.join(container_path, path.basename(renamed_files[0])) AzCopy(os.environ['PERFLAB_UPLOAD_TOKEN'], container_path, verbose).upload_files( path.join(dirname, '*perf-lab-report.json')) else: getLogger().warning("Found zero files to upload") else: getLogger().warning( "Environment variables were unset, no uploading")
def get_packages_directory() -> str: ''' The path to directory where packages should get restored ''' return path.join(get_artifacts_directory(), 'packages')