예제 #1
0
def main(main_args):
    """Main entrypoint

    Args:
        main_args ([type]): Arguments to the script
    """

    coreclr_args = setup_args(main_args)

    antigen_directory = coreclr_args.antigen_directory
    core_root = coreclr_args.core_root
    tag_name = "{}-{}".format(coreclr_args.run_configuration,
                              coreclr_args.partition)
    output_directory = coreclr_args.output_directory
    run_duration = 120  # Run for 2 hours

    path_to_corerun = os.path.join(core_root, "corerun")
    path_to_tool = os.path.join(antigen_directory, "Antigen")
    if is_windows:
        path_to_corerun += ".exe"
        path_to_tool += ".exe"

    # Run tool such that issues are placed in a temp folder
    with TempDir() as temp_location:
        run_command([
            path_to_tool, "-c", path_to_corerun, "-o", temp_location, "-d",
            str(run_duration)
        ],
                    _exit_on_fail=True,
                    _long_running=True)

        # Copy issues for upload
        print("Copying issues to " + output_directory)
        copy_issues(temp_location, output_directory, tag_name)
예제 #2
0
def strip_unrelated_mc(coreclr_args, old_mch_filename, new_mch_filename):
    """Perform the post processing of produced .mch file by stripping the method contexts
    that are specific to BenchmarkDotnet boilerplate code and hard

    Args:
        coreclr_args (CoreclrArguments): Arguments
        old_mch_filename (string): Name of source .mch file
        new_mch_filename (string): Name of new .mch file to produce post-processing.
    """
    performance_directory = coreclr_args.performance_directory
    core_root = coreclr_args.core_root
    methods_to_strip_list = path.join(performance_directory,
                                      "methods_to_strip.mcl")

    mcs_exe = path.join(core_root, "mcs")
    mcs_command = [mcs_exe, "-dumpMap", old_mch_filename]

    # Gather method list to strip
    (mcs_out, _, return_code) = run_command(mcs_command)
    if return_code != 0:
        # If strip command fails, then just copy the old_mch to new_mch
        print(
            f"-dumpMap failed. Copying {old_mch_filename} to {new_mch_filename}."
        )
        copyfile(old_mch_filename, new_mch_filename)
        copyfile(old_mch_filename + ".mct", new_mch_filename + ".mct")
        return

    method_context_list = mcs_out.decode("utf-8").split(os.linesep)
    filtered_context_list = []

    match_pattern = re.compile('^(\\d+),(BenchmarkDotNet|Perfolizer)')
    print("Method indices to strip:")
    for mc_entry in method_context_list:
        matched = match_pattern.match(mc_entry)
        if matched:
            print(matched.group(1))
            filtered_context_list.append(matched.group(1))
    print(f"Total {len(filtered_context_list)} methods.")

    with open(methods_to_strip_list, "w") as f:
        f.write('\n'.join(filtered_context_list))

    # Strip and produce new .mcs file
    if run_command([
            mcs_exe, "-strip", methods_to_strip_list, old_mch_filename,
            new_mch_filename
    ])[2] != 0:
        # If strip command fails, then just copy the old_mch to new_mch
        print(
            f"-strip failed. Copying {old_mch_filename} to {new_mch_filename}."
        )
        copyfile(old_mch_filename, new_mch_filename)
        copyfile(old_mch_filename + ".mct", new_mch_filename + ".mct")
        return

    # Create toc file
    run_command([mcs_exe, "-toc", new_mch_filename])
예제 #3
0
def make_executable(file_name):
    """Make file executable by changing the permission

    Args:
        file_name (string): file to execute
    """
    if is_windows:
        return

    print("Inside make_executable")
    run_command(["ls", "-l", file_name])
    os.chmod(file_name,
             # read+execute for owner
             (stat.S_IRUSR | stat.S_IXUSR) |
             # read+execute for group
             (stat.S_IRGRP | stat.S_IXGRP) |
             # read+execute for other
             (stat.S_IROTH | stat.S_IXOTH))
    run_command(["ls", "-l", file_name])
