def __main(args: list) -> int:
    infra_base_path = _get_gcinfra_path()
    with push_dir(infra_base_path):
        gcperfsim_path = os.path.join(infra_base_path, "src", "exec", "GCPerfSim")
        gcperf_path = os.path.join(infra_base_path, "src", "analysis", "managed-lib")
        ctools_path = os.path.join(infra_base_path, "src", "exec", "env")

        with push_dir(gcperfsim_path):
            cmdline = ['dotnet', 'build', '-c', 'release']
            RunCommand(cmdline, verbose=True).run()

        with push_dir(gcperf_path):
            cmdline = ['dotnet', 'publish']
            RunCommand(cmdline, verbose=True).run()

        with push_dir(ctools_path):
            cmdline = ['build.cmd']
            RunCommand(cmdline, verbose=True).run()
    return 0
Example #2
0
def get_build_directory(bin_directory: str, configuration: str,
                        target_framework_moniker: str) -> None:
    '''
    Gets the  output directory where the built artifacts are in with
    respect to the specified bin_directory.
    '''
    with push_dir(bin_directory):
        return path.join(
            bin_directory,
            __find_build_directory(
                configuration=configuration,
                target_framework_moniker=target_framework_moniker,
            ))
Example #3
0
def run_scripts(args: list, verbose: bool,
                BENCHMARKS_CSPROJ: dotnet.CSharpProject) -> None:
    '''Run BenchView scripts to collect performance data.'''
    if not args.generate_benchview_data:
        return

    __log_script_header('Running BenchView scripts')

    for framework in args.frameworks:
        working_directory = __get_working_directory(BENCHMARKS_CSPROJ,
                                                    args.configuration,
                                                    framework)

        with push_dir(working_directory):
            benchviewpy = BenchView(verbose)
            __run_scripts(args, benchviewpy, framework)
Example #4
0
    def measurement(self, working_directory: str) -> None:
        '''Wrapper around BenchView's measurement.py'''

        common_cmdline = [
            self.python,
            path.join(self.tools_directory, 'measurement.py'),
            'bdn',
            '--append',
        ]

        with push_dir(working_directory):
            pattern = "BenchmarkDotNet.Artifacts/**/*-full.json"
            getLogger().info('Searching BenchmarkDotNet output files with: %s',
                             pattern)

            for full_json_file in iglob(pattern, recursive=True):
                cmdline = common_cmdline + [full_json_file]
                RunCommand(cmdline,
                           verbose=self.verbose).run(working_directory)
