Repository: dotnet/runtime
File: src/coreclr/scripts/superpmi_benchmarks.py (Python)

Code before:
    run_command([python_path, 
                dotnet_script,
                "install",
                "--architecture",
                    arch,
                "--channels",
                "main",
                "--verbose"])

def build_and_run(coreclr_args, output_mch_name):
    """Build the microbenchmarks/real-world 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
    benchmark_path = coreclr_args.benchmark_path
    benchmark_binary = coreclr_args.benchmark_binary
    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 = os.path.join(performance_directory, benchmark_path)
    benchmarks_dll = os.path.join(artifacts_directory, benchmark_binary)

    # Workaround https://github.com/dotnet/sdk/issues/23430
    project_file = os.path.realpath(project_file)

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

    # Install the dotnet sdk using the script within the performance repo
    install_dotnet_sdk(python_path, performance_directory, arch)

    # Start with a "dotnet --info" to see what we've got.
    run_command([dotnet_exe, "--info"])

Review comment (performance):
Please add the following lines
```py
    os.environ["NUGET_PLUGINS_CACHE_PATH"] = os.path.join(performance_directory, "NUGET_PLUGINS_CACHE_PATH")
    os.environ["NUGET_PACKAGES"] = os.path.join(performance_directory, "NUGET_PACKAGES")
    os.environ["NUGET_HTTP_CACHE_PATH"] = os.path.join(performance_directory, "NUGET_HTTP_CACHE_PATH")
    os.environ["NUGET_SCRATCH"] = os.path.join(performance_directory, "NUGET_SCRATCH")
```
to tell .NET we're about to install that we want it to keep all cached artifacts/nugets on the disk, not in $HOME (OS disk) 

Code after:
    performance_directory = coreclr_args.performance_directory
    log_file = coreclr_args.log_file
    partition_count = coreclr_args.partition_count
    partition_index = coreclr_args.partition_index
    benchmark_path = coreclr_args.benchmark_path
    benchmark_binary = coreclr_args.benchmark_binary
    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 = os.path.join(performance_directory, benchmark_path)
    benchmarks_dll = os.path.join(artifacts_directory, benchmark_binary)

    # Workaround https://github.com/dotnet/sdk/issues/23430
    project_file = os.path.realpath(project_file)

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

    # Set up NuGet cache locations to be within the performance_directory which is on a separate disk
    # so that we don't fill up the OS disk (space is limited on helix machines)
    os.environ["NUGET_PLUGINS_CACHE_PATH"] = os.path.join(performance_directory, "NUGET_PLUGINS_CACHE_PATH")
    os.environ["NUGET_PACKAGES"] = os.path.join(performance_directory, "NUGET_PACKAGES")
    os.environ["NUGET_HTTP_CACHE_PATH"] = os.path.join(performance_directory, "NUGET_HTTP_CACHE_PATH")
    os.environ["NUGET_SCRATCH"] = os.path.join(performance_directory, "NUGET_SCRATCH")

    # Install the dotnet sdk using the script within the performance repo
    dotnet_script = os.path.join(performance_directory, "scripts", "dotnet.py")
    run_command([python_path,
                dotnet_script,
                "install",
                "--architecture",
                    arch,
                "--channels",
                "main",
                "--verbose"])

    # Start with a "dotnet --info" to see what we've got.
    run_command([dotnet_exe, "--info"])

    tfm = "net11.0"
    os.environ["PERFLAB_TARGET_FRAMEWORKS"] = tfm

    env_for_restore = os.environ.copy()