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.csvso existing analysis scripts keep working. New columns are appended at the end only.- What it contains:
ORIGINAL_COLUMNS/NEW_COLUMNSand 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 aMetricsLog, 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’soutputssection.- 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:
objectAccumulates 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_timeis sim-time (seconds since start) and populates the originalserver_response_receive_timecolumn.recv_wallis the wall-clock time the reply was processed;brake_reaction_latency_sis the wall-clock round triprecv_wall - frame_capture_timefor 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]
Per-run record of what a link was configured to do and what it actually did.
- 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(): writeslink_report.jsoninto a run’s output directory and returns the structure it wrote.
- How it fits into CADET:
ClientRuntimecallswrite_link_report()after the app finishes, for any app that exposesmessage_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.linksandconfig.routes; the measured half from the app.
- cadet.metrics.link_report.report_name(node_name)¶
Return the link-report file name for a client node.
- Return type:
str
- class cadet.metrics.link_report.MessageStats(sent, received, latencies_ms=None, reply_policy='per-message')¶
Bases:
objectWhat a client observed at the message level over one run.
- Parameters:
sent (int)
received (int)
latencies_ms (List[float] | None)
reply_policy (str)
- property unanswered: int¶
Messages sent that never got a reply.
- property unanswered_pct: float | None¶
Unanswered share, or None when the app does not answer every message.
Returning a percentage for an
on-eventapp would invite reading it as a loss rate, which it is not.
- percentile(pct)¶
Return the
pctpercentile latency in ms, or None with no samples.- Return type:
Optional[float]- Parameters:
pct (float)
- as_dict()¶
- Return type:
Dict[str,object]
- cadet.metrics.link_report.link_summary(link)¶
Flatten one configured link into the record.
semanticsstates what the numbers mean for the chosen backend, because the samedelayandlossfields are realised at different layers:delayperturbs application messages, whilenetemandnetwaggleperturb packets and let the transport react.- Return type:
Dict[str,object]
- cadet.metrics.link_report.route_summary(config, route)¶
Flatten one configured route into the record, hop by hop.
end_to_endis 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]
- cadet.metrics.link_report.write_link_report(config, out_dir, stats, node_name='client')¶
Write
link_report_<node>.jsonfor one client and return its content.- Return type:
Dict[str,object]- Parameters:
out_dir (str)
stats (MessageStats)
node_name (str)