From 682eae82b67e629f93345022c37d7e13caece285 Mon Sep 17 00:00:00 2001 From: cflmy Date: Tue, 24 Nov 2026 20:48:26 +0800 Subject: [PATCH] perf: measure run/call through the current Observation snapshot The nine G4 workloads still requested the retired `run/call --json` option, so every non-check workload exited 2 and was recorded as CORRECTNESS_FAIL; the RC performance gate could not run at all. - Request `--output json` for run/call workloads and re-record the committed expected digests. - Pin correctness to the current snapshot: terminal status/result, committed stdout/stderr byte digests, and ordered event-kind counts with a sequence digest. Run ids, wall-clock stamps and host paths are excluded, so a correct program keeps one stable digest. - Add tooling tests for the workload catalogue and digest stability. --- tools/ci/test_perf_workloads.py | 123 +++++ tools/perf/README.md | 4 + tools/perf/expected/allocator-free-list.json | 535 ++++++++++--------- tools/perf/expected/bytecode-vm.json | 91 ++-- tools/perf/expected/factorial-run.json | 50 +- tools/perf/expected/http-parser.json | 84 ++- tools/perf/expected/json-parser.json | 404 +++++++------- tools/perf/expected/matrix-multiply.json | 271 +++++----- tools/perf/expected/stdlib-print-demo.json | 42 +- tools/perf/expected/table-sort.json | 192 ++++--- tools/perf/runner.py | 68 ++- tools/perf/workloads.json | 24 +- 12 files changed, 1145 insertions(+), 743 deletions(-) create mode 100644 tools/ci/test_perf_workloads.py diff --git a/tools/ci/test_perf_workloads.py b/tools/ci/test_perf_workloads.py new file mode 100644 index 0000000..f9d8c81 --- /dev/null +++ b/tools/ci/test_perf_workloads.py @@ -0,0 +1,123 @@ +"""Tests for the performance workload catalogue and correctness digest. + +The G4 release gate runs one fixed release binary over nine workloads. A +retired CLI option or a digest that changes per invocation silently turns a +correctness-verified measurement into CORRECTNESS_FAIL, so both are pinned +here. +""" + +import importlib.util +import json +import pathlib +import unittest + +ROOT = pathlib.Path(__file__).resolve().parents[2] +WORKLOADS = ROOT / "tools" / "perf" / "workloads.json" +RUNNER = ROOT / "tools" / "perf" / "runner.py" + + +def load_runner(): + spec = importlib.util.spec_from_file_location("marqdo_perf_runner", RUNNER) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + return module + + +def snapshot(run_id: str, status: str, value, extra_file: str = "/tmp/index.mq.md"): + return { + "schema": "marqdo.observation", + "schema_version": 1, + "run": {"id": run_id, "status": status, "source": None}, + "capture": {}, + "events": [ + { + "schema": "marqdo.observation", + "schema_version": 1, + "run_id": run_id, + "seq": 0, + "kind": "stream.opened", + "payload": {"producer": {"name": "marqdo", "version": "3.0.0-rc.3"}}, + }, + { + "schema": "marqdo.observation", + "schema_version": 1, + "run_id": run_id, + "seq": 1, + "kind": "run.started", + "payload": {"entry": "e::index.mq.md::main", "started_unix_ms": 1795523668882}, + }, + { + "schema": "marqdo.observation", + "schema_version": 1, + "run_id": run_id, + "seq": 2, + "kind": "run.completed", + "payload": {"status": status, "value": value, "value_type": "Int"}, + }, + ], + } + + +class WorkloadCatalogueTest(unittest.TestCase): + def test_run_and_call_workloads_use_the_current_output_option(self): + catalogue = json.loads(WORKLOADS.read_text(encoding="utf-8")) + workloads = catalogue["workloads"] + self.assertEqual(len(workloads), 9) + for workload in workloads: + argv = workload["argv"] + if workload["kind"] in ("run", "call"): + self.assertIn( + ["--output", "json"], + [argv[index : index + 2] for index in range(len(argv))], + f"{workload['name']} must request the current Observation snapshot", + ) + self.assertNotIn( + "--json", + argv, + f"{workload['name']} still passes the retired run/call flag", + ) + else: + self.assertIn("--json", argv) + + +class DigestStabilityTest(unittest.TestCase): + def setUp(self): + self.runner = load_runner() + + def test_observation_digest_ignores_run_identity_and_paths(self): + first = self.runner.wire_digest(snapshot("run-1", "ok", 120)) + second = self.runner.wire_digest( + snapshot("run-2", "ok", 120, extra_file="/other/host/index.mq.md") + ) + self.assertEqual(first, second) + + def test_observation_digest_tracks_the_result(self): + ok = self.runner.wire_digest(snapshot("run-1", "ok", 120)) + wrong = self.runner.wire_digest(snapshot("run-1", "ok", 121)) + failed = self.runner.wire_digest(snapshot("run-1", "error", 120)) + self.assertNotEqual(ok, wrong) + self.assertNotEqual(ok, failed) + + def test_observation_digest_tracks_the_event_stream(self): + document = snapshot("run-1", "ok", 120) + truncated = dict(document) + truncated["events"] = document["events"][:2] + self.assertNotEqual( + self.runner.wire_digest(document), self.runner.wire_digest(truncated) + ) + + def test_check_document_keeps_the_command_digest(self): + report = { + "command": "check", + "success": True, + "diagnostics": [{"code": "sem.x", "severity": "error", "line": 1, "column": 2, "message": "m"}], + "stdout": "", + "stderr": "", + } + normalized = self.runner.normalize(report) + self.assertEqual(normalized["command"], "check") + self.assertEqual(len(normalized["diagnostics"]), 1) + + +if __name__ == "__main__": + unittest.main() diff --git a/tools/perf/README.md b/tools/perf/README.md index 87dafd9..15f18c0 100644 --- a/tools/perf/README.md +++ b/tools/perf/README.md @@ -10,6 +10,10 @@ workload whose wire output did not match the committed expected digest. `Cargo.lock` digest, `rustc -vV`, source SHA and profile. * Correctness comes first: every warmup run is parsed and hashed. A mismatch is `CORRECTNESS_FAIL`; its faster wall time is never reported. + `run`/`call` workloads request the current Observation snapshot + (`--output json`); the digest pins the terminal status/result, the committed + stdout/stderr byte digests and the ordered event-kind counts, never a run id + or a host path, so it is stable across invocations. * Approved-node release evidence needs at least 5 warmups and 20 samples per workload on a dedicated, stable node. A maintainer-approved shared-node RC comparison needs the same sample counts in at least three paired runs. diff --git a/tools/perf/expected/allocator-free-list.json b/tools/perf/expected/allocator-free-list.json index 3d2fedc..f486e90 100644 --- a/tools/perf/expected/allocator-free-list.json +++ b/tools/perf/expected/allocator-free-list.json @@ -1,297 +1,324 @@ { "normalized": { - "command": "run", - "stderr": "", - "stdout": "", - "success": true, - "value": { - "items": [ - { - "entries": { - "ok": { - "type": "bool", - "value": true + "events": { + "by_kind": { + "branch.eval": 134, + "call.enter": 255, + "call.exit": 255, + "effect": 249, + "loop.iteration": 40, + "parameter.observed": 558, + "return": 255, + "run.completed": 1, + "run.started": 1, + "stream.opened": 1, + "variable.assigned": 507 + }, + "count": 2256, + "sequence_sha256": "sha256:7ef37396e4e92c246a44e144f5532b8cefe460cb9bffe4897a561cf42f6a2b4b" + }, + "schema": "marqdo.observation", + "status": "ok", + "stderr": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "stdout": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "terminal": { + "status": "ok", + "value": { + "items": [ + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "16", + "type": "int" + } }, - "value": { - "decimal": "16", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "32", + "type": "int" + } }, - "value": { - "decimal": "32", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "16", + "type": "int" + } }, - "value": { - "decimal": "16", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "16", + "type": "int" + } }, - "value": { - "decimal": "16", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "32", + "type": "int" + } }, - "value": { - "decimal": "32", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "56", + "type": "int" + } }, - "value": { - "decimal": "56", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "56", + "type": "int" + } }, - "value": { - "decimal": "56", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "72", + "type": "int" + } }, - "value": { - "decimal": "72", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "96", + "type": "int" + } }, - "value": { - "decimal": "96", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "112", + "type": "int" + } }, - "value": { - "decimal": "112", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "code": { - "type": "text", - "value": "alloc.no_space" + { + "entries": { + "code": { + "type": "text", + "value": "alloc.no_space" + }, + "message": { + "type": "text", + "value": "没有足够的空闲空间" + }, + "ok": { + "type": "bool", + "value": false + } }, - "message": { - "type": "text", - "value": "没有足够的空闲空间" - }, - "ok": { - "type": "bool", - "value": false - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "16", + "type": "int" + } }, - "value": { - "decimal": "16", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "32", + "type": "int" + } }, - "value": { - "decimal": "32", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "48", + "type": "int" + } }, - "value": { - "decimal": "48", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "16", + "type": "int" + } }, - "value": { - "decimal": "16", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "code": { - "type": "text", - "value": "alloc.no_space" + { + "entries": { + "code": { + "type": "text", + "value": "alloc.no_space" + }, + "message": { + "type": "text", + "value": "没有足够的空闲空间" + }, + "ok": { + "type": "bool", + "value": false + } }, - "message": { - "type": "text", - "value": "没有足够的空闲空间" - }, - "ok": { - "type": "bool", - "value": false - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "type": "none" + } }, - "value": { - "type": "none" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "code": { - "type": "text", - "value": "alloc.double_free" + { + "entries": { + "code": { + "type": "text", + "value": "alloc.double_free" + }, + "message": { + "type": "text", + "value": "块已在空闲链表" + }, + "ok": { + "type": "bool", + "value": false + } }, - "message": { - "type": "text", - "value": "块已在空闲链表" - }, - "ok": { - "type": "bool", - "value": false - } + "type": "map" }, - "type": "map" - }, - { - "decimal": "33", - "type": "int" - }, - { - "decimal": "22", - "type": "int" - }, - { - "decimal": "33", - "type": "int" - }, - { - "decimal": "33", - "type": "int" - }, - { - "decimal": "22", - "type": "int" - }, - { - "decimal": "44", - "type": "int" - }, - { - "decimal": "55", - "type": "int" - }, - { - "decimal": "66", - "type": "int" - }, - { - "decimal": "77", - "type": "int" - } - ], - "type": "list" + { + "decimal": "33", + "type": "int" + }, + { + "decimal": "22", + "type": "int" + }, + { + "decimal": "33", + "type": "int" + }, + { + "decimal": "33", + "type": "int" + }, + { + "decimal": "22", + "type": "int" + }, + { + "decimal": "44", + "type": "int" + }, + { + "decimal": "55", + "type": "int" + }, + { + "decimal": "66", + "type": "int" + }, + { + "decimal": "77", + "type": "int" + } + ], + "type": "list" + }, + "value_type": "List" } }, "schema": "marqdo.perf.expected.v1", - "wire_sha256": "sha256:039ec1523726f48375f1fb5fafdfe849e296e1ee39b8a4820a0a0970cf3f8c3b", + "wire_sha256": "sha256:1fc8f64612fe89c66cc38884f31ba2a883c3962a36d431b4e8d224ce8a58922b", "workload": "allocator-free-list" } diff --git a/tools/perf/expected/bytecode-vm.json b/tools/perf/expected/bytecode-vm.json index 0b0b6fe..63bc29c 100644 --- a/tools/perf/expected/bytecode-vm.json +++ b/tools/perf/expected/bytecode-vm.json @@ -1,42 +1,69 @@ { "normalized": { - "command": "run", - "stderr": "", - "stdout": "", - "success": true, - "value": { - "items": [ - { - "entries": { - "ok": { - "type": "bool", - "value": true + "events": { + "by_kind": { + "branch.eval": 51, + "call.enter": 7, + "call.exit": 7, + "effect": 28, + "loop.iteration": 34, + "parameter.observed": 14, + "return": 7, + "run.completed": 1, + "run.started": 1, + "stream.opened": 1, + "variable.assigned": 66 + }, + "count": 217, + "sequence_sha256": "sha256:218b342c70a1388d8f9e5ba5843c828ea53fa01c31ddae171c023dd581423f3a" + }, + "schema": "marqdo.observation", + "status": "ok", + "stderr": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "stdout": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "terminal": { + "status": "ok", + "value": { + "items": [ + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "36", + "type": "int" + } }, - "value": { - "decimal": "36", - "type": "int" - } + "type": "map" }, - "type": "map" - }, - { - "entries": { - "ok": { - "type": "bool", - "value": true + { + "entries": { + "ok": { + "type": "bool", + "value": true + }, + "value": { + "decimal": "42", + "type": "int" + } }, - "value": { - "decimal": "42", - "type": "int" - } - }, - "type": "map" - } - ], - "type": "list" + "type": "map" + } + ], + "type": "list" + }, + "value_type": "List" } }, "schema": "marqdo.perf.expected.v1", - "wire_sha256": "sha256:418131f5780815da5716d84ed5c00269760a881856cce67e0f4c8b42d417c7ec", + "wire_sha256": "sha256:35b915e08c3f69fa0f6375565caaee21393a707d35852d03734b4b9c9643a5c0", "workload": "bytecode-vm" } diff --git a/tools/perf/expected/factorial-run.json b/tools/perf/expected/factorial-run.json index 4bbe453..8eabeec 100644 --- a/tools/perf/expected/factorial-run.json +++ b/tools/perf/expected/factorial-run.json @@ -1,24 +1,40 @@ { "normalized": { - "command": "call", - "diagnostics": [ - { - "code": "sem.inferred_signature", - "column": 1, - "line": 3, - "message": "function signature was inferred; declare it with `params(...)`", - "severity": "warning" - } - ], - "stderr": "", - "stdout": "", - "success": true, - "value": { - "decimal": "120", - "type": "int" + "events": { + "by_kind": { + "branch.eval": 9, + "call.enter": 5, + "call.exit": 5, + "parameter.observed": 5, + "return": 5, + "run.completed": 1, + "run.started": 1, + "stream.opened": 1, + "variable.assigned": 4 + }, + "count": 36, + "sequence_sha256": "sha256:1c776fb38bbfa9cfb32e907385b18e75d84df3e62d96fee7859a739054513daf" + }, + "schema": "marqdo.observation", + "status": "ok", + "stderr": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "stdout": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "terminal": { + "status": "ok", + "value": { + "decimal": "120", + "type": "int" + }, + "value_type": "Int" } }, "schema": "marqdo.perf.expected.v1", - "wire_sha256": "sha256:0cbd8ab0b0e9e671e7e54f707ff2de00181b2721924b7fdec998ff9611873275", + "wire_sha256": "sha256:34c724c5abc46f3c38875cf90c23e70e8f4048124a8571665f00f30bbbfab758", "workload": "factorial-run" } diff --git a/tools/perf/expected/http-parser.json b/tools/perf/expected/http-parser.json index 1a7bf76..bf81eee 100644 --- a/tools/perf/expected/http-parser.json +++ b/tools/perf/expected/http-parser.json @@ -1,36 +1,62 @@ { "normalized": { - "command": "run", - "stderr": "", - "stdout": "", - "success": true, - "value": { - "items": [ - { - "decimal": "200", - "type": "int" - }, - { - "type": "text", - "value": "OK" - }, - { - "type": "text", - "value": "text/plain" - }, - { - "type": "text", - "value": "hello world" - }, - { - "type": "text", - "value": "GET /health HTTP/1.1\r\nAccept: text/plain\r\nHost: example.test\r\n\r\n" - } - ], - "type": "list" + "events": { + "by_kind": { + "branch.eval": 545, + "call.enter": 34, + "call.exit": 34, + "loop.iteration": 756, + "parameter.observed": 90, + "return": 34, + "run.completed": 1, + "run.started": 1, + "stream.opened": 1, + "variable.assigned": 1548 + }, + "count": 3044, + "sequence_sha256": "sha256:d394bf12395c193818794d34de4fef9f6a9048eb63235f30ce53a6785c4a2ab5" + }, + "schema": "marqdo.observation", + "status": "ok", + "stderr": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "stdout": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "terminal": { + "status": "ok", + "value": { + "items": [ + { + "decimal": "200", + "type": "int" + }, + { + "type": "text", + "value": "OK" + }, + { + "type": "text", + "value": "text/plain" + }, + { + "type": "text", + "value": "hello world" + }, + { + "type": "text", + "value": "GET /health HTTP/1.1\r\nAccept: text/plain\r\nHost: example.test\r\n\r\n" + } + ], + "type": "list" + }, + "value_type": "List" } }, "schema": "marqdo.perf.expected.v1", - "wire_sha256": "sha256:540f8dd9a2071d40c1f07d82961e0e0174822e123c828ffc5d2a06cc880052ed", + "wire_sha256": "sha256:1617796958d6b8e30c65884f26640f1072cde6037158e3abf0a196ecb9e39712", "workload": "http-parser" } diff --git a/tools/perf/expected/json-parser.json b/tools/perf/expected/json-parser.json index 15bfa9c..405b9b3 100644 --- a/tools/perf/expected/json-parser.json +++ b/tools/perf/expected/json-parser.json @@ -1,199 +1,225 @@ { "normalized": { - "command": "run", - "stderr": "", - "stdout": "", - "success": true, - "value": { - "items": [ - { - "entries": { - "next": { - "decimal": "20", - "type": "int" - }, - "ok": { - "type": "bool", - "value": true - }, - "value": { - "items": [ - { - "decimal": "1", - "type": "int" - }, - { - "decimal": "23", - "type": "int" - }, - { - "items": [ - { - "decimal": "4", - "type": "int" - }, - { - "decimal": "5", - "type": "int" - } - ], - "type": "list" - }, - { - "decimal": "-6", - "type": "int" - } - ], - "type": "list" - } - }, - "type": "map" - }, - { - "entries": { - "code": { - "type": "text", - "value": "json.invalid_array" - }, - "message": { - "type": "text", - "value": "数组缺少逗号或 ]" - }, - "ok": { - "type": "bool", - "value": false - } - }, - "type": "map" - }, - { - "entries": { - "code": { - "type": "text", - "value": "json.unexpected_eof" - }, - "message": { - "type": "text", - "value": "数组未闭合" - }, - "ok": { - "type": "bool", - "value": false - } - }, - "type": "map" - }, - { - "entries": { - "next": { - "decimal": "35", - "type": "int" - }, - "ok": { - "type": "bool", - "value": true - }, - "value": { - "entries": { - "a": { - "decimal": "1", - "type": "int" - }, - "b": { - "items": [ - { - "type": "bool", - "value": true - }, - { - "type": "none" - }, - { - "type": "text", - "value": "说\"好" - } - ], - "type": "list" - } + "events": { + "by_kind": { + "branch.eval": 632, + "call.enter": 341, + "call.exit": 341, + "loop.iteration": 208, + "parameter.observed": 567, + "return": 341, + "run.completed": 1, + "run.started": 1, + "stream.opened": 1, + "variable.assigned": 700 + }, + "count": 3133, + "sequence_sha256": "sha256:cac83ea2856c09d105554b0e0d3bd1ed3d2541c19af51bddf236ab9b6e87f354" + }, + "schema": "marqdo.observation", + "status": "ok", + "stderr": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "stdout": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "terminal": { + "status": "ok", + "value": { + "items": [ + { + "entries": { + "next": { + "decimal": "20", + "type": "int" }, - "type": "map" - } - }, - "type": "map" - }, - { - "entries": { - "next": { - "decimal": "6", - "type": "int" - }, - "ok": { - "type": "bool", - "value": true - }, - "value": { - "type": "text", - "value": "a\nb" - } - }, - "type": "map" - }, - { - "entries": { - "next": { - "decimal": "37", - "type": "int" - }, - "ok": { - "type": "bool", - "value": true - }, - "value": { - "items": [ - { - "decimal": "1", - "type": "int" - }, - { - "type": "float", - "value": 2.5 - }, - { - "type": "float", - "value": -300.0 - }, - { - "type": "float", - "value": 0.4 - }, - { - "entries": { - "a": { - "type": "float", - "value": 1.0 - } + "ok": { + "type": "bool", + "value": true + }, + "value": { + "items": [ + { + "decimal": "1", + "type": "int" }, - "type": "map" - }, - { - "type": "text", - "value": "x" - } - ], - "type": "list" - } + { + "decimal": "23", + "type": "int" + }, + { + "items": [ + { + "decimal": "4", + "type": "int" + }, + { + "decimal": "5", + "type": "int" + } + ], + "type": "list" + }, + { + "decimal": "-6", + "type": "int" + } + ], + "type": "list" + } + }, + "type": "map" }, - "type": "map" - }, - { - "type": "text", - "value": "[1, 2.5, -300.0, 0.4, {\"a\": 1.0}, \"x\"]" - } - ], - "type": "list" + { + "entries": { + "code": { + "type": "text", + "value": "json.invalid_array" + }, + "message": { + "type": "text", + "value": "数组缺少逗号或 ]" + }, + "ok": { + "type": "bool", + "value": false + } + }, + "type": "map" + }, + { + "entries": { + "code": { + "type": "text", + "value": "json.unexpected_eof" + }, + "message": { + "type": "text", + "value": "数组未闭合" + }, + "ok": { + "type": "bool", + "value": false + } + }, + "type": "map" + }, + { + "entries": { + "next": { + "decimal": "35", + "type": "int" + }, + "ok": { + "type": "bool", + "value": true + }, + "value": { + "entries": { + "a": { + "decimal": "1", + "type": "int" + }, + "b": { + "items": [ + { + "type": "bool", + "value": true + }, + { + "type": "none" + }, + { + "type": "text", + "value": "说\"好" + } + ], + "type": "list" + } + }, + "type": "map" + } + }, + "type": "map" + }, + { + "entries": { + "next": { + "decimal": "6", + "type": "int" + }, + "ok": { + "type": "bool", + "value": true + }, + "value": { + "type": "text", + "value": "a\nb" + } + }, + "type": "map" + }, + { + "entries": { + "next": { + "decimal": "37", + "type": "int" + }, + "ok": { + "type": "bool", + "value": true + }, + "value": { + "items": [ + { + "decimal": "1", + "type": "int" + }, + { + "type": "float", + "value": 2.5 + }, + { + "type": "float", + "value": -300.0 + }, + { + "type": "float", + "value": 0.4 + }, + { + "entries": { + "a": { + "type": "float", + "value": 1.0 + } + }, + "type": "map" + }, + { + "type": "text", + "value": "x" + } + ], + "type": "list" + } + }, + "type": "map" + }, + { + "type": "text", + "value": "[1, 2.5, -300.0, 0.4, {\"a\": 1.0}, \"x\"]" + } + ], + "type": "list" + }, + "value_type": "List" } }, "schema": "marqdo.perf.expected.v1", - "wire_sha256": "sha256:d6f795f43eb1ae4c3d2f04254b8135f71d717ef8a649efdf7785f172b5381011", + "wire_sha256": "sha256:c9833930c28ef238a606db40b33005338e75b83cf9ad98ffaa16f6d9f371a12a", "workload": "json-parser" } diff --git a/tools/perf/expected/matrix-multiply.json b/tools/perf/expected/matrix-multiply.json index 8112825..6f8bbdf 100644 --- a/tools/perf/expected/matrix-multiply.json +++ b/tools/perf/expected/matrix-multiply.json @@ -1,130 +1,155 @@ { "normalized": { - "command": "run", - "stderr": "", - "stdout": "", - "success": true, - "value": { - "items": [ - { - "items": [ - { - "items": [ - { - "decimal": "1", - "type": "int" - }, - { - "decimal": "2", - "type": "int" - }, - { - "decimal": "3", - "type": "int" - } - ], - "type": "list" - }, - { - "items": [ - { - "decimal": "4", - "type": "int" - }, - { - "decimal": "5", - "type": "int" - }, - { - "decimal": "6", - "type": "int" - } - ], - "type": "list" - } - ], - "type": "list" - }, - { - "items": [ - { - "items": [ - { - "decimal": "7", - "type": "int" - }, - { - "decimal": "8", - "type": "int" - } - ], - "type": "list" - }, - { - "items": [ - { - "decimal": "9", - "type": "int" - }, - { - "decimal": "10", - "type": "int" - } - ], - "type": "list" - }, - { - "items": [ - { - "decimal": "11", - "type": "int" - }, - { - "decimal": "12", - "type": "int" - } - ], - "type": "list" - } - ], - "type": "list" - }, - { - "items": [ - { - "items": [ - { - "decimal": "58", - "type": "int" - }, - { - "decimal": "64", - "type": "int" - } - ], - "type": "list" - }, - { - "items": [ - { - "decimal": "139", - "type": "int" - }, - { - "decimal": "154", - "type": "int" - } - ], - "type": "list" - } - ], - "type": "list" - } - ], - "type": "list" + "events": { + "by_kind": { + "call.enter": 2, + "call.exit": 2, + "loop.iteration": 25, + "parameter.observed": 2, + "return": 2, + "run.completed": 1, + "run.started": 1, + "stream.opened": 1, + "variable.assigned": 54 + }, + "count": 90, + "sequence_sha256": "sha256:a2b99c523f389a8efd203f54a88f4c9c4ecefe03cf453a3c18ab255913423327" + }, + "schema": "marqdo.observation", + "status": "ok", + "stderr": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "stdout": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "terminal": { + "status": "ok", + "value": { + "items": [ + { + "items": [ + { + "items": [ + { + "decimal": "1", + "type": "int" + }, + { + "decimal": "2", + "type": "int" + }, + { + "decimal": "3", + "type": "int" + } + ], + "type": "list" + }, + { + "items": [ + { + "decimal": "4", + "type": "int" + }, + { + "decimal": "5", + "type": "int" + }, + { + "decimal": "6", + "type": "int" + } + ], + "type": "list" + } + ], + "type": "list" + }, + { + "items": [ + { + "items": [ + { + "decimal": "7", + "type": "int" + }, + { + "decimal": "8", + "type": "int" + } + ], + "type": "list" + }, + { + "items": [ + { + "decimal": "9", + "type": "int" + }, + { + "decimal": "10", + "type": "int" + } + ], + "type": "list" + }, + { + "items": [ + { + "decimal": "11", + "type": "int" + }, + { + "decimal": "12", + "type": "int" + } + ], + "type": "list" + } + ], + "type": "list" + }, + { + "items": [ + { + "items": [ + { + "decimal": "58", + "type": "int" + }, + { + "decimal": "64", + "type": "int" + } + ], + "type": "list" + }, + { + "items": [ + { + "decimal": "139", + "type": "int" + }, + { + "decimal": "154", + "type": "int" + } + ], + "type": "list" + } + ], + "type": "list" + } + ], + "type": "list" + }, + "value_type": "List" } }, "schema": "marqdo.perf.expected.v1", - "wire_sha256": "sha256:c5edb02098191e081a143b8f5d23424fcc43172643a44912cdc8ae17ace99cc2", + "wire_sha256": "sha256:b975ac00d3e9d4d01d7e0fd26e0fde152333b254d38e7e1c4195bde824e97f32", "workload": "matrix-multiply" } diff --git a/tools/perf/expected/stdlib-print-demo.json b/tools/perf/expected/stdlib-print-demo.json index 2b7c03b..498479e 100644 --- a/tools/perf/expected/stdlib-print-demo.json +++ b/tools/perf/expected/stdlib-print-demo.json @@ -1,14 +1,42 @@ { "normalized": { - "command": "run", - "stderr": "", - "stdout": "[\"文本\", 2, 1.5, [3, true], {a: 1, b: \"x\"}, None]\n[\"文本\", 2, 1.5, [3, true], {a: 1, b: \"x\"}, None]\nTable[名称 | 分数]{甲 | 87; 乙 | 92}\nTable[名称 | 分数]{甲 | 87; 乙 | 92}\n[Formula(\"a = 1\"), Code(\"text\", 9 bytes), FunctionRef(root:default::demo.mq.md::演示函数)]\n[Formula(\"a = 1\"), Code(\"text\", 9 bytes), FunctionRef(root:default::demo.mq.md::演示函数)]\n", - "success": true, - "value": { - "type": "none" + "events": { + "by_kind": { + "branch.eval": 1956, + "call.enter": 131, + "call.exit": 131, + "effect": 404, + "loop.iteration": 810, + "parameter.observed": 166, + "return": 131, + "run.completed": 1, + "run.started": 1, + "stdout.chunk": 6, + "stream.opened": 1, + "variable.assigned": 2533 + }, + "count": 6271, + "sequence_sha256": "sha256:e17ea3ebe3ecd40f9e619f06e3bd9d4370d34616caf02a6099bbffe0f686522d" + }, + "schema": "marqdo.observation", + "status": "ok", + "stderr": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "stdout": { + "bytes": 380, + "sha256": "sha256:4f5fcde6b4073511330c50f15bf07db13abc2cf0cf71de777e8e23ca870220fe" + }, + "terminal": { + "status": "ok", + "value": { + "type": "none" + }, + "value_type": "None" } }, "schema": "marqdo.perf.expected.v1", - "wire_sha256": "sha256:80dfbfb894544b5cd4281999a67deaa9ce4fb19ef32d160fb4ee72dbd615d03c", + "wire_sha256": "sha256:7bed5196b8cd52d1de12561f445bc2271dd5e91ed9c4065ebf79d0cb22d8a826", "workload": "stdlib-print-demo" } diff --git a/tools/perf/expected/table-sort.json b/tools/perf/expected/table-sort.json index 73aed24..b040fa3 100644 --- a/tools/perf/expected/table-sort.json +++ b/tools/perf/expected/table-sort.json @@ -1,94 +1,120 @@ { "normalized": { - "command": "run", - "stderr": "", - "stdout": "", - "success": true, - "value": { - "items": [ - { - "header": [ - "名称", - "分数" - ], - "rows": [ - [ - { - "type": "text", - "value": "甲" - }, - { - "decimal": "87", - "type": "int" - } + "events": { + "by_kind": { + "branch.eval": 9, + "call.enter": 5, + "call.exit": 5, + "loop.iteration": 10, + "parameter.observed": 11, + "return": 5, + "run.completed": 1, + "run.started": 1, + "stream.opened": 1, + "variable.assigned": 35 + }, + "count": 83, + "sequence_sha256": "sha256:287e3f01941c53559c4113fceded4612a1f6c8ff44d2c19712aebf3c9034a172" + }, + "schema": "marqdo.observation", + "status": "ok", + "stderr": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "stdout": { + "bytes": 0, + "sha256": "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855" + }, + "terminal": { + "status": "ok", + "value": { + "items": [ + { + "header": [ + "名称", + "分数" ], - [ - { - "type": "text", - "value": "乙" - }, - { - "decimal": "92", - "type": "int" - } + "rows": [ + [ + { + "type": "text", + "value": "甲" + }, + { + "decimal": "87", + "type": "int" + } + ], + [ + { + "type": "text", + "value": "乙" + }, + { + "decimal": "92", + "type": "int" + } + ], + [ + { + "type": "text", + "value": "丙" + }, + { + "decimal": "71", + "type": "int" + } + ] ], - [ - { - "type": "text", - "value": "丙" - }, - { - "decimal": "71", - "type": "int" - } - ] - ], - "type": "table" - }, - { - "header": [ - "名称", - "分数" - ], - "rows": [ - [ - { - "type": "text", - "value": "丙" - }, - { - "decimal": "71", - "type": "int" - } + "type": "table" + }, + { + "header": [ + "名称", + "分数" ], - [ - { - "type": "text", - "value": "甲" - }, - { - "decimal": "87", - "type": "int" - } + "rows": [ + [ + { + "type": "text", + "value": "丙" + }, + { + "decimal": "71", + "type": "int" + } + ], + [ + { + "type": "text", + "value": "甲" + }, + { + "decimal": "87", + "type": "int" + } + ], + [ + { + "type": "text", + "value": "乙" + }, + { + "decimal": "92", + "type": "int" + } + ] ], - [ - { - "type": "text", - "value": "乙" - }, - { - "decimal": "92", - "type": "int" - } - ] - ], - "type": "table" - } - ], - "type": "list" + "type": "table" + } + ], + "type": "list" + }, + "value_type": "List" } }, "schema": "marqdo.perf.expected.v1", - "wire_sha256": "sha256:12b61dcd9955cb7e137c705e51e29d58322d9525993681170f2dded48e94ee97", + "wire_sha256": "sha256:d09caebb0ee91b593a8798f67a082ee38c008ea41274eeef3c05b2a4236081d1", "workload": "table-sort" } diff --git a/tools/perf/runner.py b/tools/perf/runner.py index 13c8677..dd9d01c 100755 --- a/tools/perf/runner.py +++ b/tools/perf/runner.py @@ -17,6 +17,8 @@ performance evidence. """ import argparse +import base64 +from collections import Counter import hashlib import json import os @@ -64,8 +66,72 @@ def git_sha(repo: Path) -> str: return output(["git", "-C", str(repo), "rev-parse", "HEAD"]) or "unknown" +OBSERVATION_SCHEMA = "marqdo.observation" +# Run-specific or host-specific payload fields never contribute to correctness. +VOLATILE_PAYLOAD_KEYS = {"file", "started_unix_ms"} + + +def _stable(value): + """Drop run/host-specific data from an observation payload.""" + if isinstance(value, dict): + return { + key: _stable(item) + for key, item in value.items() + if key not in VOLATILE_PAYLOAD_KEYS + } + if isinstance(value, list): + return [_stable(item) for item in value] + if isinstance(value, str): + return value.replace(str(ROOT), "") + return value + + +def _committed_bytes(chunks: list[str]) -> dict: + data = b"".join(base64.b64decode(chunk) for chunk in chunks) + return { + "bytes": len(data), + "sha256": f"sha256:{hashlib.sha256(data).hexdigest()}", + } + + def normalize(document: dict) -> dict: - """Canonical subset used for correctness: no timings, no trace, no paths.""" + """Canonical subset used for correctness: no timings, no run ids, no paths.""" + if document.get("schema") == OBSERVATION_SCHEMA: + # Current `run`/`call --output json` snapshot: one execution event + # sequence. The run id, wall-clock start and absolute paths are + # per-invocation. Correctness pins the terminal status/result, the + # committed stdout/stderr bytes and the ordered event kinds (count, + # per-kind totals and a sequence digest) without storing thousands of + # structural payloads in the repository. + events = document.get("events") or [] + kinds = [event.get("kind") or "" for event in events] + counts = Counter(kinds) + terminal = _stable(events[-1].get("payload")) if events else None + return { + "schema": OBSERVATION_SCHEMA, + "status": (document.get("run") or {}).get("status"), + "terminal": terminal, + "stdout": _committed_bytes( + [ + event["payload"]["data_base64"] + for event in events + if event.get("kind") == "stdout.chunk" + ] + ), + "stderr": _committed_bytes( + [ + event["payload"]["data_base64"] + for event in events + if event.get("kind") == "stderr.chunk" + ] + ), + "events": { + "count": len(events), + "sequence_sha256": "sha256:" + + hashlib.sha256("\n".join(kinds).encode("utf-8")).hexdigest(), + "by_kind": dict(sorted(counts.items())), + }, + } payload = {} for key in ("command", "success", "value", "stdout", "stderr", "errors"): if key in document: diff --git a/tools/perf/workloads.json b/tools/perf/workloads.json index 3637c6f..6ad3f39 100644 --- a/tools/perf/workloads.json +++ b/tools/perf/workloads.json @@ -21,7 +21,8 @@ "数学.阶乘", "--arg", "n=5", - "--json" + "--output", + "json" ] }, { @@ -31,7 +32,8 @@ "argv": [ "run", "tests/conformance/semantics/55-first-fit-free-list-allocator.mq.md", - "--json" + "--output", + "json" ] }, { @@ -41,7 +43,8 @@ "argv": [ "run", "tests/conformance/semantics/62-json-array-parser.mq.md", - "--json" + "--output", + "json" ] }, { @@ -51,7 +54,8 @@ "argv": [ "run", "tests/conformance/semantics/65-table-sort-stdlib.mq.md", - "--json" + "--output", + "json" ] }, { @@ -61,7 +65,8 @@ "argv": [ "run", "tests/conformance/semantics/63-memory-bytecode-vm.mq.md", - "--json" + "--output", + "json" ] }, { @@ -71,7 +76,8 @@ "argv": [ "run", "tests/conformance/semantics/70-matrix-multiply.mq.md", - "--json" + "--output", + "json" ] }, { @@ -81,7 +87,8 @@ "argv": [ "run", "tests/conformance/semantics/71-http-parser.mq.md", - "--json" + "--output", + "json" ] }, { @@ -91,7 +98,8 @@ "argv": [ "run", "stdlib/demo.mq.md", - "--json" + "--output", + "json" ] } ]