Skip to content

Commit 27dd526

Browse files
hjeljeli32ch1bo
authored andcommitted
display CPU in the demo UI
1 parent b18db7e commit 27dd526

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,48 @@ def detect_total_memory_bytes():
326326
return None
327327
328328
329+
def detect_cpu_name():
330+
"""Return a human-readable CPU name if available."""
331+
try:
332+
if sys.platform.startswith("linux"):
333+
with open("/proc/cpuinfo", "r", encoding="utf-8") as f:
334+
for line in f:
335+
if line.lower().startswith("model name"):
336+
_, value = line.split(":", 1)
337+
return value.strip()
338+
elif sys.platform == "darwin":
339+
try:
340+
out = subprocess.check_output(
341+
["sysctl", "-n", "machdep.cpu.brand_string"],
342+
text=True,
343+
stderr=subprocess.DEVNULL
344+
).strip()
345+
if out:
346+
return out
347+
except Exception:
348+
pass
349+
out = subprocess.check_output(
350+
["sysctl", "-n", "hw.model"],
351+
text=True,
352+
stderr=subprocess.DEVNULL
353+
).strip()
354+
if out:
355+
return out
356+
elif sys.platform.startswith("win"):
357+
out = subprocess.check_output(
358+
["wmic", "cpu", "get", "Name"],
359+
text=True,
360+
stderr=subprocess.DEVNULL
361+
)
362+
for line in out.splitlines():
363+
line = line.strip()
364+
if line and line.lower() != "name":
365+
return line
366+
except Exception:
367+
return None
368+
return platform.processor() or None
369+
370+
329371
def gather_environment():
330372
uname = platform.uname()
331373
info = {
@@ -334,8 +376,11 @@ def gather_environment():
334376
"cpu_count": os.cpu_count(),
335377
}
336378
mem_bytes = detect_total_memory_bytes()
337-
if mem_bytes:
379+
if mem_bytes is not None:
338380
info["memory_bytes"] = mem_bytes
381+
cpu_name = detect_cpu_name()
382+
if cpu_name:
383+
info["cpu"] = cpu_name
339384
return {k: v for k, v in info.items() if v is not None}
340385
341386

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,6 +1228,15 @@ function applyEnvironmentInfo(environment) {
12281228
parts.push(environment.architecture);
12291229
}
12301230

1231+
if (environment.cpu) {
1232+
const cpuLabel = typeof environment.cpu === "string"
1233+
? environment.cpu.trim()
1234+
: environment.cpu;
1235+
if (cpuLabel) {
1236+
parts.push(cpuLabel);
1237+
}
1238+
}
1239+
12311240
if (environment.cpu_count !== undefined && environment.cpu_count !== null) {
12321241
const cores = Number(environment.cpu_count);
12331242
if (Number.isFinite(cores) && cores > 0) {

0 commit comments

Comments
 (0)