feat: enhance memory monitoring in benchmark and simplify run script

This commit is contained in:
2026-07-26 22:15:50 -05:00
parent 990ebd988e
commit 5f2ed2c34a
3 changed files with 68 additions and 66 deletions
+22
View File
@@ -213,6 +213,28 @@
mc.innerHTML = h;
document.getElementById('results').style.display = 'block';
// Main process will inject memory via executeJavaScript every 2s
window.__updateMem = function() {
var m = window.__mainMem;
if (!m) return;
var mc = document.getElementById('mem-card');
mc.innerHTML = '';
var entries = [
['Engine', m.engine],
['Platform', m.platform + ' ' + m.arch],
['Node.js', m.node],
['RSS', m.rss + ' MB'],
['Heap used', m.heapUsed + ' MB'],
['Heap total', m.heapTotal + ' MB'],
['External', m.external + ' MB'],
['System RAM', m.totalMem + ' MB'],
];
for (var i = 0; i < entries.length; i++) {
mc.innerHTML += row(entries[i][0], entries[i][1]);
}
};
window.__updateMem();
})();
</script>
</body>
+24
View File
@@ -1,8 +1,24 @@
const { app, BrowserWindow } = require('electron');
const path = require('path');
const os = require('os');
const isGelectron = !!(process.versions.gelectron || process.env.GELECTRON_NATIVE);
function getMemoryMB() {
const m = process.memoryUsage();
return JSON.stringify({
rss: +(m.rss / 1048576).toFixed(1),
heapUsed: +(m.heapUsed / 1048576).toFixed(1),
heapTotal: +(m.heapTotal / 1048576).toFixed(1),
external: +(m.external / 1048576).toFixed(1),
platform: os.platform(),
arch: os.arch(),
engine: isGelectron ? 'Gelectron' : 'Electron',
node: process.versions.node,
totalMem: +(os.totalmem() / 1048576).toFixed(0),
});
}
app.whenReady().then(() => {
const win = new BrowserWindow({
width: 680,
@@ -17,6 +33,14 @@ app.whenReady().then(() => {
});
win.loadFile(path.join(__dirname, 'index.html'));
setInterval(() => {
if (!win.isDestroyed()) {
win.webContents.executeJavaScript(
`window.__mainMem=${getMemoryMB()};window.__updateMem&&window.__updateMem()`
);
}
}, 2000);
});
app.on('window-all-closed', () => app.quit());
+22 -66
View File
@@ -1,79 +1,35 @@
#!/usr/bin/env bash
set -e
BENCH_DIR="$(cd "$(dirname "$0")" && pwd)"
ELECTRON_BIN="$BENCH_DIR/node_modules/.bin/electron"
GEELECTRON_BIN="$BENCH_DIR/../target/release/gelectron"
usage() {
echo ""
echo " Usage: ./benchmark/run.sh [options]"
echo ""
echo " Options:"
echo " --electron Run with Electron only"
echo " --gelectron Run with Gelectron only"
echo " (no args) Run both back-to-back"
echo ""
}
run_electron() {
if [ -x "$ELECTRON_BIN" ] || command -v electron &>/dev/null; then
local bin="${ELECTRON_BIN:-electron}"
echo ""
echo " ▶ Opening Electron benchmark…"
echo " Close the window when done."
"$bin" "$BENCH_DIR" 2>/dev/null
echo " ✓ Electron done"
else
echo ""
echo " ✗ Electron not found. Install with: npm install electron"
fi
}
run_gelectron() {
if [ -x "$GEELECTRON_BIN" ]; then
echo ""
echo " ▶ Opening Gelectron benchmark…"
echo " Close the window when done."
"$GEELECTRON_BIN" "$BENCH_DIR" 2>/dev/null
echo " ✓ Gelectron done"
elif command -v gelectron &>/dev/null; then
echo ""
echo " ▶ Opening Gelectron benchmark…"
echo " Close the window when done."
gelectron "$BENCH_DIR" 2>/dev/null
echo " ✓ Gelectron done"
else
echo ""
echo " ✗ Gelectron not found. Build with: cargo build --release"
fi
}
MODE="both"
for arg in "$@"; do
case "$arg" in
--electron) MODE="electron" ;;
--gelectron) MODE="gelectron" ;;
-h|--help) usage; exit 0 ;;
*) echo " Unknown option: $arg"; usage; exit 1 ;;
esac
done
echo ""
echo " ── Gelectron Benchmark ──"
echo ""
if [ "$MODE" = "both" ] || [ "$MODE" = "electron" ]; then
run_electron
# Run Electron first
if [ -x "$ELECTRON_BIN" ]; then
echo " ▶ Opening Electron benchmark…"
echo " Close the window when done."
"$ELECTRON_BIN" "$BENCH_DIR" 2>/dev/null || true
echo " ✓ Electron done"
else
echo " ✗ Electron not found. Run: npm install electron"
fi
if [ "$MODE" = "both" ] || [ "$MODE" = "gelectron" ]; then
run_gelectron
echo ""
# Then Gelectron
if [ -x "$GEELECTRON_BIN" ]; then
echo " ▶ Opening Gelectron benchmark…"
echo " Close the window when done."
"$GEELECTRON_BIN" "$BENCH_DIR" 2>/dev/null || true
echo " ✓ Gelectron done"
else
echo " ✗ Gelectron not found. Run: cargo build --release"
fi
if [ "$MODE" = "both" ]; then
echo ""
echo " ── Done ──"
echo " Both benchmarks ran. Results are shown in each window."
echo " The second window auto-loads a comparison if result files exist."
echo ""
fi
echo ""
echo " ── Done ──"
echo ""