Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions .github/scripts/frozen_bdn_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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"),
Expand All @@ -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]
Expand Down Expand Up @@ -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)
Expand Down
126 changes: 86 additions & 40 deletions .github/scripts/test_frozen_bdn_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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"]
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/frozen-bdn-control.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ on:
type: choice
options:
- concurrent
- scope-only
- scoped-dispatch
- log-composed
- queue-composed
Expand Down
Loading
Loading