예제 #4
0
def main(main_args):
    """Main entrypoint

    Args:
        main_args ([type]): Arguments to the script
    """

    coreclr_args = setup_args(main_args)
    arch_name = coreclr_args.arch
    os_name = "win" if coreclr_args.platform.lower() == "windows" else "linux"
    run_configuration = "{}-{}".format(os_name, arch_name)
    source_directory = coreclr_args.source_directory

    # CorrelationPayload directories
    correlation_payload_directory = path.join(coreclr_args.source_directory, "payload")
    scripts_src_directory = path.join(source_directory, "src", "coreclr", 'scripts')
    coreroot_dst_directory = path.join(correlation_payload_directory, "CoreRoot")
    antigen_dst_directory = path.join(correlation_payload_directory, "exploratory")

    helix_source_prefix = "official"
    creator = ""
    ci = True
    if is_windows:
        helix_queue = "Windows.10.Arm64" if arch_name == "arm64" else "Windows.10.Amd64.X86"
    else:
        if arch_name == "arm":
            helix_queue = "(Ubuntu.1804.Arm32)[email protected]/dotnet-buildtools/prereqs:ubuntu-18.04-helix-arm32v7-bfcd90a-20200121150440"
        elif arch_name == "arm64":
            helix_queue = "(Ubuntu.1804.Arm64)[email protected]/dotnet-buildtools/prereqs:ubuntu-18.04-helix-arm64v8-20210531091519-97d8652"
        else:
            helix_queue = "Ubuntu.1804.Amd64"

    # create exploratory directory
    print('Copying {} -> {}'.format(scripts_src_directory, coreroot_dst_directory))
    copy_directory(scripts_src_directory, coreroot_dst_directory, match_func=lambda path: any(path.endswith(extension) for extension in [".py"]))

    if is_windows:
        acceptable_copy = lambda path: any(path.endswith(extension) for extension in [".py", ".dll", ".exe", ".json"])
    else:
        # Need to accept files without any extension, which is how executable file's names look.
        acceptable_copy = lambda path: (os.path.basename(path).find(".") == -1) or any(path.endswith(extension) for extension in [".py", ".dll", ".so", ".json", ".a"])

    # copy CORE_ROOT
    print('Copying {} -> {}'.format(coreclr_args.core_root_directory, coreroot_dst_directory))
    copy_directory(coreclr_args.core_root_directory, coreroot_dst_directory, match_func=acceptable_copy)

    try:
        with TempDir() as tool_code_directory:
            # clone the tool
            run_command(
                ["git", "clone", "--quiet", "--depth", "1", "https://github.com/kunalspathak/Antigen.git", tool_code_directory])

            antigen_bin_directory = path.join(tool_code_directory, "bin", "Release", "net5.0")

            # build the tool
            with ChangeDir(tool_code_directory):
                dotnet_cmd = os.path.join(source_directory, "dotnet.cmd")
                if not is_windows:
                    dotnet_cmd = os.path.join(source_directory, "dotnet.sh")
                run_command([dotnet_cmd, "publish", "-c", "Release", "--self-contained", "-r", run_configuration, "-o", antigen_bin_directory], _exit_on_fail=True)

            if not os.path.exists(path.join(antigen_bin_directory, "Antigen.dll")):
                raise FileNotFoundError("Antigen.dll not present at {}".format(antigen_bin_directory))

            # copy antigen tool
            print('Copying {} -> {}'.format(antigen_bin_directory, antigen_dst_directory))
            copy_directory(antigen_bin_directory, antigen_dst_directory, match_func=acceptable_copy)
    except PermissionError as pe:
        print("Skipping file. Got error: %s", pe)

    # create foo.txt in work_item directories
    workitem_directory = path.join(source_directory, "workitem")
    os.mkdir(workitem_directory)
    foo_txt = os.path.join(workitem_directory, "foo.txt")
    with open(foo_txt, "w") as foo_txt_file:
        foo_txt_file.write("hello world!")

    # Set variables
    print('Setting pipeline variables:')
    set_pipeline_variable("CorrelationPayloadDirectory", correlation_payload_directory)
    set_pipeline_variable("WorkItemDirectory", workitem_directory)
    set_pipeline_variable("RunConfiguration", run_configuration)
    set_pipeline_variable("Creator", creator)
    set_pipeline_variable("Queue", helix_queue)
    set_pipeline_variable("HelixSourcePrefix", helix_source_prefix)
예제 #5
0
def main(main_args):
    """Main entrypoint

    Args:
        main_args ([type]): Arguments to the script
    """

    python_path = sys.executable
    cwd = os.path.dirname(os.path.realpath(__file__))
    coreclr_args = setup_args(main_args)
    spmi_location = path.join(cwd, "artifacts", "spmi")
    log_directory = coreclr_args.log_directory
    platform_name = coreclr_args.platform
    os_name = "win" if platform_name.lower() == "windows" else "unix"
    arch_name = coreclr_args.arch
    host_arch_name = "x64" if arch_name.endswith("64") else "x86"
    jit_path = path.join(
        coreclr_args.jit_directory,
        'clrjit_{}_{}_{}.dll'.format(os_name, arch_name, host_arch_name))

    print("Running superpmi.py download")
    run_command([
        python_path,
        path.join(cwd, "superpmi.py"), "download", "--no_progress",
        "-target_os", platform_name, "-target_arch", arch_name, "-core_root",
        cwd, "-spmi_location", spmi_location
    ],
                _exit_on_fail=True)

    failed_runs = []
    for jit_flag in jit_flags:
        log_file = path.join(
            log_directory, 'superpmi_{}.log'.format(jit_flag.replace("=",
                                                                     "_")))
        print("Running superpmi.py replay for {}".format(jit_flag))

        _, _, return_code = run_command([
            python_path,
            path.join(cwd, "superpmi.py"), "replay", "-core_root", cwd,
            "-jitoption", jit_flag, "-jitoption", "TieredCompilation=0",
            "-target_os", platform_name, "-target_arch", arch_name, "-arch",
            host_arch_name, "-jit_path", jit_path, "-spmi_location",
            spmi_location, "-log_level", "debug", "-log_file", log_file
        ])

        if return_code != 0:
            failed_runs.append("Failure in {}".format(log_file))

    # Consolidate all superpmi_*.logs in superpmi_platform_architecture.log
    final_log_name = path.join(
        log_directory, "superpmi_{}_{}.log".format(platform_name, arch_name))
    print("Consolidating final {}".format(final_log_name))
    with open(final_log_name, "a") as final_superpmi_log:
        for superpmi_log in listdir(log_directory):
            if not superpmi_log.startswith(
                    "superpmi_Jit") or not superpmi_log.endswith(".log"):
                continue

            print("Appending {}".format(superpmi_log))
            final_superpmi_log.write(
                "======================================================={}".
                format(os.linesep))
            final_superpmi_log.write("Contents from {}{}".format(
                superpmi_log, os.linesep))
            final_superpmi_log.write(
                "======================================================={}".
                format(os.linesep))
            with open(path.join(log_directory, superpmi_log),
                      "r") as current_superpmi_log:
                contents = current_superpmi_log.read()
                final_superpmi_log.write(contents)

        # Log failures summary
        if len(failed_runs) > 0:
            final_superpmi_log.write(os.linesep)
            final_superpmi_log.write(os.linesep)
            final_superpmi_log.write(
                "========Failed runs summary========".format(os.linesep))
            final_superpmi_log.write(os.linesep.join(failed_runs))

    return 0 if len(failed_runs) == 0 else 1
