refactor(perf): Unity Perf Harness テスト容易化 (interface 抽出 + 純関数ヘルパー)#101
Merged
Conversation
- Ros2Unity/Assets/Perf/PerfPlayerEntry.cs (282 行) の mixed concerns (CLI 解析 / participant 構築 / Stopwatch / Profiler / measure_done 構築 / diagnostics 抽出 / polling) を IPerfMetricsSink / IPerfProfilerSampler / IPerfClock の 3 interface + MeasureDoneBuilder / PerfDiagnosticsBuilder / PerfJson の純関数ヘルパーに切り出す - NDJSON event vocabulary と measure_done フィールド名は完全互換 - 既存 PerfProfilerMode (Lean/Full) / sentinel file 動作 / 外部 CLI は不変 - 新規 EditMode テスト 5 ファイル (約 20 ケース) を追加
- AddReceiveDiagnostics のフィールド数を 11 → 10 に修正 - AddTransportDiagnostics のフィールド数を「12 個 (transport あたり 6)」に明確化 - テストケース数を内訳表 (合計 33 ケース) として 7.1 節を追加 - 受け入れ基準の表記を内訳表への参照に置換
- 15 タスク (TDD + foundation + refactor + verify) - 新規 12 Perf/ ファイル + 5 Tests/EditMode/ ファイル - 既存 PerfMetricsWriter / PerfProfilerRecorders / PerfPlayerEntry.Run* を interface 抽象経由に refactor、NDJSON 完全互換を維持 - 33 ケース追加 (PerfJson 16 / MeasureDoneBuilder 8 / PerfDiagnosticsBuilder 4 / StopwatchPerfClock 2 / PerfRunFlow 3 fast + 1 Explicit)
合わせて以下を修正: - PerfMetricsWriter/PerfProfilerRecorders: interface 実装メソッドを public に - MeasureDoneBuilder: 引数型を IDictionary に変更 (IReadOnlyDictionary から)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
Ros2Unity/Assets/Perf/配下を、純関数ヘルパー + 差し替え可能 interface 中心の設計に再構成。EditMode から直接テストできる構造にし、perf run event 出力 (measure_done) の構造を assert できるようにする。
変更内容
新規ファイル (12 Perf/ + 5 Tests/EditMode/)
IPerfMetricsSink/IPerfProfilerSampler/IPerfClock/IPerfStopwatch(4 interface)PerfJson(Escape / WriteString / WriteNumber / WriteBoolean / WriteValue 純関数)MeasureDoneBuilder.BuildPublish/.BuildSubscribe(純関数)PerfTransportDiagnostics/PerfSubscriptionDiagnostics(値オブジェクト)PerfDiagnosticsBuilder.BuildReceive(純関数)StopwatchPerfClock/StopwatchWrapper(IPerfClock 実装)PerfHarnessFakes(テスト用 fake 4 種)PerfJsonTests/MeasureDoneBuilderTests/PerfDiagnosticsBuilderTests/PerfRunFlowTests(4 テストファイル)変更ファイル
PerfPlayerEntry.cs:Run*signature を 5 引数 (participant+ 3 interface) に変更。measure_done / diagnostics 構築を builder に置換PerfMetricsWriter.cs: 内部実装をPerfJson経由に。IPerfMetricsSink実装PerfProfilerRecorders.cs:IPerfProfilerSampler実装テスト結果
ROSettaDDS.UnityVerification.Tests)rosettadds-perf-runner.Tests)rosettadds.Tests)Unity EditMode は
-batchmode -runTestsで実行 (16.25 秒)。check_unity_meta.shクリーン。受け入れ基準
start/ready/matched/measure_start/measure_done/waiting_for_release/released/done/error/receive_diagnostics)measure_doneフィールド名完全互換 (elapsed_ms/sent/received/serialized_bytes_per_message/serialized_bytes/messages_per_second/*_available/_last/*_total/_samples/*_transport_diagnostics_available/*_udp_*/subscription_*/rtps_*)internalのみ)check_unity_meta.shクリーン既知の仕様逸脱
PerfJson.Write*のfirstパラメータ既定値がfalse→true(Task 3 でテストと整合させるため)。影響:
PerfMetricsWriter.Event内で全呼び出しにfirst: true/falseを明示 (Task 9)MeasureDoneBuilder.BuildPublish/SubscribeのprofilerFields引数型をIReadOnlyDictionary→IDictionary(Task 14 で interface 実装のコンパイルエラー修正)PerfMetricsWriter.Event/.WriteSentinelをinternal→public(interface 実装上必須)PerfProfilerRecorders.Snapshotの戻り型をDictionary→IDictionary(interface 実装上必須)参照
docs/superpowers/specs/2026-06-29-unity-perf-harness-testability-design.mddocs/superpowers/plans/2026-06-29-unity-perf-harness-testability.md