Example #5
0
def __main(args: list) -> int:
    validate_supported_runtime()
    args = __process_arguments(args)
    verbose = not args.quiet
    setup_loggers(verbose=verbose)

    # if repository is not set, then we are doing a core-sdk in performance repo run
    # if repository is set, user needs to supply the commit_sha
    if not ((args.commit_sha is None) == (args.repository is None)):
        raise ValueError(
            'Either both commit_sha and repository should be set or neither')

    target_framework_monikers = micro_benchmarks \
        .FrameworkAction \
        .get_target_framework_monikers(args.frameworks)

    # Acquire necessary tools (dotnet, and BenchView)
    # For arm64 runs, download the x64 version so we can get the information we need, but set all variables
    # as if we were running normally. This is a workaround due to the fact that arm64 binaries cannot run
    # in the cross containers, so we are running the ci setup script in a normal ubuntu container
    architecture = 'x64' if args.architecture == 'arm64' else args.architecture

    init_tools(architecture=architecture,
               dotnet_versions=args.dotnet_versions,
               target_framework_monikers=target_framework_monikers,
               verbose=verbose)

    # dotnet --info
    dotnet.info(verbose=verbose)

    # When running on internal repos, the repository comes to us incorrectly
    # (ie https://github.com/dotnet-coreclr). Replace dashes with slashes in that case.
    repo_url = None if args.repository is None else args.repository.replace(
        '-', '/')

    variable_format = 'set %s=%s\n' if sys.platform == 'win32' else 'export %s=%s\n'
    owner, repo = ('dotnet', 'core-sdk') if args.repository is None else (
        dotnet.get_repository(repo_url))
    config_string = ';'.join(
        args.build_configs) if sys.platform == 'win32' else '"%s"' % ';'.join(
            args.build_configs)

    remove_dotnet = False

    output = ''

    with push_dir(get_repo_root_path()):
        output = check_output(['git', 'rev-parse', 'HEAD'])

    decoded_lines = []

    for line in output.splitlines():
        decoded_lines = decoded_lines + [line.decode('utf-8')]

    decoded_output = ''.join(decoded_lines)

    perfHash = decoded_output if args.get_perf_hash else args.perf_hash

    remove_frameworks = ['netcoreapp3.0', 'netcoreapp5.0']

    for framework in target_framework_monikers:
        if framework.startswith('netcoreapp'):
            if framework in remove_frameworks:
                remove_dotnet = True
            target_framework_moniker = micro_benchmarks.FrameworkAction.get_target_framework_moniker(
                framework)
            dotnet_version = dotnet.get_dotnet_version(
                target_framework_moniker, args.cli)
            commit_sha = dotnet.get_dotnet_sdk(
                target_framework_moniker,
                args.cli) if args.commit_sha is None else args.commit_sha
            source_timestamp = dotnet.get_commit_date(target_framework_moniker,
                                                      commit_sha, repo_url)

            branch = micro_benchmarks.FrameworkAction.get_branch(
                target_framework_moniker) if not args.branch else args.branch

            getLogger().info("Writing script to %s" % args.output_file)

            with open(args.output_file, 'w') as out_file:
                out_file.write(variable_format % ('PERFLAB_INLAB', '1'))
                out_file.write(variable_format %
                               ('PERFLAB_REPO', '/'.join([owner, repo])))
                out_file.write(variable_format % ('PERFLAB_BRANCH', branch))
                out_file.write(variable_format %
                               ('PERFLAB_PERFHASH', perfHash))
                out_file.write(variable_format % ('PERFLAB_HASH', commit_sha))
                out_file.write(variable_format % ('PERFLAB_QUEUE', args.queue))
                out_file.write(variable_format %
                               ('PERFLAB_BUILDNUM', args.build_number))
                out_file.write(variable_format %
                               ('PERFLAB_BUILDARCH', args.architecture))
                out_file.write(variable_format %
                               ('PERFLAB_LOCALE', args.locale))
                out_file.write(variable_format %
                               ('PERFLAB_BUILDTIMESTAMP', source_timestamp))
                out_file.write(variable_format %
                               ('PERFLAB_CONFIGS', config_string))
                out_file.write(variable_format %
                               ('DOTNET_VERSION', dotnet_version))
                out_file.write(variable_format %
                               ('PERFLAB_TARGET_FRAMEWORKS', framework))

        else:
            with open(args.output_file, 'w') as out_file:
                out_file.write(variable_format % ('PERFLAB_INLAB', '0'))
                out_file.write(variable_format %
                               ('PERFLAB_TARGET_FRAMEWORKS', framework))

    # On non-windows platforms, delete dotnet, so that we don't have to deal with chmoding it on the helix machines
    # This is only necessary for netcoreapp3.0 and netcoreapp5.0
    if sys.platform != 'win32' and remove_dotnet:
        dotnet.remove_dotnet(architecture)
