diff --git a/.github/scripts/frozen_bdn_control.py b/.github/scripts/frozen_bdn_control.py index a7244a3ba..3d16f8512 100644 --- a/.github/scripts/frozen_bdn_control.py +++ b/.github/scripts/frozen_bdn_control.py @@ -88,7 +88,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 replay with BenchmarkDotNet native anonymous-pipe parent (FrozenNativeHost.dll).") + help="Opt-in concurrent or scoped-dispatch 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 +101,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 != "concurrent" or args.trace_tool): - parser.error("Native parent supports concurrent replay without an external trace launcher") + 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.allocation_profiler and args.case != "concurrent": parser.error("Exact allocation callbacks support only the concurrent benchmark") owner, method, parameter, operations = CASES[args.case] @@ -141,6 +141,9 @@ def main(): str((args.output / f"{index}-{side}-native.log").resolve()), str((args.output / f"{index}-{side}-native.json").resolve())] for index, side in enumerate(launches, 1)] + if args.case != "concurrent": + for command in protocol["commands"]: + command.append(args.case) if args.trace_tool: protocol["profile_limits"] = ( "Separate instrumented native-engine four-launch bracket with gc-verbose allocation sampling. " @@ -234,6 +237,12 @@ 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") 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 2a4d36329..a5b579bb1 100644 --- a/.github/scripts/test_frozen_bdn_control.py +++ b/.github/scripts/test_frozen_bdn_control.py @@ -151,6 +151,47 @@ 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 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"): + 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;") + def test_native_parent_profiles_child_only_and_retains_invalid_report(self): real_run = subprocess.run for missing in (False, True): @@ -207,7 +248,9 @@ def execute(command, **kwargs): self.assertEqual([call[4] for call in protocol["commands"]], [call[4] for call in calls]) def test_native_parent_rejects_unsupported_combinations(self): - for extra in (["--case", "scoped-dispatch"], ["--trace-tool", "trace"]): + for extra in (["--case", "log-composed"], ["--case", "queue-composed"], + ["--case", "queue-native"], ["--trace-tool", "trace"], + ["--case", "scoped-dispatch", "--trace-tool", "trace"]): with self.subTest(extra=extra), patch("sys.argv", ["control", "inputs", "output", "--native-executor", "host", *extra]): with self.assertRaises(SystemExit): main() diff --git a/tools/FrozenNativeHost/Program.cs b/tools/FrozenNativeHost/Program.cs index 26fbbc5f7..f5e14d829 100644 --- a/tools/FrozenNativeHost/Program.cs +++ b/tools/FrozenNativeHost/Program.cs @@ -11,9 +11,9 @@ using BenchmarkDotNet.Toolchains.Parameters; using BenchmarkDotNet.Toolchains.Results; -if (args.Length != 5) +if (args.Length is not (5 or 6)) { - Console.Error.WriteLine("Usage: FrozenNativeHost "); + Console.Error.WriteLine("Usage: FrozenNativeHost [concurrent|scoped-dispatch]"); return 2; } @@ -24,13 +24,22 @@ // setup, attributes, BenchmarkRunner or a builder. The child owns the native job. var metadata = new FrozenMetadataContext(directory); var assembly = metadata.LoadFromAssemblyPath(Path.Combine(directory, "Relayer.Benchmarks.dll")); -var type = assembly.GetType("Relayer.Benchmarks.EndToEndBenchmarks", throwOnError: true)!; -var method = type.GetMethod("ConcurrentRoundTrip") ?? throw new MissingMethodException(type.FullName, "ConcurrentRoundTrip"); -var descriptor = new Descriptor(type, method, operationsPerInvoke: 8); +var selectedCase = args.Length == 6 ? args[5] : "concurrent"; +var (owner, methodName, operations) = selectedCase switch +{ + "concurrent" => ("EndToEndBenchmarks", "ConcurrentRoundTrip", 8), + "scoped-dispatch" => ("ConsumePipelineBenchmarks", "DirectScopedDispatch", 1), + _ => throw new ArgumentException("Unsupported original benchmark case.") +}; +var type = assembly.GetType("Relayer.Benchmarks." + owner, throwOnError: true)!; +var method = type.GetMethod(methodName) ?? throw new MissingMethodException(type.FullName, methodName); +// 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); using var benchmarkCase = BenchmarkCase.Create(descriptor, Job.Default.WithId("Default"), new ParameterInstances([]), ManualConfig.CreateEmpty().CreateImmutableConfig()); var benchmarkId = new BenchmarkId(identity, benchmarkCase); -var expected = $"--benchmarkName Relayer.Benchmarks.EndToEndBenchmarks.ConcurrentRoundTrip --job Default --benchmarkId {identity}"; +var expected = $"--benchmarkName Relayer.Benchmarks.{owner}.{methodName} --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, "", ""); @@ -48,7 +57,8 @@ result.Results, result.PrefixedLines, result.StandardOutput, parent = "BenchmarkDotNet DotNetCliExecutor (native anonymous pipes/Broker/priority)", parentAssembly = typeof(DotNetCliExecutor).Assembly.FullName, - benchmarkArguments = benchmarkId.ToArguments() + benchmarkArguments = benchmarkId.ToArguments(), + selectedCase, operationsPerInvoke = operations }, new JsonSerializerOptions { WriteIndented = true })); return result.ExitCode == 0 && result.IsSuccess && result.Errors.Count == 0 ? 0 : 1;