cli 教程

本教程使用 mare-mark 命令把 JSONL 事件文件转换为带成对比较的 HTML 报告,并检查、然后重放一个记录下来的验证失败。命令在仓库的检出目录中运行;示例使用 testdata/ 中的测试数据。

我想要用法
把 JSONL 事件文件转换为 HTML 报告mare-mark report <input.jsonl> <output.html>
看看哪个实现更快report 打印的比较表
与某个特定实现比较mare-mark report --baseline <id> ...
在管道中使用该命令mare-mark report - -
查看记录下来的失败会运行什么mare-mark replay <artifact.jsonl> --dry-run
再次运行该命令mare-mark replay <artifact.jsonl> --yes
记录可以重放的失败用例上的 replay 函数,它负责填写 ReplaySpec

快速上手

git clone https://github.com/Luna-Flow/mare_mark
cd mare_mark
moon run src/cli --target native -- report testdata/report/compare.jsonl report.html

输出:

report written: /path/to/mare_mark/report.html
events: 62
elapsed: 11.138ms
Comparisons
Decision threshold ±2 % and outlier policy tukey_fence (applied to the paired deltas) from the recorded protocol; run seed 42 from the record. Each row pairs the confirmatory observations of one block, needs at least 3 usable blocks, and reports a 95 % percentile bootstrap interval of the median paired delta with 10000 resamples (report defaults), seeded from the run seed, case, scale, baseline and candidate; with few blocks its actual coverage can be well below the nominal level.
case        scale  baseline  candidate  baseline µs/op  candidate µs/op  delta      95 % interval           decision    blocks used / incomplete / outliers  seed                  reason
vector-add  1024   scalar    unrolled   10.169          10.231           +0.601 %   [+0.099 %, +1.025 %]    Equivalent  7 / 0 / 1                            13588634248935341968
vector-add  1024   scalar    simd       10.14           7.091            -29.664 %  [-30.665 %, -28.754 %]  Faster      7 / 0 / 1                            2598104397583004044
vector-add  4096   scalar    unrolled   40.62           40.762           +0.594 %   [+0.099 %, +1.026 %]    Equivalent  8 / 0 / 0                            297697883029165748
vector-add  4096   scalar    simd       40.101          28.07            -29.795 %  [-30.829 %, -29.079 %]  Faster      6 / 1 / 1                            13674140354933674792

在浏览器中打开 report.html。以毫秒计的耗时会有所不同;其他一切都根据记录计算,在每台机器上都相同。

compare.jsonl 是对向量加法的三个实现在两种大小下、采用层次设计的一次运行:每种大小有一个探索性数据集和四个验证性数据集,每个数据集两个区组,记录的阈值为 2 %,离群值策略为 Tukey 围栏。从左到右阅读一行:基线和候选的中位数、以基线百分比表示的成对差值中位数、它的 95 % 自助法区间、决策,以及已用的区组数、不完整的区组数(缺少一个观测)和作为成对差值离群值被移除的区组数。simd 在两种大小下都快约 30 %;unrolled 位于 2 % 阈值之内,因此为 Equivalent,尽管它的整个区间都在零以上。决策是把点估计与阈值比较;区间说明这个估计有多稳定。

日常任务

使用管道

cat testdata/report/sample.jsonl \
  | moon run src/cli --target native -- report - - > report.html

以 - 作为输出时,HTML 是 stdout 上唯一的内容,因此它可以直接写入文件或交给另一个工具;比较表写到 stderr。加上 --quiet 可以连比较表也一起抑制。

选择基线

默认情况下,每个实现都与每个用例中第一个出现的实现比较。用 --baseline 指定另一个:

moon run src/cli --target native -- report --baseline simd testdata/report/compare.jsonl report.html

这样每一行都以 simd 为基线,符号随之翻转:scalar 和 unrolled 为 Slower。不在记录中的名称是一个错误,错误信息会列出记录中包含的实现:

mare-mark: error: unknown baseline 'avx'; implementations in the record: scalar, simd, unrolled
Check the --baseline value.

重放之前先检查失败

moon run src/cli --target native -- replay testdata/replay/sample.jsonl --dry-run
command: printf
arguments: [replayed]
timeout: 1000ms

阅读该命令。如果你信任它,就执行它:

moon run src/cli --target native -- replay testdata/replay/sample.jsonl --yes

该命令以记录的超时运行;其 stdout 会被打印出来,非零退出或超时会使 mare-mark 以 1 退出。

生成可重放的产物

运行器写出的 validation_failure 事件带有你的用例的 replay 函数返回的 ReplaySpec。请让该命令能独立复现失败,例如一个接收实现 id 和最小输入的小型工作程序。在导入了 "Luna-Flow/mare_mark/model" 的情况下:

test "a replayable failure description" {
  let replay = (input : Int, implementation : String) => {
    @model.ReplaySpec::new("my-worker", [implementation, input.to_string()], timeout_ms=2000)
  }
  let spec = replay(0, "off-by-one")
  debug_inspect(spec.arguments, content="[\"off-by-one\", \"0\"]")
}

runner 教程展示了一次产生此类事件的运行。

更进一步

  • 把报告步骤加入 CI:运行你的基准测试,写出 JSONL,然后执行 mare-mark report run.jsonl report.html,把打印的表格保留在作业日志中,并上传这两个文件。
  • 在其他目标上,该命令只支持使用文件路径的 report,并且不打印比较表。
  • 在摘要开始携带协议和种子之前写出的记录,会以 1 % 阈值、不过滤离群值和种子 0 进行比较;注释的第一行会说明这一点。

常见陷阱

  • 从 stdin 重放。 不支持;请把产物保存到文件。
  • 忘记 --yes。 没有它(也没有 --dry-run)时,replay 以 2 退出且不运行任何东西。
  • 多余的参数。 第三个位置参数是用法错误。
  • 在 --baseline 之后紧跟另一个选项。 --baseline 把下一个参数当作 id,因此 --baseline --quiet 会与一个名为 --quiet 的实现比较;请把 id 紧接在该选项之后。
  • 忘记产物。 即使使用 --dry-run,replay 也需要产物路径;没有它时以 2 退出。

后续步骤