cadet.metrics

Per-frame metric collection for the braking experiment.

What this is for:

Collects one record per transmitted frame and writes a CSV compatible with the original *_latency_location_log.csv so existing analysis scripts keep working. New columns are appended at the end only.

What it contains:
  • ORIGINAL_COLUMNS / NEW_COLUMNS and the combined field order.

  • MetricsLog: accumulate records, mark brake/stop, write CSV, and compute a summary (brake-engage/stop time+location, frames sent, median brake-reaction latency).

How it fits into CADET:

The braking client app (cadet.apps.braking) owns a MetricsLog, adds a record per frame sent, and finalises it on stop. The runtime never writes results into curated dirs; paths come from the resolved config’s outputs section.

How to configure it:

Construct with the output CSV path and the run_id/rep; those populate the appended columns.

class cadet.metrics.frame_log.MetricsLog(csv_path, run_id, rep)

Bases: object

Accumulates per-frame records and derives braking summary metrics.

Parameters:
  • csv_path (str)

  • run_id (str)

  • rep (int)

new_frame(frame_id, capture_time, capture_loc, speed_mph)

Start a record for a captured/sent frame.

Return type:

None

Parameters:
  • frame_id (int)

  • capture_time (float)

  • speed_mph (float)

mark_sent(frame_id, send_time, send_loc)

Record when/where a frame was sent.

Return type:

None

Parameters:
  • frame_id (int)

  • send_time (float)

mark_brake(frame_id, server_proc_time, response_time, response_loc, recv_wall=None)

Record the brake-triggering frame’s response fields and summary.

response_time is sim-time (seconds since start) and populates the original server_response_receive_time column. recv_wall is the wall-clock time the reply was processed; brake_reaction_latency_s is the wall-clock round trip recv_wall - frame_capture_time for the brake-triggering frame (both wall-clock, unlike the original which mixed clocks). See docs/e2e_latency.md for why it is ~1.4 s.

Return type:

None

Parameters:
  • frame_id (int)

  • response_time (float)

mark_stop(stop_time, stop_loc)

Record the full-stop time/location against braked frames.

Return type:

None

Parameters:

stop_time (float)

write()

Write all records to the CSV at csv_path.

Return type:

None

frames_sent()

Number of frames that were actually transmitted.

Return type:

int

median_brake_reaction_s()

Median brake-reaction latency (one sample here), or None.

Return type:

Optional[float]

summary()

Return the headline metrics for reporting/parity.

Return type:

Dict[str, Any]

What this is for:

The three link backends realise a configuration in different ways, and the gap between “configured 60 ms” and “the application saw X ms” is the thing an experiment needs to be able to inspect. Every run therefore writes both: the link parameters as configured, and the effective per-message latency and unanswered counts as measured. Without this the gap is invisible in outputs and has to be reconstructed by hand from logs.

What it contains:
  • MessageStats: what a client role observed (sent, received, and the per-message latencies in milliseconds).

  • link_summary(): a link’s configuration, flattened for the record.

  • write_link_report(): writes link_report.json into a run’s output directory and returns the structure it wrote.

How it fits into CADET:

ClientRuntime calls write_link_report() after the app finishes, for any app that exposes message_stats(). The file sits beside the per-frame CSV and the run marker.

Latency here is message latency: the time from handing a payload to the transport until its reply is taken off the wire. It is deliberately recorded at reply arrival rather than when the application next looks, because a polling loop would otherwise fold its own tick interval into the number.

A route is recorded the same way, with one addition: a composed path has no observable hop (one connection, one timestamp pair), so the record states each hop’s configured percentiles and the end-to-end composition, and the measured half stays what it was - what the application saw end to end. The composed p50 and p99 are the sums of the hops’, which is the intent rather than a prediction: delays add, but a sum of independent samples has a narrower tail than the sum of their p99s, so the composed p99 is an upper bound. Per-hop measurement is a property of realise: relay, where each hop is a real connection.

How to configure it:

Nothing to configure. The configured half comes from config.links and config.routes; the measured half from the app.

Return the link-report file name for a client node.

Return type:

str

Bases: object

What a client observed at the message level over one run.

Parameters:
  • sent (int)

  • received (int)

  • latencies_ms (List[float] | None)

  • reply_policy (str)

Messages sent that never got a reply.

Unanswered share, or None when the app does not answer every message.

Returning a percentage for an on-event app would invite reading it as a loss rate, which it is not.

Return the pct percentile latency in ms, or None with no samples.

Return type:

Optional[float]

Parameters:

pct (float)

Return type:

Dict[str, object]

Flatten one configured link into the record.

semantics states what the numbers mean for the chosen backend, because the same delay and loss fields are realised at different layers: delay perturbs application messages, while netem and netwaggle perturb packets and let the transport react.

Return type:

Dict[str, object]

Flatten one configured route into the record, hop by hop.

end_to_end is the composition of the hops that act on each direction: the delay percentiles add, the loss is the chance of surviving every hop, and the bandwidth is the slowest hop’s, because hops in series are a pipeline whose bottleneck sets the rate.

Return type:

Dict[str, object]

Write link_report_<node>.json for one client and return its content.

Return type:

Dict[str, object]

Parameters: