|
| 1 | +# ── Summary JSON serialization ───────────────────────────────────────────────── |
| 2 | + |
| 3 | +function _esc_json(s::String)::String |
| 4 | + replace(s, "\\" => "\\\\", "\"" => "\\\"", "\n" => "\\n") |
| 5 | +end |
| 6 | + |
| 7 | +""" |
| 8 | + write_summary(results, results_root, info) |
| 9 | +
|
| 10 | +Write a `summary.json` to `results_root` encoding run settings, tool versions, |
| 11 | +machine info, and per-model pipeline pass/fail data. |
| 12 | +Called automatically by `main()` at the end of each run. |
| 13 | +""" |
| 14 | +function write_summary( |
| 15 | + results :: Vector{ModelResult}, |
| 16 | + results_root :: String, |
| 17 | + info :: RunInfo, |
| 18 | +) |
| 19 | + path = joinpath(results_root, "summary.json") |
| 20 | + open(path, "w") do io |
| 21 | + print(io, "{\n") |
| 22 | + print(io, " \"library\": \"$(_esc_json(info.library))\",\n") |
| 23 | + print(io, " \"lib_version\": \"$(_esc_json(info.lib_version))\",\n") |
| 24 | + print(io, " \"filter\": \"$(_esc_json(info.filter))\",\n") |
| 25 | + print(io, " \"omc_exe\": \"$(_esc_json(info.omc_exe))\",\n") |
| 26 | + print(io, " \"results_root\": \"$(_esc_json(info.results_root))\",\n") |
| 27 | + print(io, " \"ref_root\": \"$(_esc_json(info.ref_root))\",\n") |
| 28 | + print(io, " \"omc_version\": \"$(_esc_json(info.omc_version))\",\n") |
| 29 | + print(io, " \"bm_version\": \"$(_esc_json(info.bm_version))\",\n") |
| 30 | + print(io, " \"cpu_model\": \"$(_esc_json(info.cpu_model))\",\n") |
| 31 | + print(io, " \"cpu_threads\": $(info.cpu_threads),\n") |
| 32 | + print(io, " \"ram_gb\": $(@sprintf "%.2f" info.ram_gb),\n") |
| 33 | + print(io, " \"total_time_s\": $(@sprintf "%.2f" info.total_time_s),\n") |
| 34 | + print(io, " \"models\": [\n") |
| 35 | + for (i, r) in enumerate(results) |
| 36 | + sep = i < length(results) ? "," : "" |
| 37 | + print(io, |
| 38 | + " {\"name\":\"$(_esc_json(r.name))\"," * |
| 39 | + "\"export\":$(r.export_success)," * |
| 40 | + "\"parse\":$(r.parse_success)," * |
| 41 | + "\"sim\":$(r.sim_success)," * |
| 42 | + "\"cmp_total\":$(r.cmp_total)," * |
| 43 | + "\"cmp_pass\":$(r.cmp_pass)}$sep\n") |
| 44 | + end |
| 45 | + print(io, " ]\n}\n") |
| 46 | + end |
| 47 | + @info "summary.json written to $results_root" |
| 48 | +end |
| 49 | + |
| 50 | +# ── Summary type and JSON loading ────────────────────────────────────────────── |
| 51 | + |
| 52 | +""" |
| 53 | + RunSummary |
| 54 | +
|
| 55 | +Parsed contents of a single `summary.json` file. |
| 56 | +
|
| 57 | +# Fields |
| 58 | +- `library` — Modelica library name (e.g. `"Modelica"`) |
| 59 | +- `lib_version` — library version (e.g. `"4.1.0"`) |
| 60 | +- `filter` — model name filter regex, or `""` when none was given |
| 61 | +- `omc_exe` — path / command used to launch OMC |
| 62 | +- `results_root` — absolute path where results were written |
| 63 | +- `ref_root` — absolute path to reference results, or `""` when unused |
| 64 | +- `omc_version` — OMC version string |
| 65 | +- `bm_version` — BaseModelica.jl version string (e.g. `"1.6.0"`) |
| 66 | +- `cpu_model` — CPU model name |
| 67 | +- `cpu_threads` — number of logical CPU threads |
| 68 | +- `ram_gb` — total system RAM in GiB |
| 69 | +- `total_time_s` — wall-clock duration of the full test run in seconds |
| 70 | +- `models` — vector of per-model dicts; each has keys |
| 71 | + `"name"`, `"export"`, `"parse"`, `"sim"`, `"cmp_total"`, `"cmp_pass"` |
| 72 | +""" |
| 73 | +struct RunSummary |
| 74 | + library :: String |
| 75 | + lib_version :: String |
| 76 | + filter :: String |
| 77 | + omc_exe :: String |
| 78 | + results_root :: String |
| 79 | + ref_root :: String |
| 80 | + omc_version :: String |
| 81 | + bm_version :: String |
| 82 | + cpu_model :: String |
| 83 | + cpu_threads :: Int |
| 84 | + ram_gb :: Float64 |
| 85 | + total_time_s :: Float64 |
| 86 | + models :: Vector{Dict{String,Any}} |
| 87 | +end |
| 88 | + |
| 89 | +""" |
| 90 | + load_summary(results_root) → RunSummary or nothing |
| 91 | +
|
| 92 | +Read and parse the `summary.json` written by `write_summary` from `results_root`. |
| 93 | +Returns `nothing` if the file does not exist or cannot be parsed. |
| 94 | +""" |
| 95 | +function load_summary(results_root::String)::Union{RunSummary,Nothing} |
| 96 | + path = joinpath(results_root, "summary.json") |
| 97 | + isfile(path) || return nothing |
| 98 | + txt = read(path, String) |
| 99 | + |
| 100 | + _str(key) = begin |
| 101 | + m = match(Regex("\"$(key)\"\\s*:\\s*\"([^\"]*)\""), txt) |
| 102 | + m === nothing ? "" : string(m.captures[1]) |
| 103 | + end |
| 104 | + _int(key) = begin |
| 105 | + m = match(Regex("\"$(key)\"\\s*:\\s*(\\d+)"), txt) |
| 106 | + m === nothing ? 0 : parse(Int, m.captures[1]) |
| 107 | + end |
| 108 | + _float(key) = begin |
| 109 | + m = match(Regex("\"$(key)\"\\s*:\\s*([\\d.]+)"), txt) |
| 110 | + m === nothing ? 0.0 : parse(Float64, m.captures[1]) |
| 111 | + end |
| 112 | + |
| 113 | + models = Dict{String,Any}[] |
| 114 | + for m in eachmatch( |
| 115 | + r"\{\"name\":\"([^\"]*)\",\"export\":(true|false),\"parse\":(true|false),\"sim\":(true|false),\"cmp_total\":(\d+),\"cmp_pass\":(\d+)\}", |
| 116 | + txt) |
| 117 | + push!(models, Dict{String,Any}( |
| 118 | + "name" => string(m.captures[1]), |
| 119 | + "export" => m.captures[2] == "true", |
| 120 | + "parse" => m.captures[3] == "true", |
| 121 | + "sim" => m.captures[4] == "true", |
| 122 | + "cmp_total" => parse(Int, m.captures[5]), |
| 123 | + "cmp_pass" => parse(Int, m.captures[6]), |
| 124 | + )) |
| 125 | + end |
| 126 | + return RunSummary( |
| 127 | + _str("library"), |
| 128 | + _str("lib_version"), |
| 129 | + _str("filter"), |
| 130 | + _str("omc_exe"), |
| 131 | + _str("results_root"), |
| 132 | + _str("ref_root"), |
| 133 | + _str("omc_version"), |
| 134 | + _str("bm_version"), |
| 135 | + _str("cpu_model"), |
| 136 | + _int("cpu_threads"), |
| 137 | + _float("ram_gb"), |
| 138 | + _float("total_time_s"), |
| 139 | + models, |
| 140 | + ) |
| 141 | +end |
0 commit comments