1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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"
|