Setting the file. One moment.
Bench Analyze · 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-analyze.mjs
JavaScript · 93 lines · 3 KB
argv
=
process.argv.
slice
(
2
)
12 const target = argv. find (( a ) => ! a. startsWith ( '--' ))
13 const get = ( name ) => {
14 const i = argv. indexOf (name)
15 return i >= 0 ? argv[i + 1 ] : undefined
16 }
17 if ( ! target) {
18 console. error (
19 'usage: node bench-analyze.mjs <runDir|runId> [--base arm] [--cand arm]'
20 )
21 process. exit ( 1 )
22 }
23 const db = openDb ()
24 let runId
25 if (fs. existsSync (target)) {
26 runId = importRun (db, target).runId
27 } else {
28 runId = path. basename (target)
29 }
30 const { failures , notes } = verify (db, runId)
31 for ( const n of notes) console. log ( `note: ${ n }` )
32 if (failures. length ) {
33 console. error ( `RESULTS DB VERIFY FAILED: \n ${ failures . join ( ' \n ' ) }` )
34 process. exit ( 1 )
35 }
36 const rows = loadRows (db, runId)
37 const arms = [ ...new Set (rows. map (( r ) => r.arm))]
38 if (arms. length !== 2 ) {
39 console. error ( `expected exactly 2 arms, found: ${ arms . join ( ', ' ) }` )
40 process. exit ( 1 )
41 }
42 // Which arm is base? Row order cannot answer this (ABBA runs the
43 // candidate first), so require an explicit source: the run's meta,
44 // a conventional name, or the --base flag.
45 const meta = runMeta (db, runId)?.meta
46 const base =
47 get ( '--base' ) ??
48 (meta && arms. includes (meta.base) ? meta.base : undefined ) ??
49 [ 'base' , 'synced' ]. find (( n ) => arms. includes (n))
50 if ( ! base) {
51 console. error (
52 `cannot determine the base arm from {${ arms . join ( ', ' ) }}: ` +
53 'no meta, no arm named "base"/"synced" — pass --base <arm>'
54 )
55 process. exit ( 1 )
56 }
57 const cand = get ( '--cand' ) ?? arms. find (( a ) => a !== base)
58 const boots = new Set (rows. map (( r ) => r.vm)).size
59 console. log ( `${ runId } boots=${ boots } arms: ${ base } (base) vs ${ cand }` )
60 if (meta?.pr)
61 console. log (
62 `PR: ${ meta . pr . title ? `"${ meta . pr . title }" — ` : ''}${ meta . pr . url }`
63 )
64 for ( const a of meta?.arms ?? [])
65 if (a.title) console. log ( ` ${ a . name }: "${ a . title }"` )
66 if (rows[ 0 ].route === '' ) {
67 // Micro (sandbox-ab) samples: phase holds the payload name.
68 analyzeE2eRows (rows, base, cand, [ 'mean' , 'p50' , 'p95' , 'p99' , 'gcMs' ])
69 } else if (meta?.suite === 'ssr' ) {
70 analyzeE2eRows (rows, base, cand, [
71 'rps' ,
72 'mean' ,
73 'median' ,
74 'p95' ,
75 'p99' ,
76 'gcMs' ,
77 'heapMb' ,
78 ])
79 } else {
80 // No p99 for e2e: the load phases are far too small for it.
81 analyzeE2eRows (rows, base, cand, [
82 'rps' ,
83 'median' ,
84 'mean' ,
85 'p95' ,
86 'ttfb' ,
87 'docKb' ,
88 'gzipKb' ,
89 'flightKb' ,
90 'rss' ,
91 'rssHw' ,
92 ])
93 }