Setting the file. One moment.
Bench Status · Sandbox Bench · vercel/next.js · Skills Docs
ContentsBack to the top of the page 24.4
Bench Common
(opens in a new tab)
scripts/ bench-status.mjs
JavaScript · 95 lines · 3 KB
'./config.mjs'
13
14 const CONFIG = loadConfig ({ requireScope: false })
15 const E2E = path. join ( CONFIG .cacheDir, 'e2e' )
16 const all = process.argv. includes ( '--all' )
17
18 const dirs = fs. existsSync ( E2E )
19 ? fs
20 . readdirSync ( E2E )
21 . filter (( d ) => d. startsWith ( 'run-' ))
22 . map (( d ) => path. join ( E2E , d))
23 . sort (( a , b ) => fs. statSync (b).mtimeMs - fs. statSync (a).mtimeMs)
24 : []
25
26 const DAY = 24 * 3600 * 1000
27 let shown = 0
28 for ( const dir of dirs) {
29 const sf = path. join (dir, 'status.json' )
30 if ( ! fs. existsSync (sf)) continue
31 let st
32 try {
33 st = JSON . parse (fs. readFileSync (sf, 'utf8' ))
34 } catch {
35 continue
36 }
37 const fresh = fs. statSync (sf).mtimeMs > Date. now () - DAY
38 let alive = false
39 if (st.pid) {
40 try {
41 process. kill (st.pid, 0 )
42 alive = true
43 } catch {}
44 }
45 if ( ! all && ! fresh && ! alive) {
46 continue
47 }
48 const ageMin = st.updatedAt
49 ? Math. round ((Date. now () - new Date (st.updatedAt). getTime ()) / 60000 )
50 : null
51 const vms = Object. values (st.vms || {})
52 const rows = vms. reduce (( s , v ) => s + (v.rows || 0 ), 0 )
53
54 let action
55 if (st.phase === 'done' ) {
56 action = 'complete — bench-analyze.mjs re-reads it any time'
57 } else if ( String (st.phase). startsWith ( 'prepared' )) {
58 action =
59 'complete (--prepare: caches only) — launch the real run without --prepare'
60 } else if (alive) {
61 action = 'RUNNING — leave it alone'
62 } else if (
63 (rows > 0 || st.phase === 'measuring' ) &&
64 ageMin !== null &&
65 ageMin > 290
66 ) {
67 action =
68 'DEAD and its VMs have expired — whatever was collected is in the ' +
69 'run dir/results db; relaunch if more data is needed'
70 } else if (rows > 0 || st.phase === 'measuring' ) {
71 action =
72 `DEAD but VMs may still hold data — node scripts/bench-collect.mjs ${ dir }` +
73 ' (measurement VMs time out ~5h after launch; collect before that)'
74 } else {
75 action =
76 'DEAD before measurement — safe to relaunch (caches make it cheap); ' +
77 'check for leaked builder VMs with sandbox-sweep.mjs'
78 }
79
80 console. log (
81 `${ path . basename ( dir ) } \n ` +
82 ` phase=${ st . phase }` +
83 (st.error
84 ? ` error=${ JSON . stringify ( String ( st . error ). slice ( 0 , 140 )) }`
85 : '' ) +
86 ` pid=${ st . pid ?? '?'}(${ alive ? 'alive' : 'dead'})` +
87 (ageMin !== null ? ` updated=${ ageMin }m ago` : '' ) +
88 ` rows=${ rows }${ st . rowsExpected ? `/${ st . rowsExpected }` : ''} \n ` +
89 ` -> ${ action }`
90 )
91 shown ++
92 }
93 if ( ! shown) {
94 console. log ( 'no recent runs (use --all to list everything)' )
95 }