Example #6
0
def __main(args: list) -> int:
    validate_supported_runtime()
    args = __process_arguments(args)
    verbose = not args.quiet
    setup_loggers(verbose=verbose)

    # if repository is not set, then we are doing a core-sdk in performance repo run
    # if repository is set, user needs to supply the commit_sha
    if not ((args.commit_sha is None) == (args.repository is None)):
        raise ValueError(
            'Either both commit_sha and repository should be set or neither')

    # Acquire necessary tools (dotnet)
    # For arm64 runs, download the x64 version so we can get the information we need, but set all variables
    # as if we were running normally. This is a workaround due to the fact that arm64 binaries cannot run
    # in the cross containers, so we are running the ci setup script in a normal ubuntu container
    architecture = 'x64' if args.architecture == 'arm64' else args.architecture

    init_tools(architecture=architecture,
               dotnet_versions=args.dotnet_versions,
               channel=args.channel,
               verbose=verbose,
               install_dir=args.install_dir)

    # dotnet --info
    dotnet.info(verbose=verbose)

    # When running on internal repos, the repository comes to us incorrectly
    # (ie https://github.com/dotnet-coreclr). Replace dashes with slashes in that case.
    repo_url = None if args.repository is None else args.repository.replace(
        '-', '/')

    variable_format = 'set %s=%s\n' if sys.platform == 'win32' else 'export %s=%s\n'
    path_variable = 'set PATH=%%PATH%%;%s\n' if sys.platform == 'win32' else 'export PATH=$PATH:%s\n'
    dotnet_path = '%HELIX_CORRELATION_PAYLOAD%\dotnet' if sys.platform == 'win32' else '$HELIX_CORRELATION_PAYLOAD/dotnet'
    owner, repo = ('dotnet', 'core-sdk') if args.repository is None else (
        dotnet.get_repository(repo_url))
    config_string = ';'.join(
        args.build_configs) if sys.platform == 'win32' else '"%s"' % ';'.join(
            args.build_configs)

    output = ''

    with push_dir(get_repo_root_path()):
        output = check_output(['git', 'rev-parse', 'HEAD'])

    decoded_lines = []

    for line in output.splitlines():
        decoded_lines = decoded_lines + [line.decode('utf-8')]

    decoded_output = ''.join(decoded_lines)

    perfHash = decoded_output if args.get_perf_hash else args.perf_hash

    framework = ChannelMap.get_target_framework_moniker(args.channel)
    if framework.startswith('netcoreapp'):
        target_framework_moniker = dotnet.FrameworkAction.get_target_framework_moniker(
            framework)
        dotnet_version = dotnet.get_dotnet_version(target_framework_moniker,
                                                   args.cli)
        commit_sha = dotnet.get_dotnet_sdk(
            target_framework_moniker,
            args.cli) if args.commit_sha is None else args.commit_sha
        source_timestamp = dotnet.get_commit_date(target_framework_moniker,
                                                  commit_sha, repo_url)

        branch = ChannelMap.get_branch(
            args.channel) if not args.branch else args.branch

        getLogger().info("Writing script to %s" % args.output_file)

        with open(args.output_file, 'w') as out_file:
            out_file.write(variable_format % ('PERFLAB_INLAB', '1'))
            out_file.write(variable_format %
                           ('PERFLAB_REPO', '/'.join([owner, repo])))
            out_file.write(variable_format % ('PERFLAB_BRANCH', branch))
            out_file.write(variable_format % ('PERFLAB_PERFHASH', perfHash))
            out_file.write(variable_format % ('PERFLAB_HASH', commit_sha))
            out_file.write(variable_format % ('PERFLAB_QUEUE', args.queue))
            out_file.write(variable_format %
                           ('PERFLAB_BUILDNUM', args.build_number))
            out_file.write(variable_format %
                           ('PERFLAB_BUILDARCH', args.architecture))
            out_file.write(variable_format % ('PERFLAB_LOCALE', args.locale))
            out_file.write(variable_format %
                           ('PERFLAB_BUILDTIMESTAMP', source_timestamp))
            out_file.write(variable_format %
                           ('PERFLAB_CONFIGS', config_string))
            out_file.write(variable_format %
                           ('DOTNET_VERSION', dotnet_version))
            out_file.write(variable_format %
                           ('PERFLAB_TARGET_FRAMEWORKS', framework))
            out_file.write(variable_format %
                           ('DOTNET_CLI_TELEMETRY_OPTOUT', '1'))
            out_file.write(variable_format % ('DOTNET_MULTILEVEL_LOOKUP', '0'))
            out_file.write(variable_format % ('UseSharedCompilation', 'false'))
            out_file.write(variable_format % ('DOTNET_ROOT', dotnet_path))
            out_file.write(path_variable % dotnet_path)

    else:
        with open(args.output_file, 'w') as out_file:
            out_file.write(variable_format % ('PERFLAB_INLAB', '0'))
            out_file.write(variable_format %
                           ('PERFLAB_TARGET_FRAMEWORKS', framework))
            out_file.write(path_variable % dotnet_path)

    # The '_Framework' is needed for specifying frameworks in proj files and for building tools later in the pipeline
    __write_pipeline_variable('_Framework', framework)
