diff --git a/.github/scripts/frozen_bdn_control.py b/.github/scripts/frozen_bdn_control.py index 3d16f8512..3cda58d25 100644 --- a/.github/scripts/frozen_bdn_control.py +++ b/.github/scripts/frozen_bdn_control.py @@ -16,6 +16,7 @@ # Explicit original generated runner selectors; ConsumptionModel.Queue=0, Log=1. CASES = { "concurrent": ("EndToEndBenchmarks", "ConcurrentRoundTrip", None, 8), + "scope-only": ("ConsumePipelineBenchmarks", "ScopeOnly", "instance.ScopedHandler = true;", 1), "scoped-dispatch": ("ConsumePipelineBenchmarks", "DirectScopedDispatch", "instance.ScopedHandler = true;", 1), "log-composed": ("InMemoryTransportBenchmarks", "ComposedRoundTrip", "instance.Mode = (Relayer.Transports.ConsumptionModel)(1);", 1), "queue-composed": ("InMemoryTransportBenchmarks", "ComposedRoundTrip", "instance.Mode = (Relayer.Transports.ConsumptionModel)(0);", 1), @@ -88,7 +89,7 @@ def main(): parser.add_argument("--case", choices=tuple(CASES), default="concurrent", help="Select an original generated runner and parameter, preserving its native job.") parser.add_argument("--native-executor", type=Path, - help="Opt-in concurrent or scoped-dispatch replay with BenchmarkDotNet native anonymous-pipe parent (FrozenNativeHost.dll).") + help="Opt-in concurrent, scoped-dispatch or scoped ScopeOnly replay with BenchmarkDotNet native anonymous-pipe parent (FrozenNativeHost.dll).") parser.add_argument("--trace-tool", type=Path, help="Separate instrumented replay; retain whole-process raw allocation profiles.") parser.add_argument("--runtime-version", choices=("10.0.14", "10.0.15"), @@ -101,8 +102,8 @@ def main(): help="Separate exact CLR callback counts in the selected native boundary.") args = parser.parse_args() from frozen_scope_control import result as timing_result - if args.native_executor and (args.case not in ("concurrent", "scoped-dispatch") or args.trace_tool): - parser.error("Native parent supports concurrent or scoped-dispatch replay without an external trace launcher") + if args.native_executor and (args.case not in ("concurrent", "scoped-dispatch", "scope-only") or args.trace_tool): + parser.error("Native parent supports concurrent, scoped-dispatch or scoped ScopeOnly replay without an external trace launcher") if args.allocation_profiler and args.case != "concurrent": parser.error("Exact allocation callbacks support only the concurrent benchmark") owner, method, parameter, operations = CASES[args.case] @@ -237,12 +238,15 @@ def main(): # The native logger includes Broker signal lines (AfterAll), # which ExecuteResult intentionally omits from PrefixedLines. text = (args.output / f"{index}-{side}-native.log").read_text() - if args.case == "scoped-dispatch": - expected = f"--benchmarkName {benchmark} --job Default --benchmarkId {runners[side][1]}" - if (receipt.get("benchmarkArguments") != expected - or receipt.get("selectedCase") != args.case - or receipt.get("operationsPerInvoke") != operations): - raise ValueError("Native executor benchmark identity differs from selected original runner") + # Independently bind the parent's receipt to the selected original + # runner, including the parameterized ScopeOnly benchmark name. + name_argument = (f'"{benchmark}(ScopedHandler: True)"' + if args.case == "scope-only" else benchmark) + expected = f"--benchmarkName {name_argument} --job Default --benchmarkId {runners[side][1]}" + if (receipt.get("benchmarkArguments") != expected + or receipt.get("selectedCase") != args.case + or receipt.get("operationsPerInvoke") != operations): + raise ValueError("Native executor benchmark identity differs from selected original runner") outcome["nativeReceipt"] = f"{index}-{side}-native.json" if args.runtime_version: versions = re.findall(r"^// Runtime=\.NET ([0-9.]+) ", text, re.M) diff --git a/.github/scripts/test_frozen_bdn_control.py b/.github/scripts/test_frozen_bdn_control.py index a5b579bb1..96162ee65 100644 --- a/.github/scripts/test_frozen_bdn_control.py +++ b/.github/scripts/test_frozen_bdn_control.py @@ -56,6 +56,41 @@ def fixture(self, root, identity="10"): {"path": path.relative_to(root).as_posix()} for path in (source, image)]})) return source, image + def test_scoped_scope_runner_selection_and_native_parent(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + for side in ("baseline", "candidate"): + source, image = self.fixture(root / "performance-builds" / side) + source.write_text(source.read_text().replace("EndToEndBenchmarks", "ConsumePipelineBenchmarks") + .replace("ConcurrentRoundTrip()", "ScopeOnly()") + .replace("OperationsPerInvoke = 8", "OperationsPerInvoke = 1") + .replace("workloadDelegate =", "instance.ScopedHandler = true; workloadDelegate =")) + self.assertEqual(executable(root / "performance-builds" / side, "scope-only"), (image.resolve(), "10")) + output = root / "results" + calls = [] + + def execute(command, **kwargs): + calls.append(command) + self.assertEqual(command[-1], "scope-only") + Path(command[-2]).write_text(json.dumps({"FoundExecutable": True, "ExitCode": 0, + "IsSuccess": True, "Errors": [], + "benchmarkArguments": '--benchmarkName "Relayer.Benchmarks.ConsumePipelineBenchmarks.ScopeOnly(ScopedHandler: True)" --job Default --benchmarkId 10', + "selectedCase": "scope-only", "operationsPerInvoke": 1})) + Path(command[-3]).write_text(COMPLETE.replace("65536", "9")) + + with patch("sys.argv", ["control", str(root), str(output), "--case", "scope-only", + "--native-executor", str(root / "host.dll")]), \ + patch("frozen_bdn_control.verify", return_value="frozen"), \ + patch("frozen_bdn_control.subprocess.run", side_effect=execute): + main() + self.assertEqual(len(calls), 4) + outcomes = json.loads((output / "outcomes.json").read_text()) + self.assertTrue(all(row["operations"] == 9 for row in outcomes)) + self.assertTrue(all("bytesPerMessage" not in row for row in outcomes)) + protocol = json.loads((output / "protocol.json").read_text()) + self.assertEqual(protocol["operationsPerInvoke"], 1) + self.assertEqual(protocol["parameter"], "instance.ScopedHandler = true;") + def test_discovers_runner_from_inventoried_generated_source(self): with tempfile.TemporaryDirectory() as directory: root = Path(directory) @@ -120,7 +155,9 @@ def execute(command, **kwargs): receipt = {"FoundExecutable": True, "ExitCode": 0, "IsSuccess": True, "Errors": [], "Results": ["WorkloadResult 1: 65536 op, 1 ns, 1 ns/op"], "PrefixedLines": ["// GC: 0 0 0 45823680 65536", "// AfterAll"], - "StandardOutput": ["// Runtime=.NET 10.0.15 (test), ARM64"]} + "StandardOutput": ["// Runtime=.NET 10.0.15 (test), ARM64"], + "benchmarkArguments": "--benchmarkName Relayer.Benchmarks.EndToEndBenchmarks.ConcurrentRoundTrip --job Default --benchmarkId 10", + "selectedCase": "concurrent", "operationsPerInvoke": 8} if len(calls) == 2: if invalid == "exit": receipt["ExitCode"] = 1 if invalid == "errors": receipt["Errors"] = ["native error"] @@ -151,46 +188,53 @@ def execute(command, **kwargs): self.assertIn("anonymous pipes/Broker", protocol["host"]) self.assertIn("bundled protocol intervention", protocol["limits"]) - def test_scoped_native_parent_checks_identity_and_retains_all_outcomes(self): - for invalid in (None, "identity", "case", "operations"): - with self.subTest(invalid=invalid), tempfile.TemporaryDirectory() as directory: - root = Path(directory) - output = root / "results" - calls = [] + def test_native_parent_checks_every_case_identity_and_retains_all_outcomes(self): + for case, benchmark, operations in ( + ("concurrent", "Relayer.Benchmarks.EndToEndBenchmarks.ConcurrentRoundTrip", 8), + ("scoped-dispatch", "Relayer.Benchmarks.ConsumePipelineBenchmarks.DirectScopedDispatch", 1), + ("scope-only", '"Relayer.Benchmarks.ConsumePipelineBenchmarks.ScopeOnly(ScopedHandler: True)"', 1)): + for invalid in (None, "identity", "case", "operations"): + with self.subTest(case=case, invalid=invalid), tempfile.TemporaryDirectory() as directory: + root = Path(directory) + output = root / "results" + calls = [] - def execute(command, **kwargs): - calls.append(command) - self.assertEqual(command[-1], "scoped-dispatch") - self.assertEqual(command[3], "42") - receipt = {"FoundExecutable": True, "ExitCode": 0, "IsSuccess": True, "Errors": [], - "benchmarkArguments": "--benchmarkName Relayer.Benchmarks.ConsumePipelineBenchmarks.DirectScopedDispatch --job Default --benchmarkId 42", - "selectedCase": "scoped-dispatch", "operationsPerInvoke": 1} - if len(calls) == 2: - if invalid == "identity": receipt["benchmarkArguments"] = "wrong runner" - if invalid == "case": receipt["selectedCase"] = "concurrent" - if invalid == "operations": receipt["operationsPerInvoke"] = 8 - Path(command[-2]).write_text(json.dumps(receipt)) - # A one-operation benchmark need not be divisible by eight. - Path(command[-3]).write_text(COMPLETE.replace("65536", "9")) - - with patch("sys.argv", ["control", str(root), str(output), "--case", "scoped-dispatch", - "--native-executor", str(root / "host.dll")]), \ - patch("frozen_bdn_control.verify", return_value="frozen"), \ - patch("frozen_bdn_control.executable", return_value=(root / "image.dll", "42")), \ - patch("frozen_bdn_control.subprocess.run", side_effect=execute): - if invalid: - with self.assertRaisesRegex(SystemExit, "launches failed"): + def execute(command, **kwargs): + calls.append(command) + if case != "concurrent": + self.assertEqual(command[-1], case) + self.assertEqual(command[3], "42") + receipt = {"FoundExecutable": True, "ExitCode": 0, "IsSuccess": True, "Errors": [], + "benchmarkArguments": f"--benchmarkName {benchmark} --job Default --benchmarkId 42", + "selectedCase": case, "operationsPerInvoke": operations} + if len(calls) == 2: + if invalid == "identity": receipt["benchmarkArguments"] = "wrong runner" + if invalid == "case": receipt["selectedCase"] = "wrong case" + if invalid == "operations": receipt["operationsPerInvoke"] = 99 + Path(command[6]).write_text(json.dumps(receipt)) + # A one-operation benchmark need not be divisible by eight. + Path(command[5]).write_text(COMPLETE if case == "concurrent" else COMPLETE.replace("65536", "9")) + + with patch("sys.argv", ["control", str(root), str(output), "--case", case, + "--native-executor", str(root / "host.dll")]), \ + patch("frozen_bdn_control.verify", return_value="frozen"), \ + patch("frozen_bdn_control.executable", return_value=(root / "image.dll", "42")), \ + patch("frozen_bdn_control.subprocess.run", side_effect=execute): + if invalid: + with self.assertRaisesRegex(SystemExit, "launches failed"): + main() + else: main() - else: - main() - self.assertEqual(len(calls), 4) - outcomes = json.loads((output / "outcomes.json").read_text()) - self.assertEqual([item["side"] for item in outcomes], ["baseline", "candidate", "candidate", "baseline"]) - self.assertEqual("error" in outcomes[1], invalid is not None) - self.assertEqual(outcomes[3]["operations"], 9) - protocol = json.loads((output / "protocol.json").read_text()) - self.assertFalse(protocol["instrumented"]) - self.assertEqual(protocol["parameter"], "instance.ScopedHandler = true;") + self.assertEqual(len(calls), 4) + outcomes = json.loads((output / "outcomes.json").read_text()) + self.assertEqual([item["side"] for item in outcomes], ["baseline", "candidate", "candidate", "baseline"]) + self.assertEqual("error" in outcomes[1], invalid is not None) + if invalid: + self.assertIn("benchmark identity differs", outcomes[1]["error"]) + self.assertEqual(outcomes[3]["operations"], 65536 if case == "concurrent" else 9) + protocol = json.loads((output / "protocol.json").read_text()) + self.assertFalse(protocol["instrumented"]) + self.assertEqual(protocol["parameter"], None if case == "concurrent" else "instance.ScopedHandler = true;") def test_native_parent_profiles_child_only_and_retains_invalid_report(self): real_run = subprocess.run @@ -218,7 +262,9 @@ def execute(command, **kwargs): self.assertEqual(child, ["1", str((root / "profiler 'quoted.so").resolve()), str(report.resolve()), "MeasureWithGc", "--fx-version", "10.0.15", "--roll-forward", "Disable", "image with spaces.dll", "--anonymousPipes", "pipe handles"]) - Path(command[-1]).write_text(json.dumps({"FoundExecutable": True, "ExitCode": 0, "IsSuccess": True, "Errors": []})) + Path(command[-1]).write_text(json.dumps({"FoundExecutable": True, "ExitCode": 0, "IsSuccess": True, "Errors": [], + "benchmarkArguments": "--benchmarkName Relayer.Benchmarks.EndToEndBenchmarks.ConcurrentRoundTrip --job Default --benchmarkId 10", + "selectedCase": "concurrent", "operationsPerInvoke": 8})) Path(command[-2]).write_text("// Runtime=.NET 10.0.15 (test), X64\n" + COMPLETE) if missing and len(calls) == 2: return diff --git a/.github/workflows/frozen-bdn-control.yml b/.github/workflows/frozen-bdn-control.yml index 6991d04e7..ede8f34a5 100644 --- a/.github/workflows/frozen-bdn-control.yml +++ b/.github/workflows/frozen-bdn-control.yml @@ -24,6 +24,7 @@ on: type: choice options: - concurrent + - scope-only - scoped-dispatch - log-composed - queue-composed diff --git a/.github/workflows/frozen-scope-control.yml b/.github/workflows/frozen-scope-control.yml index ad0c24121..51ad2c61e 100644 --- a/.github/workflows/frozen-scope-control.yml +++ b/.github/workflows/frozen-scope-control.yml @@ -1,4 +1,4 @@ -name: Frozen scope native contention events +name: Frozen scope native parent control # New historical-input experiment, never a rerun of the performance gate. on: @@ -8,7 +8,9 @@ on: - '.github/scripts/test_frozen_scope_control.py' - '.github/scripts/frozen_concurrent_control.py' - '.github/workflows/frozen-scope-control.yml' - - 'tools/FrozenScopeSampleReader/**' + - 'tools/FrozenNativeHost/**' + - '.github/scripts/frozen_bdn_control.py' + - '.github/scripts/test_frozen_bdn_control.py' - 'tools/FrozenAllocationReader/RuntimeIdentityScope.cs' workflow_dispatch: @@ -24,9 +26,10 @@ jobs: - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 - uses: actions/setup-dotnet@0f4a354dd5547a28c70b7853dbd95d5b67886e73 # v6.1.0 with: - # The 11.0 SDK builds the net11.0 probes; benchmark images retained from earlier runs need the 10.0 runtime. + # SDK 10.0.404 supplies the exact 10.0.15 runtime pinned by the replay. + # The 11.0 SDK builds the net11.0 probes. dotnet-version: | - 10.0.403 + 10.0.404 11.0.100 - name: Record host and verify launcher run: | @@ -34,36 +37,26 @@ jobs: dotnet --info > results/runtime.txt uname -a > results/host.txt python3 -m unittest discover -s .github/scripts -p test_frozen_scope_control.py > results/launcher-tests.log 2>&1 - dotnet build tools/FrozenScopeSampleReader -c Release > results/reader-build.log 2>&1 + dotnet build tools/FrozenNativeHost -c Release > results/parent-build.log 2>&1 + python3 -m unittest discover -s .github/scripts -p test_frozen_bdn_control.py > results/native-launcher-tests.log 2>&1 - name: Download original images for code attribution env: GH_TOKEN: ${{ github.token }} run: | gh run download 42772012652 --name performance-42772012652-1 --dir inputs - # Sample labels concentrated in Monitor.Enter_Slowpath cannot establish - # contention. Test native contention events with the sampling profiler absent. - # Retain every launch/event; never compare instrumented timings. - - name: Capture native contention without the sampling profiler - run: python3 .github/scripts/frozen_scope_control.py inputs results/sampling --counterbalanced --eventpipe-contention - - name: Parse every retained trace even after launch failure - if: always() - run: | - failed=0 - shopt -s nullglob - traces=(results/sampling/*-samples.nettrace) - if (( ${#traces[@]} != 16 )); then - echo "Expected sixteen native sample captures" >&2 - failed=1 - fi - for trace in "${traces[@]}"; do - dotnet tools/FrozenScopeSampleReader/bin/Release/net11.0/FrozenScopeSampleReader.dll "$trace" --contention > "$trace.jsonl" 2> "$trace.reader.log" || failed=1 - done - exit "$failed" + # Prior console-parent captures cannot reproduce the historical parent protocol. + # One original-image native-parent ABBA tests this bundled intervention; + # retain every outcome, without attributing historical causality or pipe cost. + - name: Execute original scoped runner through native BDN parent + run: >- + python3 .github/scripts/frozen_bdn_control.py inputs results/native-scope + --case scope-only --runtime-version 10.0.15 + --native-executor tools/FrozenNativeHost/bin/Release/net10.0/FrozenNativeHost.dll - name: Retain all outcomes and executable inputs if: always() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 with: - name: frozen-scope-contention-${{ github.run_id }}-${{ github.run_attempt }} + name: frozen-scope-native-parent-${{ github.run_id }}-${{ github.run_attempt }} path: | .github/workflows/frozen-scope-control.yml results/ @@ -73,7 +66,8 @@ jobs: .github/scripts/test_frozen_bdn_control.py .github/scripts/frozen_bdn_control.py .github/scripts/frozen_concurrent_control.py - tools/FrozenScopeSampleReader/*.cs - tools/FrozenScopeSampleReader/*.csproj + tools/FrozenNativeHost/Program.cs + tools/FrozenNativeHost/FrozenNativeHost.csproj + tools/FrozenNativeHost/bin/Release/net10.0/ tools/FrozenAllocationReader/RuntimeIdentityScope.cs retention-days: 90 diff --git a/tools/FrozenNativeHost/Program.cs b/tools/FrozenNativeHost/Program.cs index f5e14d829..5afc14968 100644 --- a/tools/FrozenNativeHost/Program.cs +++ b/tools/FrozenNativeHost/Program.cs @@ -13,7 +13,7 @@ if (args.Length is not (5 or 6)) { - Console.Error.WriteLine("Usage: FrozenNativeHost [concurrent|scoped-dispatch]"); + Console.Error.WriteLine("Usage: FrozenNativeHost [concurrent|scoped-dispatch|scope-only]"); return 2; } @@ -28,6 +28,7 @@ var (owner, methodName, operations) = selectedCase switch { "concurrent" => ("EndToEndBenchmarks", "ConcurrentRoundTrip", 8), + "scope-only" => ("ConsumePipelineBenchmarks", "ScopeOnly", 1), "scoped-dispatch" => ("ConsumePipelineBenchmarks", "DirectScopedDispatch", 1), _ => throw new ArgumentException("Unsupported original benchmark case.") }; @@ -36,10 +37,16 @@ // The inventoried generated runner ID selects the parameter and original job. // The descriptor supplies only the method name required by the native executor. var descriptor = new Descriptor(type, method, operationsPerInvoke: operations); +ParameterInstance[] parameters = selectedCase == "scope-only" + ? [new(new ParameterDefinition("ScopedHandler", false, [true], false, typeof(bool), 0), true, BenchmarkDotNet.Reports.SummaryStyle.Default)] + : []; using var benchmarkCase = BenchmarkCase.Create(descriptor, Job.Default.WithId("Default"), - new ParameterInstances([]), ManualConfig.CreateEmpty().CreateImmutableConfig()); + new ParameterInstances(parameters), ManualConfig.CreateEmpty().CreateImmutableConfig()); var benchmarkId = new BenchmarkId(identity, benchmarkCase); -var expected = $"--benchmarkName Relayer.Benchmarks.{owner}.{methodName} --job Default --benchmarkId {identity}"; +var nameArgument = selectedCase == "scope-only" + ? "\"Relayer.Benchmarks.ConsumePipelineBenchmarks.ScopeOnly(ScopedHandler: True)\"" + : $"Relayer.Benchmarks.{owner}.{methodName}"; +var expected = $"--benchmarkName {nameArgument} --job Default --benchmarkId {identity}"; if (benchmarkId.ToArguments() != expected) throw new InvalidOperationException("Native parent identity differs from the verified original runner."); var paths = new ArtifactsPaths(directory, directory, directory, "", "", "", "", "", "", image, "", "");