{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "urn:ledgermath:events:1",
  "title": "Event",
  "description": "One line of a benchmark's stdout. A benchmark prints a stream of these, one JSON object per line, and nothing else on stdout. The six universal events below have exactly the fields listed. A benchmark may also emit events of its own, under any other name, with any fields beside `event` and `t`. A schema of one line cannot hold the stream's order, which is a rule of its own: started first and once, and in a stream that is recorded without quick: true; finished last and once; samples numbered from 0 in order, each starting only when none is open and at a t no earlier than the previous sample's sample_ended; every sample_ended closing the open sample, of the same number, at a t no earlier than its start, and every sample closed; each observed key once; exactly one verified; and at least one sample whose warmup is false.",
  "type": "object",
  "required": ["event", "t"],
  "properties": {
    "event": { "description": "The event's name: one of the six universal events, started, observed, sample_started, sample_ended, verified and finished, whose fields are fixed; or a benchmark's own, under any other name.", "type": "string", "minLength": 1 },
    "t": {
      "description": "Whole nanoseconds on the clock that `started` names.",
      "type": "integer",
      "minimum": 0
    }
  },
  "allOf": [
    {
      "if": { "properties": { "event": { "const": "started" } } },
      "then": {
        "description": "Always first.",
        "required": ["schema", "wall_utc", "clock", "clock_read_ns"],
        "properties": {
          "event": true,
          "t": true,
          "schema": { "description": "Which version of the stream's shape the binary prints.", "const": "ledgermath.events/1" },
          "wall_utc": {
            "description": "The wall clock read straight after `t`, to the nanosecond.",
            "type": "string",
            "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}\\.[0-9]{9}Z$"
          },
          "clock": { "description": "The clock every `t` is read from.", "type": "string", "minLength": 1 },
          "clock_read_ns": {
            "description": "The median cost of one clock read, measured at startup.",
            "type": "number",
            "minimum": 0
          },
          "quick": {
            "description": "True for a developer's trial stream, from the binary's quick mode. The scheduled box never asks for quick mode; a runner told to run quick passes it on and still writes the Run, but no Method counts a Run whose stream says quick: true.",
            "type": "boolean"
          }
        },
        "additionalProperties": false
      }
    },
    {
      "if": { "properties": { "event": { "const": "observed" } } },
      "then": {
        "description": "What the program observed about its own work. May appear more than once; each key appears once across all of them.",
        "required": ["values"],
        "properties": {
          "event": true,
          "t": true,
          "values": { "description": "What the benchmark observed of its own run, by key, as the benchmark documents them: the counterparts of its parameters, and whatever else it records of the run (http_get's include the cost of a clock read, how many responses had each status, how many lines it withheld, and why it ended early). Never a value merely read back from its environment. bytes_per_repetition, when present, is what bytes per second are derived from.", "type": "object" }
        },
        "additionalProperties": false
      }
    },
    {
      "if": { "properties": { "event": { "const": "sample_started" } } },
      "then": {
        "description": "The start edge of one sample. Samples are numbered from 0 and never overlap.",
        "required": ["sample", "warmup", "repetitions"],
        "properties": {
          "event": true,
          "t": true,
          "sample": { "description": "The sample's number: from 0, in stream order.", "type": "integer", "minimum": 0 },
          "warmup": { "description": "True for a warmup sample: printed and tagged, never dropped, and not a counted sample, so neither one of the LM_SAMPLES samples the stream must hold nor among the samples a Method takes times from. A benchmark's own counts in its observed values may include it: http_get's requests_made does.", "type": "boolean" },
          "repetitions": { "description": "How many repetitions of the measured work lie between the sample's two edges, 1 or more.", "type": "integer", "minimum": 1 }
        },
        "additionalProperties": false
      }
    },
    {
      "if": { "properties": { "event": { "const": "sample_ended" } } },
      "then": {
        "description": "The end edge of the sample with the same number.",
        "required": ["sample"],
        "properties": {
          "event": true,
          "t": true,
          "sample": { "description": "The number of the sample it closes: the open one.", "type": "integer", "minimum": 0 }
        },
        "additionalProperties": false
      }
    },
    {
      "if": { "properties": { "event": { "const": "verified" } } },
      "then": {
        "description": "A value derived from the data the measured work processed.",
        "required": ["checksum"],
        "properties": {
          "event": true,
          "t": true,
          "checksum": { "description": "The value, 0x and sixteen lower-case hex digits: derived from the data the measured work processed, so that a compiler cannot delete the work.", "type": "string", "pattern": "^0x[0-9a-f]{16}$" }
        },
        "additionalProperties": false
      }
    },
    {
      "if": { "properties": { "event": { "const": "finished" } } },
      "then": {
        "description": "Always last. Its absence is evidence of a crash.",
        "properties": { "event": true, "t": true },
        "additionalProperties": false
      }
    }
  ]
}
