summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/profile-multiworld.sh80
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/profile-multiworld.sh b/scripts/profile-multiworld.sh
new file mode 100755
index 0000000..3ab099d
--- /dev/null
+++ b/scripts/profile-multiworld.sh
@@ -0,0 +1,80 @@
+#!/usr/bin/env bash
+# P59 多世界并存后台压测 MasterProcess(systemd --user transient unit 的 ExecStart)。
+#
+# 职责:
+# * 在 <PMW_DIR> 落 state.json(pid/unit/log/commit/参数/起止/exit);
+# * 以 2>&1 运行 Headless `--profile-multiworld N D npcs sampleEvery seedBase`,
+# 逐采样行流式打印并 flush;
+# * 退出时写回 ended_at/exit,并回传真实退出码。
+#
+# 环境变量(由 unit/transient 属性注入):
+# PMW_REPO / PMW_DIR / PMW_COMMIT / PMW_LOG
+# PMW_WORLDS(默认 10)/ PMW_DAYS(默认 20)/ PMW_NPCS(默认 30)
+# PMW_SAMPLE_EVERY(默认 2)/ PMW_SEED_BASE(默认 42)
+set -u
+
+REPO="${PMW_REPO:?PMW_REPO required}"
+DIR="${PMW_DIR:?PMW_DIR required}"
+COMMIT="${PMW_COMMIT:?PMW_COMMIT required}"
+WORLDS="${PMW_WORLDS:-10}"
+DAYS="${PMW_DAYS:-20}"
+NPCS="${PMW_NPCS:-30}"
+SAMPLE_EVERY="${PMW_SAMPLE_EVERY:-2}"
+SEED_BASE="${PMW_SEED_BASE:-42}"
+LOG="${PMW_LOG:-$REPO/artifacts/perf-multiworld/latest/acceptance.log}"
+UNIT="living-village-multiworld.service"
+DLL="$REPO/src/LivingVillage.Headless/bin/Release/net8.0/LivingVillage.Headless.dll"
+
+mkdir -p "$DIR"
+if [ ! -f "$DLL" ]; then
+ echo "[pmw] FATAL missing build: $DLL" >&2
+ exit 90
+fi
+
+STARTED="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
+echo "$$" > "$DIR/pid"
+echo "[pmw] start unit=$UNIT pid=$$ commit=$COMMIT worlds=$WORLDS days=$DAYS npcs=$NPCS sample_every=$SAMPLE_EVERY seed_base=$SEED_BASE started_at=$STARTED"
+
+python3 - "$DIR/state.json" "$UNIT" "$COMMIT" "$WORLDS" "$DAYS" "$NPCS" "$SAMPLE_EVERY" "$SEED_BASE" "$LOG" "$STARTED" "$$" <<'PY'
+import json, sys
+out, unit, commit, worlds, days, npcs, sample, seed, log, started, pid = sys.argv[1:12]
+state = {
+ "pid": int(pid),
+ "unit": unit,
+ "log": log,
+ "commit": commit,
+ "params": {
+ "worlds": int(worlds),
+ "days": int(days),
+ "npcs": int(npcs),
+ "sample_every_days": int(sample),
+ "seed_base": int(seed),
+ },
+ "started_at": started,
+ "ended_at": None,
+ "exit": None,
+}
+with open(out, "w", encoding="utf-8") as fh:
+ json.dump(state, fh, ensure_ascii=False, indent=2, sort_keys=True)
+ fh.write("\n")
+PY
+
+( exec dotnet "$DLL" --profile-multiworld "$WORLDS" "$DAYS" "$NPCS" "$SAMPLE_EVERY" "$SEED_BASE" 2>&1 )
+CODE=$?
+
+ENDED="$(date -u +%Y-%m-%dT%H:%M:%SZ)"
+echo "[pmw] end pid=$$ exit=$CODE ended_at=$ENDED"
+
+python3 - "$DIR/state.json" "$CODE" "$ENDED" <<'PY'
+import json, sys
+path, code, ended = sys.argv[1:4]
+with open(path, encoding="utf-8") as fh:
+ state = json.load(fh)
+state["ended_at"] = ended
+state["exit"] = int(code)
+with open(path, "w", encoding="utf-8") as fh:
+ json.dump(state, fh, ensure_ascii=False, indent=2, sort_keys=True)
+ fh.write("\n")
+PY
+
+exit "$CODE"