Skip to main content

qualia_core_db/inference/inference_bench/
reporting.rs

1//! Result-set serializers for the harness output: pretty JSON, CSV (header +
2//! one row per result), and a human-readable stdout table. Pure code motion —
3//! behaviour unchanged.
4
5use super::*;
6
7// ── Reporting ─────────────────────────────────────────────────────────────────
8
9/// Pretty-printed JSON for a result set.
10pub fn results_to_json(results: &[BenchResult]) -> String {
11    serde_json::to_string_pretty(results).unwrap_or_else(|e| format!("{{\"error\":\"{e}\"}}"))
12}
13
14/// CSV (header + one row per result).
15pub fn results_to_csv(results: &[BenchResult]) -> String {
16    let mut s = String::new();
17    s.push_str(
18        "label,quantization,n_layer,mapped_bytes,prompt_tokens,output_tokens,\
19cold_ttft_ms,cold_total_ms,warm_ttft_ms,warm_total_ms,\
20load_ms,prefill_ms,prefill_tok_s,decode_ms,decode_tok_s,directml,gpu_ts,\
21gpu_adapter,gpu_backend,gpu_device_type,gpu_adapter_features,gpu_enabled_features\n",
22    );
23    for r in results {
24        s.push_str(&format!(
25            "{},{},{},{},{},{},{:.3},{:.3},{:.3},{:.3},{:.3},{:.3},{:.2},{:.3},{:.2},{},{},{},{},{},{},{}\n",
26            r.label.replace(',', " "),
27            r.quantization,
28            r.model.n_layer,
29            r.model.mapped_bytes,
30            r.prompt_tokens,
31            r.output_tokens,
32            r.cold_ttft_ms,
33            r.cold_total_ms,
34            r.warm_ttft_ms,
35            r.warm_total_ms,
36            r.load_ms,
37            r.prefill_ms,
38            r.prefill_tok_s,
39            r.decode_ms,
40            r.decode_tok_s,
41            r.model.directml_enabled,
42            r.gpu_timestamp_supported,
43            r.gpu.adapter.replace(',', " "),
44            r.gpu.backend,
45            r.gpu.device_type,
46            r.gpu.adapter_feature_flags.replace(',', " "),
47            r.gpu.enabled_feature_flags.replace(',', " "),
48        ));
49    }
50    s
51}
52
53/// Human-readable table for stdout.
54pub fn results_to_table(results: &[BenchResult]) -> String {
55    let mut s = String::new();
56    s.push_str(&format!(
57        "{:<22} {:>6} {:>10} {:>10} {:>10} {:>11} {:>11}\n",
58        "model", "layers", "coldTTFT", "warmTTFT", "prefill/s", "decode/s", "decode_ms"
59    ));
60    s.push_str(&"-".repeat(86));
61    s.push('\n');
62    for r in results {
63        s.push_str(&format!(
64            "{:<22} {:>6} {:>9.0}m {:>9.0}m {:>10.1} {:>11.2} {:>10.1}\n",
65            r.label,
66            r.model.n_layer,
67            r.cold_ttft_ms,
68            r.warm_ttft_ms,
69            r.prefill_tok_s,
70            r.decode_tok_s,
71            r.decode_ms,
72        ));
73    }
74    s
75}