diff --git a/.github/scripts/frozen_bdn_control.py b/.github/scripts/frozen_bdn_control.py index e07576093..2a06c31d7 100644 --- a/.github/scripts/frozen_bdn_control.py +++ b/.github/scripts/frozen_bdn_control.py @@ -7,14 +7,23 @@ import subprocess from frozen_concurrent_control import verify +from frozen_scope_control import result as timing_result BENCHMARK = "Relayer.Benchmarks.EndToEndBenchmarks.ConcurrentRoundTrip" LAUNCHES = ("baseline", "candidate", "candidate", "baseline") +# Explicit original generated runner selectors; ConsumptionModel.Queue=0, Log=1. +CASES = { + "concurrent": ("EndToEndBenchmarks", "ConcurrentRoundTrip", None, 8), + "scoped-dispatch": ("ConsumePipelineBenchmarks", "DirectScopedDispatch", "instance.ScopedHandler = true;", 1), + "log-composed": ("InMemoryTransportBenchmarks", "ComposedRoundTrip", "instance.Mode = (Relayer.Transports.ConsumptionModel)(1);", 1), + "queue-native": ("InMemoryTransportBenchmarks", "NativeRoundTrip", "instance.Mode = (Relayer.Transports.ConsumptionModel)(0);", 1), +} -def executable(root): - """Require the original generated runner and its eight-operation GC-stat job.""" +def executable(root, case="concurrent"): + """Require the selected original generated runner, parameter and GC-stat job.""" + owner, method, parameter, operations = CASES[case] root = Path(root).resolve() files = {entry["path"] for entry in json.loads((root / "inventory-sha256.json").read_text())["files"]} sources = list(root.glob("builds/*/Relayer.Benchmarks-DefaultJob-*/*.notcs")) @@ -22,14 +31,15 @@ def executable(root): raise ValueError("Expected one retained generated BenchmarkDotNet source") source = sources[0] text = source.read_text() - runners = re.findall(r"public unsafe class Runnable_(\d+) : global::Relayer\.Benchmarks\.EndToEndBenchmarks\s*\{(.*?)(?=public unsafe class Runnable_|\Z)", text, re.S) + runners = re.findall(rf"public unsafe class Runnable_(\d+) : global::Relayer\.Benchmarks\.{owner}\s*\{{(.*?)(?=public unsafe class Runnable_|\Z)", text, re.S) matches = [(identity, body) for identity, body in runners - if "AwaitHelper.GetResult(ConcurrentRoundTrip())" in body] + if f"AwaitHelper.GetResult({method}())" in body + and (parameter is None or parameter in body)] if len(matches) != 1: - raise ValueError("Expected one original ConcurrentRoundTrip runner") + raise ValueError(f"Expected one original {case} runner for selected parameter") identity, body = matches[0] - if "OperationsPerInvoke = 8," not in body or "MeasureExtraStats = true," not in body: - raise ValueError("Original runner must measure eight operations and GC statistics") + if f"OperationsPerInvoke = {operations}," not in body or "MeasureExtraStats = true," not in body: + raise ValueError(f"Original runner must measure {operations} operations and GC statistics") images = list(source.parent.glob("bin/Release/net10.0/Relayer.Benchmarks-DefaultJob-*.dll")) if len(images) != 1: raise ValueError("Expected one retained generated BenchmarkDotNet executable") @@ -73,6 +83,8 @@ def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("artifact", type=Path) parser.add_argument("output", type=Path) + parser.add_argument("--case", choices=tuple(CASES), default="concurrent", + help="Select an original generated runner and parameter, preserving its native job.") 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"), @@ -80,22 +92,25 @@ def main(): parser.add_argument("--same-image", choices=("baseline", "candidate"), help="Negative control: launch the selected original image four times, without an image comparison.") args = parser.parse_args() + owner, method, parameter, operations = CASES[args.case] + benchmark = f"Relayer.Benchmarks.{owner}.{method}" builds = args.artifact.resolve() / "performance-builds" # Verify all three original inventories before starting any process. A2 deliberately # repeats the first baseline executable, as in the external-probe ABBA. commits = {side: verify(builds / side) for side in (*dict.fromkeys(LAUNCHES), "baseline-after")} - runners = {side: executable(builds / side) for side in dict.fromkeys(LAUNCHES)} + runners = {side: executable(builds / side, args.case) for side in dict.fromkeys(LAUNCHES)} launches = (args.same_image,) * 4 if args.same_image else LAUNCHES args.output.mkdir(parents=True, exist_ok=False) - protocol = {"commits": commits, "launches": launches, "sameImage": args.same_image, "benchmark": BENCHMARK, + protocol = {"commits": commits, "launches": launches, "sameImage": args.same_image, "benchmark": benchmark, + "case": args.case, "parameter": parameter, "engine": "Original retained BenchmarkDotNet generated executable and Default job", "host": "Native NoAcknowledgementConsoleHost; original anonymous-pipe parent absent", - "operationsPerInvoke": 8, "instrumented": args.trace_tool is not None, + "operationsPerInvoke": operations, "instrumented": args.trace_tool is not None, "limits": "New original-engine executions, not historical reconstruction, allocation-type attribution, throughput equivalence or native-client budget evidence. No external fixed-count driver, sampled profile, job override or threshold change.", "requestedRuntime": args.runtime_version, "commands": []} for side in launches: image, identity = runners[side] - protocol["commands"].append([*runtime_command(image, args.runtime_version), "--benchmarkName", BENCHMARK, + protocol["commands"].append([*runtime_command(image, args.runtime_version), "--benchmarkName", benchmark, "--job", "Default", "--benchmarkId", identity]) if args.trace_tool: protocol["profile_limits"] = ( @@ -136,7 +151,11 @@ def main(): if versions != [args.runtime_version]: raise ValueError(f"Unexpected loaded runtime: {versions}") outcome["runtime"] = versions[0] - outcome.update(result(text)) + # Reuse the existing native WorkloadResult parser; these are new + # process samples, never a gate verdict or historical reconstruction. + outcome.update(timing_result(text)) + if args.case == "concurrent": + outcome.update(result(text)) except ValueError as error: outcome["error"] = str(error) failed = True diff --git a/.github/scripts/frozen_scope_control.py b/.github/scripts/frozen_scope_control.py index 76199d5b3..8f2258d1e 100644 --- a/.github/scripts/frozen_scope_control.py +++ b/.github/scripts/frozen_scope_control.py @@ -45,13 +45,14 @@ def executable(root, scoped, method="ScopeOnly"): def result(text): gc = re.findall(r"^// GC: +(\d+) +(\d+) +(\d+) +(\d+) +(\d+)\s*$", text, re.M) - samples = re.findall(r"^WorkloadResult +\d+: +\d+ op, +[0-9.]+ ns, +([0-9.]+) ns/op\s*$", text, re.M) + samples = re.findall(r"^WorkloadResult +\d+: +\d+ op, +[0-9.]+ ns, +([0-9.]+) (ns|us|µs|μs|ms|s)/op\s*$", text, re.M) if len(gc) != 1 or len(re.findall(r"^// GC:", text, re.M)) != 1 or not samples or len(re.findall(r"^// AfterAll\s*$", text, re.M)) != 1: raise ValueError("Incomplete or ambiguous native results") gen0, gen1, gen2, allocated, operations = map(int, gc[0]) if operations <= 0: raise ValueError("Expected positive native operation count") - values = list(map(float, samples)) + scales = {"ns": 1, "us": 1_000, "µs": 1_000, "μs": 1_000, "ms": 1_000_000, "s": 1_000_000_000} + values = [float(value) * scales[unit] for value, unit in samples] return {"collections": [gen0, gen1, gen2], "allocatedBytes": allocated, "operations": operations, "bytesPerOperation": allocated / operations, "workloadResultNs": values, "meanNs": statistics.mean(values)} diff --git a/.github/scripts/test_frozen_bdn_control.py b/.github/scripts/test_frozen_bdn_control.py index fde9050fc..f0efdde80 100644 --- a/.github/scripts/test_frozen_bdn_control.py +++ b/.github/scripts/test_frozen_bdn_control.py @@ -91,6 +91,61 @@ def execute(command, **kwargs): if profiled: self.assertEqual(len(list(output.glob("*.nettrace"))), 4) + def test_selects_throughput_cases_from_original_parameterized_runners(self): + cases = ( + ("scoped-dispatch", "ConsumePipelineBenchmarks", "DirectScopedDispatch", + "instance.ScopedHandler = true;", "instance.ScopedHandler = false;"), + ("log-composed", "InMemoryTransportBenchmarks", "ComposedRoundTrip", + "instance.Mode = (Relayer.Transports.ConsumptionModel)(1);", "instance.Mode = (Relayer.Transports.ConsumptionModel)(0);"), + ("queue-native", "InMemoryTransportBenchmarks", "NativeRoundTrip", + "instance.Mode = (Relayer.Transports.ConsumptionModel)(0);", "instance.Mode = (Relayer.Transports.ConsumptionModel)(1);"), + ) + for case, owner, method, parameter, opposite in cases: + with self.subTest(case=case), tempfile.TemporaryDirectory() as directory: + root = Path(directory) + source, image = self.fixture(root) + # Include the same method with the opposite parameter. Selecting only + # by method would execute a different benchmark than the failing case. + runner = lambda identity, assignment: f"""public unsafe class Runnable_{identity} : global::Relayer.Benchmarks.{owner} + {{ OperationsPerInvoke = 1, MeasureExtraStats = true, + {assignment} workloadDelegate = () => BenchmarkDotNet.Helpers.AwaitHelper.GetResult({method}()); }}""" + source.write_text(runner("31", opposite) + runner("32", parameter)) + self.assertEqual(executable(root, case), (image.resolve(), "32")) + source.write_text(runner("31", opposite)) + with self.assertRaisesRegex(ValueError, "selected parameter"): + executable(root, case) + source.write_text(runner("31", parameter) + runner("32", parameter)) + with self.assertRaisesRegex(ValueError, "selected parameter"): + executable(root, case) + + def test_one_operation_case_retains_native_timings_without_message_denominator(self): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + output = root / "results" + image = root / "original.dll" + log = "WorkloadResult 1: 3 op, 9 ns, 3 ns/op\nWorkloadResult 2: 3 op, 15 ns, 5 ns/op\n// GC: 0 0 0 72 3\n// AfterAll\n" + calls = [] + + def execute(command, **kwargs): + calls.append(command) + kwargs["stdout"].write(log) + + with patch("sys.argv", ["control", str(root), str(output), "--case", "scoped-dispatch"]), \ + patch("frozen_bdn_control.verify", return_value="frozen"), \ + patch("frozen_bdn_control.executable", return_value=(image, "6")), \ + patch("frozen_bdn_control.subprocess.run", side_effect=execute): + main() + self.assertEqual(len(calls), 4) + self.assertTrue(all(command[command.index("--benchmarkName") + 1] == + "Relayer.Benchmarks.ConsumePipelineBenchmarks.DirectScopedDispatch" for command in calls)) + outcomes = json.loads((output / "outcomes.json").read_text()) + self.assertTrue(all(item["bytesPerOperation"] == 24 and item["meanNs"] == 4 for item in outcomes)) + self.assertTrue(all(item["workloadResultNs"] == [3, 5] for item in outcomes)) + self.assertTrue(all("bytesPerMessage" not in item for item in outcomes)) + protocol = json.loads((output / "protocol.json").read_text()) + self.assertEqual(protocol["operationsPerInvoke"], 1) + self.assertEqual(protocol["parameter"], "instance.ScopedHandler = true;") + def test_rejects_uninventoried_or_wrong_job_input(self): for invalid in ("inventory", "operations", "stats", "runner"): with self.subTest(invalid=invalid), tempfile.TemporaryDirectory() as directory: diff --git a/.github/scripts/test_frozen_scope_control.py b/.github/scripts/test_frozen_scope_control.py index e91650f8e..195822d56 100644 --- a/.github/scripts/test_frozen_scope_control.py +++ b/.github/scripts/test_frozen_scope_control.py @@ -21,6 +21,15 @@ def test_native_results_keep_timing_and_single_operation_allocations(self): with self.subTest(invalid=invalid), self.assertRaises(ValueError): result(invalid) + def test_native_timing_units_are_normalized_to_nanoseconds(self): + for unit, scale in (("ns", 1), ("us", 1_000), ("µs", 1_000), + ("μs", 1_000), ("ms", 1_000_000), ("s", 1_000_000_000)): + with self.subTest(unit=unit): + actual = result(COMPLETE.replace("27 ns/op", f"4.7363 {unit}/op")) + self.assertEqual(actual["workloadResultNs"], [4.7363 * scale]) + self.assertEqual(actual["meanNs"], 4.7363 * scale) + self.assertEqual(actual["bytesPerOperation"], 128) + def test_selects_parameter_and_rejects_wrong_job_and_missing_inventory(self): with tempfile.TemporaryDirectory() as directory: root = Path(directory) diff --git a/.github/workflows/frozen-537-core-crossover.yml b/.github/workflows/frozen-537-core-crossover.yml index 984078b05..bae8abfd2 100644 --- a/.github/workflows/frozen-537-core-crossover.yml +++ b/.github/workflows/frozen-537-core-crossover.yml @@ -47,6 +47,7 @@ jobs: .github/scripts/frozen_core_crossover.py .github/scripts/test_frozen_core_crossover.py .github/scripts/frozen_bdn_control.py + .github/scripts/frozen_scope_control.py .github/scripts/test_frozen_bdn_control.py .github/scripts/frozen_concurrent_control.py .github/workflows/frozen-537-core-crossover.yml diff --git a/.github/workflows/frozen-bdn-control.yml b/.github/workflows/frozen-bdn-control.yml index 1f32bd6e9..9f747015c 100644 --- a/.github/workflows/frozen-bdn-control.yml +++ b/.github/workflows/frozen-bdn-control.yml @@ -7,6 +7,7 @@ on: - '.github/scripts/frozen_bdn_control.py' - '.github/scripts/test_frozen_bdn_control.py' - '.github/scripts/frozen_concurrent_control.py' + - '.github/scripts/frozen_scope_control.py' - '.github/workflows/frozen-bdn-control.yml' workflow_dispatch: inputs: @@ -15,6 +16,17 @@ on: required: false type: string + benchmark_case: + description: Original runner and parameter to replay + required: true + default: concurrent + type: choice + options: + - concurrent + - scoped-dispatch + - log-composed + - queue-native + permissions: contents: read actions: read @@ -41,10 +53,11 @@ jobs: env: GH_TOKEN: ${{ github.token }} PERFORMANCE_RUN: ${{ inputs.performance_run || '42310409459' }} + BENCHMARK_CASE: ${{ inputs.benchmark_case || 'concurrent' }} run: | [[ "$PERFORMANCE_RUN" =~ ^[0-9]+$ ]] || { echo "Invalid Performance run ID: $PERFORMANCE_RUN" >&2; exit 1; } gh run download "$PERFORMANCE_RUN" --name "performance-$PERFORMANCE_RUN-1" --dir inputs - python3 .github/scripts/frozen_bdn_control.py inputs results/original-engine + python3 .github/scripts/frozen_bdn_control.py inputs results/original-engine --case "$BENCHMARK_CASE" - name: Retain all outcomes and executable inputs if: always() uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 @@ -56,4 +69,6 @@ jobs: .github/scripts/frozen_bdn_control.py .github/scripts/test_frozen_bdn_control.py .github/scripts/frozen_concurrent_control.py + .github/scripts/frozen_scope_control.py + .github/workflows/frozen-bdn-control.yml retention-days: 90 diff --git a/.github/workflows/frozen-core-crossover.yml b/.github/workflows/frozen-core-crossover.yml index 7bc33b8ae..beef57a40 100644 --- a/.github/workflows/frozen-core-crossover.yml +++ b/.github/workflows/frozen-core-crossover.yml @@ -47,6 +47,7 @@ jobs: .github/scripts/frozen_core_crossover.py .github/scripts/test_frozen_core_crossover.py .github/scripts/frozen_bdn_control.py + .github/scripts/frozen_scope_control.py .github/scripts/test_frozen_bdn_control.py .github/scripts/frozen_concurrent_control.py .github/workflows/frozen-core-crossover.yml diff --git a/.github/workflows/frozen-exact-crossover.yml b/.github/workflows/frozen-exact-crossover.yml index 10d517d51..2b5c67ad4 100644 --- a/.github/workflows/frozen-exact-crossover.yml +++ b/.github/workflows/frozen-exact-crossover.yml @@ -131,6 +131,7 @@ jobs: .github/scripts/frozen_concurrent_control.py .github/scripts/frozen_core_crossover.py .github/scripts/frozen_bdn_control.py + .github/scripts/frozen_scope_control.py .github/scripts/frozen_exact_crossover.py .github/scripts/test_frozen_exact_crossover.py .github/scripts/read_native_allocations.py diff --git a/.github/workflows/frozen-native-owner-control.yml b/.github/workflows/frozen-native-owner-control.yml index 72eb9278e..bfd9be15b 100644 --- a/.github/workflows/frozen-native-owner-control.yml +++ b/.github/workflows/frozen-native-owner-control.yml @@ -71,6 +71,7 @@ jobs: .diagnostic-tools/ .github/workflows/frozen-native-owner-control.yml .github/scripts/frozen_bdn_control.py + .github/scripts/frozen_scope_control.py .github/scripts/test_frozen_bdn_control.py .github/scripts/frozen_concurrent_control.py tools/FrozenAllocationReader/ diff --git a/.github/workflows/frozen-native-tail-control.yml b/.github/workflows/frozen-native-tail-control.yml index 28c845d6e..66c796e66 100644 --- a/.github/workflows/frozen-native-tail-control.yml +++ b/.github/workflows/frozen-native-tail-control.yml @@ -141,6 +141,7 @@ jobs: tools/FrozenAllocationReader/ .diagnostic-tools/ .github/scripts/frozen_bdn_control.py + .github/scripts/frozen_scope_control.py .github/scripts/frozen_concurrent_control.py .github/scripts/test_frozen_bdn_control.py .github/workflows/frozen-native-tail-control.yml diff --git a/.github/workflows/frozen-net10-protocol-control.yml b/.github/workflows/frozen-net10-protocol-control.yml index bb4fcee20..c591d34fc 100644 --- a/.github/workflows/frozen-net10-protocol-control.yml +++ b/.github/workflows/frozen-net10-protocol-control.yml @@ -75,6 +75,7 @@ jobs: tools/FrozenFixtureProbe/InvocationAllocations.cs tools/FrozenMeasurementEvents.cs .github/scripts/frozen_bdn_control.py + .github/scripts/frozen_scope_control.py .github/scripts/test_frozen_bdn_control.py .github/scripts/frozen_concurrent_control.py .github/scripts/test_frozen_concurrent_control.py diff --git a/.github/workflows/sequence-allocation-control.yml b/.github/workflows/sequence-allocation-control.yml index a131f7b6a..f7e7aae91 100644 --- a/.github/workflows/sequence-allocation-control.yml +++ b/.github/workflows/sequence-allocation-control.yml @@ -71,6 +71,7 @@ jobs: inputs/ .github/scripts/benchmark_gate.py .github/scripts/frozen_bdn_control.py + .github/scripts/frozen_scope_control.py .github/scripts/frozen_concurrent_control.py .github/workflows/sequence-allocation-control.yml retention-days: 90