예제 #6
0
def build_and_run(coreclr_args, output_mch_name):
    """Build the microbenchmarks and run them under "superpmi collect"

    Args:
        coreclr_args (CoreClrArguments): Arguments use to drive
        output_mch_name (string): Name of output mch file name
    """
    arch = coreclr_args.arch
    python_path = sys.executable
    core_root = coreclr_args.core_root
    superpmi_directory = coreclr_args.superpmi_directory
    performance_directory = coreclr_args.performance_directory
    log_file = coreclr_args.log_file
    partition_count = coreclr_args.partition_count
    partition_index = coreclr_args.partition_index
    dotnet_directory = os.path.join(performance_directory, "tools", "dotnet",
                                    arch)
    dotnet_exe = os.path.join(dotnet_directory, "dotnet")

    artifacts_directory = os.path.join(performance_directory, "artifacts")
    artifacts_packages_directory = os.path.join(artifacts_directory,
                                                "packages")
    project_file = path.join(performance_directory, "src", "benchmarks",
                             "micro", "MicroBenchmarks.csproj")
    benchmarks_dll = path.join(artifacts_directory, "MicroBenchmarks.dll")

    if is_windows:
        shim_name = "%JitName%"
        corerun_exe = "CoreRun.exe"
        script_name = "run_microbenchmarks.bat"
    else:
        shim_name = "$JitName"
        corerun_exe = "corerun"
        script_name = "run_microbenchmarks.sh"

    make_executable(dotnet_exe)

    run_command([
        dotnet_exe, "restore", project_file, "--packages",
        artifacts_packages_directory
    ],
                _exit_on_fail=True)

    run_command([
        dotnet_exe, "build", project_file, "--configuration", "Release",
        "--framework", "net6.0", "--no-restore", "/p:NuGetPackageRoot=" +
        artifacts_packages_directory, "-o", artifacts_directory
    ],
                _exit_on_fail=True)

    # Disable ReadyToRun so we always JIT R2R methods and collect them
    collection_command = f"{dotnet_exe} {benchmarks_dll}  --filter \"*\" --corerun {path.join(core_root, corerun_exe)} --partition-count {partition_count} " \
                         f"--partition-index {partition_index} --envVars COMPlus_JitName:{shim_name} " \
                         " COMPlus_ZapDisable:1  COMPlus_ReadyToRun:0 " \
                         "--iterationCount 1 --warmupCount 0 --invocationCount 1 --unrollFactor 1 --strategy ColdStart"

    # Generate the execution script in Temp location
    with TempDir() as temp_location:
        script_name = path.join(temp_location, script_name)

        contents = []
        # Unset the JitName so dotnet process will not fail
        if is_windows:
            contents.append("set JitName=%COMPlus_JitName%")
            contents.append("set COMPlus_JitName=")
        else:
            contents.append("#!/bin/bash")
            contents.append("export JitName=$COMPlus_JitName")
            contents.append("unset COMPlus_JitName")
        contents.append(f"pushd {performance_directory}")
        contents.append(collection_command)

        with open(script_name, "w") as collection_script:
            collection_script.write(os.linesep.join(contents))

        print()
        print(f"{script_name} contents:")
        print("******************************************")
        print(os.linesep.join(contents))
        print("******************************************")

        make_executable(script_name)

        run_command([
            python_path,
            path.join(superpmi_directory, "superpmi.py"), "collect",
            "-core_root", core_root, "-output_mch_path", output_mch_name,
            "-log_file", log_file, "-log_level", "debug", script_name
        ],
                    _exit_on_fail=True)