Skip to content

Commit 78dd6b8

Browse files
committed
display environment information in the UI
1 parent a4468d2 commit 78dd6b8

File tree

4 files changed

+138
-4
lines changed

4 files changed

+138
-4
lines changed

crypto-benchmarks.rs/demo/scripts/60_export_demo_json.sh

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ PY="${PY:-python3}"
2525

2626
pushd "$RUN_DIR" >/dev/null
2727
"$PY" - <<'PY'
28-
import os, json, collections
28+
import json
29+
import os
30+
import platform
31+
import subprocess
32+
import sys
2933
try:
3034
import cbor2
3135
except ImportError:
@@ -289,6 +293,54 @@ params = {
289293
"quorum_fraction": quorum_fraction, # may be None if not recorded
290294
}
291295
296+
297+
def detect_total_memory_bytes():
298+
"""Attempt to detect total physical memory without external dependencies."""
299+
try:
300+
if sys.platform.startswith("linux"):
301+
with open("/proc/meminfo", "r", encoding="utf-8") as f:
302+
for line in f:
303+
if line.startswith("MemTotal:"):
304+
parts = line.split()
305+
if len(parts) >= 2:
306+
# Value reported in kB
307+
return int(float(parts[1]) * 1024)
308+
elif sys.platform == "darwin":
309+
out = subprocess.check_output(
310+
["sysctl", "-n", "hw.memsize"], text=True, stderr=subprocess.DEVNULL
311+
).strip()
312+
if out:
313+
return int(out)
314+
elif sys.platform.startswith("win"):
315+
out = subprocess.check_output(
316+
["wmic", "ComputerSystem", "get", "TotalPhysicalMemory"],
317+
text=True,
318+
stderr=subprocess.DEVNULL
319+
)
320+
for line in out.splitlines():
321+
line = line.strip()
322+
if line.isdigit():
323+
return int(line)
324+
except Exception:
325+
return None
326+
return None
327+
328+
329+
def gather_environment():
330+
uname = platform.uname()
331+
info = {
332+
"os": f"{uname.system} {uname.release}".strip(),
333+
"architecture": uname.machine or None,
334+
"cpu_count": os.cpu_count(),
335+
}
336+
mem_bytes = detect_total_memory_bytes()
337+
if mem_bytes:
338+
info["memory_bytes"] = mem_bytes
339+
return {k: v for k, v in info.items() if v is not None}
340+
341+
342+
environment = gather_environment()
343+
292344
out = {
293345
"params": params,
294346
"universe": universe,
@@ -308,7 +360,10 @@ out = {
308360
"votes_preview": votes_preview,
309361
}
310362
363+
if environment:
364+
out["environment"] = environment
365+
311366
json.dump(out, open("demo.json", "w"), indent=2)
312367
print("Wrote demo.json")
313368
PY
314-
popd >/dev/null
369+
popd >/dev/null

crypto-benchmarks.rs/demo/ui/static/app.js

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,7 +1153,7 @@ async function loadTimingsForRun(runDir) {
11531153
setText("verify_time", "—");
11541154
setText("verify_status", "—");
11551155
applyVerificationStatus(null);
1156-
return;
1156+
return null;
11571157
}
11581158
const timings = await tryFetchJson(`/demo/${runDir}/timings.json`);
11591159
if (timings && typeof timings === "object") {
@@ -1190,6 +1190,7 @@ async function loadTimingsForRun(runDir) {
11901190
setText("verify_time", "—");
11911191
applyVerificationStatus(null);
11921192
}
1193+
return timings ?? null;
11931194
}
11941195

11951196
function fillIdentifiers(obj) {
@@ -1204,6 +1205,53 @@ function fillIdentifiers(obj) {
12041205
}
12051206
}
12061207

1208+
function applyEnvironmentInfo(environment) {
1209+
const container = document.getElementById("demo_meta");
1210+
const summaryEl = document.getElementById("machine_summary");
1211+
1212+
if (!container || !summaryEl) return;
1213+
1214+
const hasEnvironment = environment && typeof environment === "object";
1215+
1216+
if (!hasEnvironment) {
1217+
summaryEl.textContent = "—";
1218+
container.hidden = true;
1219+
return;
1220+
}
1221+
1222+
const parts = [];
1223+
if (environment.os && environment.architecture) {
1224+
parts.push(`${environment.os} (${environment.architecture})`);
1225+
} else if (environment.os) {
1226+
parts.push(environment.os);
1227+
} else if (environment.architecture) {
1228+
parts.push(environment.architecture);
1229+
}
1230+
1231+
if (environment.cpu_count !== undefined && environment.cpu_count !== null) {
1232+
const cores = Number(environment.cpu_count);
1233+
if (Number.isFinite(cores) && cores > 0) {
1234+
parts.push(`${cores} ${cores === 1 ? "core" : "cores"}`);
1235+
}
1236+
}
1237+
1238+
if (environment.memory_bytes !== undefined && environment.memory_bytes !== null) {
1239+
const memoryBytes = Number(environment.memory_bytes);
1240+
if (Number.isFinite(memoryBytes) && memoryBytes > 0) {
1241+
parts.push(`${formatBytes(memoryBytes)} RAM`);
1242+
}
1243+
}
1244+
1245+
if (!parts.length) {
1246+
summaryEl.textContent = "—";
1247+
container.hidden = true;
1248+
return;
1249+
}
1250+
1251+
summaryEl.textContent = parts.join(" • ");
1252+
container.hidden = false;
1253+
}
1254+
12071255
const FLOW_STEPS = [
12081256
{
12091257
wrapperId: "step_committee",
@@ -1313,6 +1361,9 @@ function clearUIPlaceholders() {
13131361
setText('agg_votes_size', '—');
13141362
setText('agg_cert_size', '—');
13151363
setText('agg_gain', '—');
1364+
setText("machine_summary", "—");
1365+
const metaEl = document.getElementById("demo_meta");
1366+
if (metaEl) metaEl.hidden = true;
13161367
// Clear main panels
13171368
const clearIds = ["universe_canvas", "committee_canvas", "voters_canvas", "aggregation_canvas"];
13181369
for (const id of clearIds) {
@@ -1342,8 +1393,9 @@ async function loadAndRenderRun(runDir) {
13421393
renderCommitteeFromDemo(demo);
13431394
renderVotersFromDemo(demo);
13441395
renderAggregationFromDemo(demo);
1396+
applyEnvironmentInfo(demo?.environment ?? null);
13451397
applyVerificationStatus(demo?.verification?.status ?? demo?.verification_status ?? null);
1346-
await loadTimingsForRun(runDir);
1398+
const timings = await loadTimingsForRun(runDir);
13471399
syncGridColumns();
13481400
window.addEventListener("resize", syncGridColumns);
13491401
} else {

crypto-benchmarks.rs/demo/ui/static/styles.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ a {
4949
text-align: center;
5050
}
5151

52+
.app-meta {
53+
display: flex;
54+
flex-wrap: wrap;
55+
gap: 0.5rem;
56+
align-items: center;
57+
justify-content: center;
58+
font-size: 16px;
59+
color: var(--muted);
60+
}
61+
62+
.app-meta__line {
63+
display: flex;
64+
gap: 0.35rem;
65+
align-items: center;
66+
}
67+
68+
.app-meta__line strong {
69+
color: var(--text);
70+
font-weight: 600;
71+
}
72+
5273
.app-title {
5374
margin: 0;
5475
font-size: 28px;

crypto-benchmarks.rs/demo/ui/templates/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ <h1 class="app-title">Leios Voting Demo</h1>
1717
<input id="run-input" name="run" type="text" placeholder="e.g., run64" />
1818
<button type="submit">Load</button>
1919
</form>
20+
<div id="demo_meta" class="app-meta" hidden>
21+
<span class="app-meta__line">
22+
<strong>Environment:</strong>
23+
<span id="machine_summary"></span>
24+
</span>
25+
</div>
2026
</header>
2127

2228
<main>

0 commit comments

Comments
 (0)