ir_sink tutorial

This short tutorial wires a benchmark’s events into both memory and a JSONL record using the ir_sink shorthand.

Quick start

moon add Luna-Flow/mare_mark@0.3.0
import {
  "Luna-Flow/mare_mark/model",
  "Luna-Flow/mare_mark/ir_sink",
}
test "memory and record in one sink" {
  let memory = @ir_sink.in_memory()
  let record = @ir_sink.jsonl()
  let sink = @ir_sink.tee(memory.as_sink(), record.as_sink())
  (sink.emit_validation)(@model.Validation::new(Valid, "reference", "loop", "1024"))
  inspect(memory.validations.length(), content="1")
  inspect(record.to_jsonl().contains("\"status\":\"valid\""), content="true")
}

Everyday tasks

Stream to a writer

test "stream" {
  let lines : Array[String] = []
  let sink = @ir_sink.jsonl_stream(line => lines.push(line), "stdout")
  (sink.emit_validation)(@model.Validation::new(Unsupported("no NaN support"), "reference", "fast", "8"))
  inspect(lines[0].contains("\"status\":\"unsupported\""), content="true")
}

Pass the sink to @runner.RunContext::new; the runner tutorial shows a complete run.

Going further

Everything returned here is an @event type; see the event tutorial for custom sinks and the record format.

Common pitfalls

  • Mixing ir_sink and event values. Works, because they are the same types; there is nothing to convert.

Next steps