Example #7
0
def __run_benchview_scripts(
        args: list,
        verbose: bool,
        BENCHMARKS_CSPROJ: dotnet.CSharpProject
) -> None:
    '''Run BenchView scripts to collect performance data.'''
    if not args.generate_benchview_data:
        return

    # TODO: Delete previously generated BenchView data (*.json)

    benchviewpy = benchview.BenchView(verbose)
    bin_directory = BENCHMARKS_CSPROJ.bin_path

    # BenchView submission-metadata.py
    # TODO: Simplify logic. This should be removed and unify repo data.
    submission_name = args.benchview_submission_name
    is_pr = args.benchview_run_type == 'private' and \
        'BenchviewCommitName' in os.environ
    rolling_data = args.benchview_run_type == 'rolling' and \
        'GIT_BRANCH_WITHOUT_ORIGIN' in os.environ and \
        'GIT_COMMIT' in os.environ
    if is_pr:
        submission_name = '%s %s %s' % (
            args.category,
            args.benchview_run_type,
            args.benchview_submission_name
        )
    elif rolling_data:
        submission_name += '%s %s %s %s' % (
            args.category,
            args.benchview_run_type,
            os.environ['GIT_BRANCH_WITHOUT_ORIGIN'],
            os.environ['GIT_COMMIT']
        )

    benchviewpy.submission_metadata(
        working_directory=bin_directory,
        name=submission_name)

    # BenchView machinedata.py
    benchviewpy.machinedata(
        working_directory=bin_directory,
        architecture=args.architecture)

    for framework in args.frameworks:
        target_framework_moniker = micro_benchmarks \
            .FrameworkAction \
            .get_target_framework_moniker(framework)
        buildinfo = __get_build_info(args, target_framework_moniker)

        # BenchView build.py
        benchviewpy.build(
            working_directory=bin_directory,
            build_type=args.benchview_run_type,
            subparser=buildinfo.subparser,
            branch=buildinfo.branch,
            commit=buildinfo.commit_sha,
            repository=buildinfo.repository,
            source_timestamp=buildinfo.source_timestamp
        )

        working_directory = dotnet.get_build_directory(
            bin_directory=bin_directory,
            configuration=args.configuration,
            target_framework_moniker=target_framework_moniker,
        )

        # BenchView measurement.py
        benchviewpy.measurement(working_directory=working_directory)

    # Build the BenchView configuration data
    benchview_config_name = args.benchview_config_name \
        if args.benchview_config_name else args.configuration
    benchview_config = list(chain(args.benchview_config)) \
        if args.benchview_config else []
    i = iter(benchview_config)
    benchview_config = dict(zip(i, i))

    # Configuration
    if 'Configuration' not in benchview_config:
        benchview_config['Configuration'] = args.configuration

    # Generate existing configs.
    # TODO: Unify configs across all repos?
    submission_architecture = args.architecture
    if args.category.casefold() == 'CoreClr'.casefold():
        benchview_config['JitName'] = 'ryujit'  # FIXME: Remove this.
        benchview_config['OS'] = __get_coreclr_os_name()
        benchview_config['OptLevel'] = args.optimization_level  # Optimization
        benchview_config['PGO'] = 'pgo'  # FIXME: Remove this? Enabled/Disabled
        benchview_config['Profile'] = 'On' if args.enable_pmc else 'Off'
    elif args.category.casefold() == 'CoreFx'.casefold():
        submission_architecture = 'AnyCPU'
        benchview_config['OS'] = __get_corefx_os_name()
        benchview_config['RunType'] = \
            'Diagnostic' if args.enable_pmc else 'Profile'

    # Find all measurement.json
    with push_dir(bin_directory):
        for framework in args.frameworks:
            target_framework_moniker = micro_benchmarks \
                .FrameworkAction \
                .get_target_framework_moniker(framework)
            glob_format = '**/%s/%s/measurement.json' % (
                args.configuration,
                target_framework_moniker
            )

            measurement_jsons = []
            for measurement_json in iglob(glob_format, recursive=True):
                measurement_jsons.append(measurement_json)

            jobGroup = '.NET Performance (%s)' % args.category \
                if args.category \
                else '.NET Performance'

            if len(args.frameworks) > 1:
                benchview_config['Framework'] = framework

            # BenchView submission.py
            benchviewpy.submission(
                working_directory=bin_directory,
                measurement_jsons=measurement_jsons,
                architecture=submission_architecture,
                config_name=benchview_config_name,
                configs=benchview_config,
                machinepool=args.benchview_machinepool,
                jobgroup=jobGroup,
                jobtype=args.benchview_run_type
            )

            # Upload to a BenchView container (upload.py).
            # TODO: submission.py does not have an --append option,
            #   instead upload each build/config separately.
            if args.upload_to_benchview_container:
                benchviewpy.upload(
                    working_directory=bin_directory,
                    container=args.upload_to_benchview_container)
Example #8
0
def __main(args: list) -> int:
    validate_supported_runtime()
    args = __process_arguments(args)
    verbose = not args.quiet
    setup_loggers(verbose=verbose)

    # if repository is not set, then we are doing a core-sdk in performance repo run
    # if repository is set, user needs to supply the commit_sha
    if not ((args.commit_sha is None) == (args.repository is None)):
        raise ValueError('Either both commit_sha and repository should be set or neither')

    target_framework_monikers = micro_benchmarks \
        .FrameworkAction \
        .get_target_framework_monikers(args.frameworks)
    # Acquire necessary tools (dotnet, and BenchView)
    init_tools(
        architecture=args.architecture,
        dotnet_versions=args.dotnet_versions,
        target_framework_monikers=target_framework_monikers,
        verbose=verbose
    )

    # dotnet --info
    dotnet.info(verbose=verbose)

    variable_format = 'set %s=%s\n' if sys.platform == 'win32' else 'export %s=%s\n'
    owner, repo = ('dotnet', 'core-sdk') if args.repository is None else (dotnet.get_repository(args.repository))
    config_string = ';'.join(args.build_configs) if sys.platform == 'win32' else '"%s"' % ';'.join(args.build_configs)

    is_netcoreapp_30 = False

    output = ''

    with push_dir(get_repo_root_path()):
        output = check_output(['git', 'rev-parse', 'HEAD'])

    decoded_lines = []

    for line in output.splitlines():
        decoded_lines = decoded_lines + [line.decode('utf-8')]

    decoded_output = ''.join(decoded_lines)

    perfHash = decoded_output if args.get_perf_hash else args.perf_hash

    for framework in target_framework_monikers:
        if framework.startswith('netcoreapp'):
            if framework == 'netcoreapp3.0':
                is_netcoreapp_30 = True
            target_framework_moniker = micro_benchmarks.FrameworkAction.get_target_framework_moniker(framework)
            dotnet_version = dotnet.get_dotnet_version(target_framework_moniker, args.cli)
            commit_sha =  dotnet.get_dotnet_sdk(target_framework_moniker, args.cli) if args.commit_sha is None else args.commit_sha
            source_timestamp = dotnet.get_commit_date(target_framework_moniker, commit_sha, args.repository)

            branch = micro_benchmarks.FrameworkAction.get_branch(target_framework_moniker) if not args.branch else args.branch

            getLogger().info("Writing script to %s" % args.output_file)

            with open(args.output_file, 'w') as out_file:
                out_file.write(variable_format % ('PERFLAB_INLAB', '1'))
                out_file.write(variable_format % ('PERFLAB_REPO', '/'.join([owner, repo])))
                out_file.write(variable_format % ('PERFLAB_BRANCH', branch))
                out_file.write(variable_format % ('PERFLAB_PERFHASH', perfHash))
                out_file.write(variable_format % ('PERFLAB_HASH', commit_sha))
                out_file.write(variable_format % ('PERFLAB_QUEUE', args.queue))
                out_file.write(variable_format % ('PERFLAB_BUILDNUM', args.build_number))
                out_file.write(variable_format % ('PERFLAB_BUILDARCH', args.architecture))
                out_file.write(variable_format % ('PERFLAB_LOCALE', args.locale))
                out_file.write(variable_format % ('PERFLAB_BUILDTIMESTAMP', source_timestamp))
                out_file.write(variable_format % ('PERFLAB_CONFIGS', config_string))
                out_file.write(variable_format % ('DOTNET_VERSION', dotnet_version))

        else:
            with open(args.output_file, 'w') as out_file:
                out_file.write(variable_format % ('PERFLAB_INLAB', '0'))

    # On non-windows platforms, delete dotnet, so that we don't have to deal with chmoding it on the helix machines
    # This is only necessary for netcoreapp3.0
    if sys.platform != 'win32' and is_netcoreapp_30:
        dotnet.remove_dotnet(args.architecture)