ostia 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/chunk-nfgy545q.js +4 -0
- package/chunk-tw064qem.js +21 -0
- package/cli.js +48 -24
- package/index.d.ts +38 -1
- package/index.js +1 -1
- package/package.json +1 -1
- package/runner.ts +4 -4
- package/chunk-3rp84rbb.js +0 -4
- package/chunk-s1d2tx3w.js +0 -21
package/README.md
CHANGED
|
@@ -167,6 +167,41 @@ headroom, so numbers taken at `--jobs > 1` are noisier and not like-for-like wit
|
|
|
167
167
|
baseline measured at 1. It defaults to 1 for that reason; opt in for exploratory runs,
|
|
168
168
|
keep 1 for anything you `compare` or `ci` against.
|
|
169
169
|
|
|
170
|
+
`--isolate` gives every task its own child process instead of sharing its suite file's,
|
|
171
|
+
isolating each task's JIT tier state, inline caches and heap shape from every other task
|
|
172
|
+
in the run - the same guarantee suite files already get from each other, at task
|
|
173
|
+
granularity. `task(name, fn, { isolate })` / `group(name, fn, { isolate })` override the
|
|
174
|
+
suite-wide default for mixed suites (e.g. a couple of outlier-prone tasks isolated, the
|
|
175
|
+
rest sharing a process). `--jobs` then pools across those per-task processes the same way
|
|
176
|
+
it pools across per-file ones, so pair a higher `--jobs` with `--isolate` deliberately -
|
|
177
|
+
overhead now scales with task count, not file count.
|
|
178
|
+
|
|
179
|
+
`--gc` calls `Bun.gc(true)` between trials (default: off, which hides allocation cost as
|
|
180
|
+
Bun/V8 batch calls together and amortize it away). `task(name, fn, { gc })` /
|
|
181
|
+
`group(name, fn, { gc })` override the suite-wide default per task or group, the same
|
|
182
|
+
override pattern as `isolate` - useful when a few allocation-heavy tasks need GC settled
|
|
183
|
+
between trials but the rest of the suite doesn't.
|
|
184
|
+
|
|
185
|
+
`--preload PATH` (repeatable) imports a script before each suite file loads, in the same
|
|
186
|
+
subprocess - the same shape as Bun's own `--preload` / `bunfig.toml`'s `preload` array. Use
|
|
187
|
+
it to install globals a suite needs at import time (jsdom's `document`/`window`) or register
|
|
188
|
+
a `Bun.plugin()` file-loader (e.g. compiling `.svelte`/`.vue` SFCs) before the suite's own
|
|
189
|
+
top-level code runs. Multiple `--preload` scripts run in the order given, so state one
|
|
190
|
+
installs (a plugin registration, a global) is visible to the next and to the suite itself.
|
|
191
|
+
ostia ships none of this itself - just the hook point:
|
|
192
|
+
|
|
193
|
+
```ts
|
|
194
|
+
// bench/jsdom-setup.ts
|
|
195
|
+
import { JSDOM } from "jsdom"
|
|
196
|
+
const dom = new JSDOM("<!doctype html>")
|
|
197
|
+
Object.assign(globalThis, { document: dom.window.document, window: dom.window })
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
```sh
|
|
201
|
+
ostia bench --preload ./bench/jsdom-setup.ts bench/*.dom.bench.ts
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
|
|
170
205
|
```
|
|
171
206
|
Command Mean [ms] Min…Max [ms] Relative
|
|
172
207
|
--------------------------------------------------------------------------------------
|
|
@@ -361,6 +396,7 @@ import {
|
|
|
361
396
|
bench,
|
|
362
397
|
group,
|
|
363
398
|
task,
|
|
399
|
+
range,
|
|
364
400
|
compareDocuments,
|
|
365
401
|
renderers,
|
|
366
402
|
saveDocument,
|
|
@@ -454,6 +490,29 @@ group("parse", () => {
|
|
|
454
490
|
})
|
|
455
491
|
```
|
|
456
492
|
|
|
493
|
+
### `range(start, end, multiplier?)` → `number[]`
|
|
494
|
+
|
|
495
|
+
Geometric sweep points for parameterizing `task()` over a size dimension - mitata's
|
|
496
|
+
`.range(name, start, end, multiplier)` point generation (default multiplier `8`, always
|
|
497
|
+
ending on `end` even if the last step overshot it), without the name templating: build
|
|
498
|
+
the task name yourself in the loop.
|
|
499
|
+
|
|
500
|
+
```ts
|
|
501
|
+
import { group, task, range } from "ostia"
|
|
502
|
+
|
|
503
|
+
group("parse", () => {
|
|
504
|
+
for (const size of range(100, 10_000)) {
|
|
505
|
+
const input = buildInput(size) // setup, runs once per point, unmeasured
|
|
506
|
+
task(`${size} items`, () => parse(input))
|
|
507
|
+
}
|
|
508
|
+
})
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
```ts
|
|
512
|
+
range(100, 10_000) // -> [100, 800, 6400, 10000]
|
|
513
|
+
range(100, 100_000) // -> [100, 800, 6400, 51200, 100000]
|
|
514
|
+
```
|
|
515
|
+
|
|
457
516
|
```ts
|
|
458
517
|
// demo.ts
|
|
459
518
|
import { bench } from "ostia"
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
function h(n){return JSON.stringify(F(n))}function F(n){if(Array.isArray(n))return n.map(F);if(n!==null&&typeof n==="object"){let a={};for(let d of Object.keys(n).sort())a[d]=F(n[d]);return a}return n}function e(n,...a){let d=Bun.CryptoHasher.hash("sha256",h(a),"hex");return`${n}_${d.slice(0,16)}`}var c="0.1.0";function r(n,a){return{schemaVersion:1,toolVersion:c,bunVersion:Bun.version,platform:{os:process.platform,arch:process.arch},createdAt:new Date().toISOString(),workloads:n,runs:a}}function u(n,a){return{id:e("wl","subprocess",n,process.cwd()),kind:"subprocess",command:n,label:a}}function R(n,a){return{id:e("wl","inprocess",n.name,n.toString()),kind:"inprocess",label:a}}function P(n,a,d={}){return{id:e("wl","inprocess-entry",n,a),kind:"inprocess",entry:{file:n,task:a,...d.group!==void 0&&{group:d.group}},...d.label!==void 0&&{label:d.label},...d.baseline!==void 0&&{baseline:d.baseline},...d.description!==void 0&&{description:d.description},...d.groupDescription!==void 0&&{groupDescription:d.groupDescription},...d.isolated!==void 0&&{isolated:d.isolated}}}function i(n){return{id:e("run",n.workload.id,"timing",n.configFingerprint,Bun.version,c),workloadId:n.workload.id,phase:"timing",instrumented:!1,configFingerprint:n.configFingerprint,trials:n.trials,timing:n.timing,warnings:n.warnings,artifacts:[],memory:Q(n.trials)}}function Q(n){let a=n.map((d)=>d.maxRssBytes).filter((d)=>d!==void 0);if(a.length===0)return;return{origin:"resourceUsage",perTrial:n.map((d)=>({rssBytes:d.maxRssBytes})),maxRssBytes:Math.max(...a)}}function b(n){return{id:e("run",n.workload.id,n.phase,n.configFingerprint,Bun.version,c),workloadId:n.workload.id,phase:n.phase,instrumented:!0,configFingerprint:n.configFingerprint,trials:[{i:0,wallNs:n.diagnosticWallNs,exitCode:n.exitCode}],diagnosticWallNs:n.diagnosticWallNs,cpu:n.cpu,heap:n.heap,jit:n.jit,warnings:n.warnings,artifacts:n.artifacts}}async function T(n,a,d){let f=await Bun.file(d).arrayBuffer(),w=new Bun.CryptoHasher("sha256");return w.update(f),{id:e("art",n,a,d),kind:a,path:d,sha256:w.digest("hex"),bytes:f.byteLength}}function s(n){return e("cfg",n)}function k(n){return`${JSON.stringify(F(n),null,2)}
|
|
3
|
+
`}async function o(n,a){await Bun.write(a,k(n))}async function t(n){let a=await Bun.file(n).text();return JSON.parse(a)}var G=[],W;function U(n,a,d){let g=W;W={name:n,description:d?.description,isolate:d?.isolate,gc:d?.gc};try{a()}finally{W=g}}function M(n,a,d){G.push({groupName:W?.name,groupDescription:W?.description,groupIsolate:W?.isolate,groupGc:W?.gc,name:n,fn:a,baseline:d?.baseline,opts:d})}function I(){return G}function C(){G.length=0,W=void 0}function m(n){return n.groupName?`${n.groupName}/${n.name}`:n.name}function N(n,a){return n.opts?.isolate??n.groupIsolate??a}function D(n,a){return n.opts?.gc??n.groupGc??a}function v(n,a){if(!a)return[...n];let d=new RegExp(a);return n.filter((g)=>d.test(m(g)))}function l(n){if(n.length===0)throw Error("computeTimingStats: samples must be non-empty");let a=n.length,d=L(n),g=0;for(let y=0;y<a;y++)g+=n[y];let f=g/a,w=O(d,0.5),x=0;for(let y=0;y<a;y++){let S=n[y]-f;x+=S*S}let A=Math.sqrt(x/a),H=d[0],B=d[a-1],q=O(d,0.25),_=O(d,0.75),E=_-q,z=q-1.5*E,V=_+1.5*E,K=q-3*E,Z=_+3*E,J=0,j=0;for(let y=0;y<a;y++){let S=n[y];if(S<K||S>Z)j++;else if(S<z||S>V)J++}return{unit:"ns",samples:n,mean:f,median:w,stddev:A,min:H,max:B,outliers:{mild:J,severe:j}}}function L(n){let a=new Float64Array(n.length);return a.set(n),a.sort(),a}function O(n,a){let d=n.length;if(d===1)return n[0];let g=a*(d-1),f=Math.floor(g),w=Math.ceil(g);if(f===w)return n[f];let x=g-f;return n[f]*(1-x)+n[w]*x}var X=5000000,Y=200;function p(n,a,d="subprocess"){let g=[],f=n.samples[0];if(f!==void 0){let x=L(n.samples),A=O(x,0.25),B=O(x,0.75)-A;if(f>n.median+3*B&&B>0)g.push({code:"slow-first-run",message:`First run took ${(f/1e6).toFixed(2)}ms, much slower than the median ${(n.median/1e6).toFixed(2)}ms. Consider more warmup.`,data:{firstNs:f,medianNs:n.median}})}if(n.outliers.mild+n.outliers.severe>0)g.push({code:"outliers-detected",message:`${n.outliers.mild+n.outliers.severe} outlier(s) detected (${n.outliers.severe} severe, ${n.outliers.mild} mild).`,data:n.outliers});if(d==="subprocess"&&n.median<X)g.push({code:"fast-command",message:`Median run time (${(n.median/1e6).toFixed(3)}ms) is very fast; results may be dominated by spawn overhead.`,data:{medianNs:n.median}});if(d==="inprocess"&&n.median<Y)g.push({code:"below-timer-resolution",message:`Median run time (${n.median.toFixed(0)}ns) is close to timer resolution; consider a larger batch size or a coarser operation.`,data:{medianNs:n.median}});let w=a.filter((x)=>x!==void 0&&x!==0);if(w.length>0)g.push({code:"nonzero-exit",message:`${w.length} of ${a.length} trial(s) exited non-zero.`,data:{exitCodes:w}});return g}
|
|
4
|
+
export{h,e,c,r,u,R,P,i,b,T,s,k,o,t,l,p,U,M,I,C,m,N,D,v};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
import{h,e,r,u,R,i,b,T,s,k,t,l,p}from"./chunk-nfgy545q.js";function _e(o){return o.startsWith("file://")?o.slice(7):o}function ie(o,N,c){let I=o.nodes,m=I.length,v=new Map,C=[],P=new Map,U=new Int32Array(m);for(let W=0;W<m;W++){let E=I[W],B=E.callFrame,H=_e(B.url),G=v.get(B.functionName);if(G===void 0)G=new Map,v.set(B.functionName,G);let Y=G.get(H);if(Y===void 0)Y=C.length,G.set(H,Y),C.push({key:e("fr",B.functionName,H),name:B.functionName,url:H||void 0,line:B.lineNumber>=0?B.lineNumber:void 0,col:B.columnNumber>=0?B.columnNumber:void 0});U[W]=Y,P.set(E.id,W)}let D=Array(m);for(let W=0;W<m;W++){let E=I[W];D[W]={id:E.id,frameIx:U[P.get(E.id)],children:E.children??[]}}let M=new Float64Array(m),O=new Float64Array(m),{samples:A,timeDeltas:z}=o;for(let W=0;W<A.length;W++){let E=P.get(A[W]);if(E===void 0)continue;M[E]+=z[W]??0,O[E]+=1}let K=new Int32Array(m).fill(-1);for(let W=0;W<m;W++){let E=I[W].children;if(!E)continue;for(let B of E){let H=P.get(B);if(H!==void 0)K[H]=W}}let _=[],J=[];for(let W=m-1;W>=0;W--)if(K[W]===-1)J.push(W);while(J.length>0){let W=J.pop();_.push(W);let E=I[W].children;if(!E)continue;for(let B of E){let H=P.get(B);if(H!==void 0&&K[H]===W)J.push(H)}}let V=new Float64Array(m);for(let W=_.length-1;W>=0;W--){let E=_[W];V[E]+=M[E];let B=K[E];if(B>=0)V[B]+=V[E]}let L=Array(C.length),j=[];for(let W=0;W<m;W++){let E=D[W].frameIx,B=L[E];if(B)B.selfUs+=M[W],B.totalUs+=V[W],B.samples+=O[W];else{let H={frameIx:E,selfUs:M[W],totalUs:V[W],samples:O[W]};L[E]=H,j.push(H)}}return{origin:N,samplingIntervalUs:c,frames:C,nodes:D,totals:j.sort((W,E)=>E.selfUs-W.selfUs),samples:{nodeIds:o.samples,timeDeltasUs:o.timeDeltas}}}function Le(o,N,c,I){let m=["--cpu-prof","--cpu-prof-dir",N,"--cpu-prof-name",c,"--cpu-prof-interval",String(I)],v=o[0];if(v==="bun"||v?.endsWith("/bun"))return[v,...m,...o.slice(1)];return o}async function fe(o){let N=`${o.artifactDir}/${o.fileName}`,c=o.argv[0],I=c==="bun"||c?.endsWith("/bun"),m=Le(o.argv,o.artifactDir,o.fileName,o.intervalUs),v=I?o.env:{...process.env,...o.env,BUN_OPTIONS:`--cpu-prof --cpu-prof-dir ${o.artifactDir} --cpu-prof-name ${o.fileName} --cpu-prof-interval ${o.intervalUs}`},C=Bun.nanoseconds(),U=await Bun.spawn(m,{cwd:o.cwd,env:v,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,D=Bun.nanoseconds()-C,M=Bun.file(N);if(!await M.exists())return{diagnosticWallNs:D,exitCode:U,warnings:[{code:"artifact-missing",message:`Expected a .cpuprofile at ${N} after exit ${U}, found nothing. The workload's argv[0] must be a \`bun\` binary for CPU capture.`,data:{artifactPath:N,argv:o.argv}}]};let O=await M.json(),A=ie(O,"cpu-prof",o.intervalUs),z=O.samples.length===0?[{code:"empty-profile",message:"CPU capture produced zero samples."}]:[];return{diagnosticWallNs:D,exitCode:U,artifactPath:N,cpu:A,warnings:z}}function ge(o,N="heap-prof"){let{node_fields:c,node_types:I}=o.snapshot.meta,m=c.indexOf("type"),v=c.indexOf("self_size"),C=c.length,P=I[0];if(m===-1||v===-1||!Array.isArray(P))return{origin:N,typeCounts:[],objectCount:o.snapshot.node_count};let U=P.length,D=Array(U),M=new Map,O=[],A=0,z=o.nodes,K=z.length;for(let j=0;j<K;j+=C){let W=z[j+m],E=z[j+v]??0;A+=E;let B;if(W>=0&&W<U){if(B=D[W],B===void 0)B={type:P[W],count:0,bytes:0},D[W]=B,O.push(B)}else{let H=`unknown(${W})`;if(B=M.get(H),B===void 0)B={type:H,count:0,bytes:0},M.set(H,B),O.push(B)}B.count++,B.bytes+=E}let _=O.sort((j,W)=>W.count-j.count),J=_.slice(0,20),V=_.slice(20),L=J.map(({type:j,count:W,bytes:E})=>({type:j,count:W,retainedBytes:E}));if(V.length>0){let j=0,W=0;for(let E of V)j+=E.count,W+=E.bytes;L.push({type:"other",count:j,retainedBytes:W})}return{origin:N,heapSizeBytes:A,objectCount:o.snapshot.node_count,typeCounts:L}}function He(o,N,c){let I=["--heap-prof","--heap-prof-dir",N,"--heap-prof-name",c],m=o[0];if(m==="bun"||m?.endsWith("/bun"))return[m,...I,...o.slice(1)];return o}async function he(o){let N=`${o.artifactDir}/${o.fileName}`,c=o.argv[0],I=c==="bun"||c?.endsWith("/bun"),m=He(o.argv,o.artifactDir,o.fileName),v=I?o.env:{...process.env,...o.env,BUN_OPTIONS:`--heap-prof --heap-prof-dir ${o.artifactDir} --heap-prof-name ${o.fileName}`},C=Bun.nanoseconds(),U=await Bun.spawn(m,{cwd:o.cwd,env:v,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,D=Bun.nanoseconds()-C,M=Bun.file(N);if(!await M.exists())return{diagnosticWallNs:D,exitCode:U,warnings:[{code:"artifact-missing",message:`Expected a heap snapshot at ${N} after exit ${U}, found nothing. The workload's argv[0] must be a \`bun\` binary for heap capture.`,data:{artifactPath:N,argv:o.argv}}]};let O=await M.json(),A=ge(O,"heap-prof");return{diagnosticWallNs:D,exitCode:U,artifactPath:N,heap:A,warnings:[]}}import{Session as Je}from"inspector/promises";var ze=1000;async function be(o,N={}){let c=N.intervalUs??ze,I=new Je;I.connect();let m=Bun.nanoseconds();try{await I.post("Profiler.enable"),await I.post("Profiler.setSamplingInterval",{interval:c}),await I.post("Profiler.start");let v=await o(),{profile:C}=await I.post("Profiler.stop"),P=Bun.nanoseconds()-m,U=ie(C,"inspector",c);return{result:v,cpu:U,diagnosticWallNs:P}}finally{I.disconnect()}}import{profile as Ke}from"bun:jsc";var Ve=new Map([["LLInt","llint"],["Baseline","baseline"],["DFG","dfg"],["FTL","ftl"]]),ye=4294967295;function we(o,N){let c=N??o.interval*1e6,I=new Map,m=[];function v(B,H,G,Y){let Q=I.get(B);if(Q===void 0)Q=new Map,I.set(B,Q);let q=H??"",Z=Q.get(q);if(Z===void 0)Z=m.length,Q.set(q,Z),m.push({key:e("fr",B,q),name:B,url:H,line:G,col:Y});return Z}function C(B){let H=B.line===ye,G=H?void 0:B.line-1,Y=H||B.column===ye?void 0:B.column-1;return v(B.name,B.sourceURL,G,Y)}let P=v("(root)",void 0,void 0,void 0),U=1,D={id:0,frameIx:P,children:new Map,selfUs:0,samples:0,totalUs:0},M=new Map([[0,D]]),O={llint:0,baseline:0,dfg:0,ftl:0},A=new Map,z=[],K=[];for(let B of o.traces){let H=B.frames,G=D;for(let q=H.length-1;q>=0;q--){let Z=C(H[q]),te=G.children.get(Z);if(!te)te={id:U++,frameIx:Z,children:new Map,selfUs:0,samples:0,totalUs:0},G.children.set(Z,te),M.set(te.id,te);G=te}G.selfUs+=c,G.samples+=1,z.push(G.id),K.push(c);let Y=H[0],Q=Y&&Ve.get(Y.category);if(Q){O[Q]++;let q=A.get(Q)??new Map;q.set(G.frameIx,(q.get(G.frameIx)??0)+1),A.set(Q,q)}}function _(B){let H=B.selfUs;for(let G of B.children.values())H+=_(G);return B.totalUs=H,H}_(D);let J=new Map;function V(B){let H=J.get(B.frameIx);if(H)H.selfUs+=B.selfUs,H.totalUs+=B.totalUs,H.samples+=B.samples;else J.set(B.frameIx,{frameIx:B.frameIx,selfUs:B.selfUs,totalUs:B.totalUs,samples:B.samples});for(let G of B.children.values())V(G)}V(D);let L=[...M.values()].map((B)=>({id:B.id,frameIx:B.frameIx,children:[...B.children.values()].map((H)=>H.id)})),j={origin:"jsc-profile",samplingIntervalUs:c,frames:m,nodes:L,totals:[...J.values()].sort((B,H)=>H.selfUs-B.selfUs),samples:{nodeIds:z,timeDeltasUs:K}},W=[...A.entries()].flatMap(([B,H])=>[...H.entries()].sort((G,Y)=>Y[1]-G[1]).slice(0,3).map(([G,Y])=>({tier:B,frameKey:m[G].key,samples:Y})));return{cpu:j,jit:{origin:"jsc-profile",tiers:O,topFramesByTier:W}}}var Ge=1000;async function xe(o,N={}){let c=N.intervalUs??Ge,I,m=Bun.nanoseconds(),v=await Ke(async()=>(I=await o(),I),c),C=Bun.nanoseconds()-m,{cpu:P,jit:U}=we(v.stackTraces,c);return{result:I,cpu:P,jit:U,diagnosticWallNs:C}}async function le(o){let N=Bun.nanoseconds(),c=Bun.spawn(o.argv,{cwd:o.cwd,env:o.env,stdout:"ignore",stderr:"ignore",stdin:"ignore"}),I=await c.exited,m=Bun.nanoseconds(),v=c.resourceUsage?.();return{wallNs:m-N,exitCode:I,userNs:v?Number(v.cpuTime.user)*1000:void 0,systemNs:v?Number(v.cpuTime.system)*1000:void 0,maxRssBytes:v?.maxRSS}}function Re(o){return o.trim().split(/\s+/).filter(Boolean)}var Ye=10,qe=3000000000,Qe=3;async function g(o){let N=o.warmup??Qe;for(let M=0;M<N;M++)await le(o);let c=[],I=o.runs??o.minRuns??Ye,m=o.runs!==void 0?0:o.minTotalNs??qe,v=0,C=0;while(C<I||v<m){let M=await le(o);if(c.push({i:C,wallNs:M.wallNs,exitCode:M.exitCode,userNs:M.userNs,systemNs:M.systemNs,maxRssBytes:M.maxRssBytes}),v+=M.wallNs,C++,o.runs!==void 0&&C>=o.runs)break}let P=c.map((M)=>M.wallNs),U=l(P),D=p(U,c.map((M)=>M.exitCode));return{trials:c,timing:U,warnings:D}}var Pe=new URL("./runner.ts",import.meta.url).pathname,Xe="node_modules/.cache/ostia";function x(){return Math.max(1,navigator.hardwareConcurrency||1)}async function d(o){let c=`${o.outDir??Xe}/bench-tmp`,I=o.cwd??process.cwd(),m=Math.max(1,Math.floor(o.jobs??1)),v={timeBudgetMs:o.timeBudgetMs,minSamples:o.minSamples,gc:o.gc},C=o.suites.map((D)=>D.startsWith("/")?D:`${I}/${D}`),P=(o.preload??[]).map((D)=>D.startsWith("/")?D:`${I}/${D}`),U=async(D,M)=>{let O=new Set,A=0,z,K=async()=>{while(z===void 0&&A<D.length){let _=A++;try{let J=Bun.spawn(D[_],{cwd:I,stdout:"inherit",stderr:"inherit",stdin:"ignore"});O.add(J);let V=await J.exited;if(O.delete(J),V!==0)throw Error(`Bench suite failed: ${M(_)} (runner exited ${V})`)}catch(J){z??=J instanceof Error?J:Error(String(J));for(let V of O)V.kill()}}};if(await Promise.all(Array.from({length:Math.min(m,D.length)},K)),z)throw z};try{let D=C.map((L)=>`${c}/${e("bench-plan",L)}.json`),M=C.map((L,j)=>["bun",Pe,L,D[j],JSON.stringify({...v,filter:o.filter,isolate:o.isolate,preload:P,planOnly:!0})]);await U(M,(L)=>o.suites[L]);let O=await Promise.all(D.map(async(L)=>{let{tasks:j}=await Bun.file(L).json();return j})),A=[];for(let L=0;L<O.length;L++){let j=O[L].filter((W)=>!W.isolate).map((W)=>W.id);if(j.length>0)A.push({suiteIndex:L,taskIds:j,markIsolated:!1});for(let W of O[L])if(W.isolate)A.push({suiteIndex:L,taskIds:[W.id],markIsolated:!0})}let z=A.map((L,j)=>`${c}/${e("bench-item",C[L.suiteIndex],j)}.json`),K=A.map((L,j)=>["bun",Pe,C[L.suiteIndex],z[j],JSON.stringify({...v,taskIds:L.taskIds,preload:P,...L.markIsolated&&{markIsolated:!0}})]);await U(K,(L)=>o.suites[A[L].suiteIndex]);let _=await Promise.all(z.map(t)),J=[],V=[];for(let L=0;L<O.length;L++){let j=A.findIndex((H)=>H.suiteIndex===L&&!H.markIsolated),W=j>=0?_[j]:void 0,E=0,B=new Map;A.forEach((H,G)=>{if(H.suiteIndex===L&&H.markIsolated)B.set(H.taskIds[0],_[G])});for(let H of O[L])if(H.isolate){let G=B.get(H.id);J.push(G.workloads[0]),V.push(G.runs[0])}else J.push(W.workloads[E]),V.push(W.runs[E]),E++}return r(J,V)}finally{await Bun.spawn(["rm","-rf",c]).exited}}function F(o,N,c=8){if(c<=1)throw RangeError(`range: multiplier must be > 1, got ${c}`);if(o<=0)throw RangeError(`range: start must be > 0, got ${o}`);let I=[];for(let m=o;m<=N;m*=c)I.push(m);if(!I.includes(N))I.push(N);return I}var a={timingPct:5,frameSelfPct:10,heapTypePct:10,minFrameSelfUs:1000};function ae(o,N){if(o===0)return N===0?0:1/0;return(N-o)/o*100}function re(o,N,c){return o.runs.find((I)=>I.workloadId===N&&I.phase===c)}function f(o,N,c=a){let I=new Set(N.workloads.map((v)=>v.id)),m=[];for(let v of o.workloads){if(!I.has(v.id))continue;let C=w(o,N,v.id,c);if(C)m.push(C)}return m}function w(o,N,c,I=a){let m=re(o,c,"timing"),v=re(N,c,"timing"),C=re(o,c,"cpu"),P=re(N,c,"cpu"),U=re(o,c,"heap"),D=re(N,c,"heap"),M=m?.id??C?.id??U?.id,O=v?.id??P?.id??D?.id;if(!M||!O)return;let A=!1,z;if(m?.timing&&v?.timing){let J=ae(m.timing.median,v.timing.median),V=ae(m.timing.mean,v.timing.mean),L=J>I.timingPct?"regressed":J<-I.timingPct?"improved":"unchanged";if(L==="regressed")A=!0;z={medianDeltaPct:J,meanDeltaPct:V,verdict:L}}let K;if(C?.cpu&&P?.cpu){let J=new Map(C.cpu.totals.map((E)=>[C.cpu.frames[E.frameIx].key,E])),V=new Map(P.cpu.totals.map((E)=>[P.cpu.frames[E.frameIx].key,E])),L=new Map(C.cpu.frames.map((E)=>[E.key,E.name])),j=new Map(P.cpu.frames.map((E)=>[E.key,E.name]));K=[...new Set([...J.keys(),...V.keys()])].map((E)=>{let B=J.get(E)?.selfUs??0,H=V.get(E)?.selfUs??0;return{frameKey:E,name:j.get(E)??L.get(E)??E,baseSelfUs:B,candSelfUs:H,deltaPct:ae(B,H)}}).sort((E,B)=>Math.abs(B.deltaPct)-Math.abs(E.deltaPct));for(let E of K)if((E.baseSelfUs>=I.minFrameSelfUs||E.candSelfUs>=I.minFrameSelfUs)&&E.deltaPct>I.frameSelfPct)A=!0}let _;if(U?.heap&&D?.heap){let J=new Map(U.heap.typeCounts.map((j)=>[j.type,j])),V=new Map(D.heap.typeCounts.map((j)=>[j.type,j]));_=[...new Set([...J.keys(),...V.keys()])].map((j)=>{let W=J.get(j),E=V.get(j);return{type:j,baseCount:W?.count??0,candCount:E?.count??0,baseBytes:W?.retainedBytes,candBytes:E?.retainedBytes,deltaPct:ae(W?.count??0,E?.count??0)}}).sort((j,W)=>Math.abs(W.deltaPct)-Math.abs(j.deltaPct));for(let j of _)if(j.deltaPct>I.heapTypePct)A=!0}return{id:e("cmp",M,O),baselineRunId:M,candidateRunId:O,timing:z,frames:K,heapTypes:_,thresholds:I,verdict:A?"fail":"pass"}}function ee(o,N){if(N){let c=o.runs.find((I)=>I.id===N);return c?.cpu?[c]:[]}return o.runs.filter((c)=>c.phase==="cpu"&&c.cpu)}function se(o){let N=o.nodes,c=N.length,I=Ze(o),m=new Int32Array(c).fill(-1);for(let U=0;U<c;U++)for(let D of N[U].children){let M=I(D);if(M!==-1)m[M]=U}let v=[];for(let U=0;U<c;U++)if(m[U]===-1)v.push(U);let C=[],P=[];for(let U=v.length-1;U>=0;U--)P.push(v[U]);while(P.length>0){let U=P.pop();C.push(U);for(let D of N[U].children){let M=I(D);if(M!==-1&&m[M]===U)P.push(M)}}return{count:c,indexOf:I,parentIx:m,roots:v,order:C}}function Ze(o){let N=o.nodes,c=N.length,I=1/0,m=-1/0,v=!0;for(let P=0;P<c;P++){let U=N[P].id;if(!Number.isInteger(U)){v=!1;break}if(U<I)I=U;if(U>m)m=U}if(v&&c>0&&m-I<c*4+64){let P=m-I+1,U=new Int32Array(P).fill(-1);for(let D=0;D<c;D++)U[N[D].id-I]=D;return(D)=>{let M=D-I;return M>=0&&M<P?U[M]:-1}}let C=new Map;for(let P=0;P<c;P++)C.set(N[P].id,P);return(P)=>C.get(P)??-1}function ke(o,N){let{count:c,indexOf:I,parentIx:m,order:v}=N,C=new Float64Array(c),P=new Float64Array(c),U=o.samples?.nodeIds??[],D=o.samples?.timeDeltasUs??[];for(let O=0;O<U.length;O++){let A=I(U[O]);if(A===-1)continue;C[A]+=D[O]??0,P[A]+=1}let M=new Float64Array(c);for(let O=v.length-1;O>=0;O--){let A=v[O];M[A]+=C[A];let z=m[A];if(z>=0)M[z]+=M[A]}return{selfUs:C,totalUs:M,samples:P}}var Te={name:"collapsed",async render(o,N={}){return{files:ee(o,N.runId).map((m)=>{let v=m.cpu,{nodes:C,frames:P}=v,U=se(v),D=Array(U.count);for(let K of U.order){let _=P[C[K].frameIx].name||"(anonymous)",J=U.parentIx[K];D[K]=J===-1?_:`${D[J]};${_}`}let M=new Float64Array(U.count),O=[],A=v.samples?.nodeIds??[];for(let K=0;K<A.length;K++){let _=U.indexOf(A[K]);if(_===-1)continue;if(M[_]++===0)O.push(_)}let z=Array(O.length);for(let K=0;K<O.length;K++){let _=O[K];z[K]=`${D[_]} ${M[_]}`}return{path:`${m.id}.collapsed.txt`,content:z.join(`
|
|
3
|
+
`)+(z.length>0?`
|
|
4
|
+
`:"")}})}}};var Ie={name:"cpuprofile",async render(o,N={}){let c=ee(o,N.runId),I=[],m=[];for(let v of c){if(v.cpu?.origin!=="cpu-prof"&&v.cpu?.origin!=="inspector"){m.push(`${v.id} (origin ${v.cpu?.origin??"unknown"} has no .cpuprofile artifact to pass through)`);continue}let C=v.artifacts.find((U)=>U.kind==="cpuprofile");if(!C){m.push(`${v.id} (no cpuprofile artifact recorded on this run)`);continue}let P=Bun.file(C.path);if(!await P.exists()){m.push(`${v.id} (artifact missing on disk: ${C.path})`);continue}I.push({path:`${v.id}.cpuprofile`,content:await P.text()})}if(I.length===0&&m.length>0)return{text:`No .cpuprofile artifacts available:
|
|
5
|
+
${m.map((v)=>` - ${v}`).join(`
|
|
6
|
+
`)}
|
|
7
|
+
`};return{files:I}}};var $e={name:"json",async render(o){return{text:k(o)}}};var ve={name:"jsonl",async render(o){let{runs:N,...c}=o;return{text:`${[h(c),...N.map((m)=>h(m))].join(`
|
|
8
|
+
`)}
|
|
9
|
+
`}}};function ne(o){return(o/1e6).toFixed(3)}function ce(o){return o?.label??o?.command?.join(" ")??o?.entry?.task??o?.id??"unknown"}var Ce=10,Ne=10,Ue={name:"markdown",async render(o){let N=new Map(o.workloads.map((m)=>[m.id,m])),c=[];c.push("# Profile Report",""),c.push(`Bun ${o.bunVersion} \xB7 ostia ${o.toolVersion} \xB7 ${o.platform.os}/${o.platform.arch} \xB7 ${o.createdAt}`,"");let I=o.runs.filter((m)=>m.phase==="timing"&&m.timing!==void 0);if(I.length>0){c.push("## Timing",""),c.push("| Command | Mean \xB1 SD (ms) | Min\u2026Max (ms) | Median (ms) |","|---|---|---|---|");for(let v of I){let C=ce(N.get(v.workloadId)),P=v.timing;c.push(`| ${C} | ${ne(P.mean)} \xB1 ${ne(P.stddev)} | ${ne(P.min)}\u2026${ne(P.max)} | ${ne(P.median)} |`)}c.push("");let m=I.filter((v)=>v.warnings.length>0);if(m.length>0){c.push("### Warnings","");for(let v of m){let C=ce(N.get(v.workloadId));for(let P of v.warnings)c.push(`- **${C}**: ${P.message} (\`${P.code}\`)`)}c.push("")}}for(let m of o.runs){if(m.phase!=="cpu"&&m.phase!=="heap")continue;let v=ce(N.get(m.workloadId));if(m.phase==="cpu"){if(c.push(`## CPU capture - ${v}`,""),c.push(`instrumented, diagnostic wall ${ne(m.diagnosticWallNs??0)}ms`,""),m.cpu){c.push(`origin: \`${m.cpu.origin}\`, interval: ${m.cpu.samplingIntervalUs}\xB5s`,""),c.push("| Self % | Self (ms) | Total (ms) | Frame |","|---|---|---|---|");let C=m.cpu.totals.reduce((P,U)=>P+U.selfUs,0)||1;for(let P of m.cpu.totals.slice(0,Ce)){let U=m.cpu.frames[P.frameIx],D=(P.selfUs/C*100).toFixed(1);c.push(`| ${D}% | ${(P.selfUs/1000).toFixed(2)} | ${(P.totalUs/1000).toFixed(2)} | ${U?.name||"(anonymous)"} |`)}if(c.push(""),m.jit){let P=m.jit.tiers;c.push(`JIT tiers: LLInt ${P.llint} \xB7 Baseline ${P.baseline} \xB7 DFG ${P.dfg} \xB7 FTL ${P.ftl}`,"")}}}else if(c.push(`## Heap snapshot - ${v}`,""),c.push(`instrumented, diagnostic wall ${ne(m.diagnosticWallNs??0)}ms`,""),m.heap){c.push(`${m.heap.objectCount??"?"} objects, ${((m.heap.heapSizeBytes??0)/1e6).toFixed(2)}MB`,""),c.push("| Count | Type |","|---|---|");for(let C of m.heap.typeCounts.slice(0,Ne))c.push(`| ${C.count} | ${C.type} |`);c.push("")}for(let C of m.artifacts)c.push(`- artifact: \`${C.path}\``);for(let C of m.warnings)c.push(`- ! ${C.message} (\`${C.code}\`)`);if(m.artifacts.length>0||m.warnings.length>0)c.push("")}if(o.comparisons&&o.comparisons.length>0){c.push("## Comparisons","");for(let m of o.comparisons){let v=o.runs.find((P)=>P.id===m.candidateRunId),C=ce(v?N.get(v.workloadId):void 0);if(c.push(`### ${m.verdict==="pass"?"\u2713":"\u2717"} ${C}`,""),m.timing){let P=m.timing.medianDeltaPct>0?"+":"";c.push(`- timing: ${P}${m.timing.medianDeltaPct.toFixed(1)}% median (**${m.timing.verdict}**)`)}for(let P of m.frames?.slice(0,Ce)??[]){if(Math.abs(P.deltaPct)<0.5)continue;let U=P.deltaPct>0?"+":"";c.push(`- frame \`${P.name}\`: ${U}${P.deltaPct.toFixed(1)}% self-time (${(P.baseSelfUs/1000).toFixed(2)}ms \u2192 ${(P.candSelfUs/1000).toFixed(2)}ms)`)}for(let P of m.heapTypes?.slice(0,Ne)??[]){if(Math.abs(P.deltaPct)<0.5)continue;let U=P.deltaPct>0?"+":"";c.push(`- heap \`${P.type}\`: ${U}${P.deltaPct.toFixed(1)}% count (${P.baseCount} \u2192 ${P.candCount})`)}c.push("")}}return{text:c.join(`
|
|
10
|
+
`)}}};var en=15;function pe(o){return`n${o}`}function nn(o,N,c){return`${(o||"(anonymous)").replace(/"/g,"'")} (self ${(N/1000).toFixed(2)}ms, total ${(c/1000).toFixed(2)}ms)`}function tn(o,N,c,I){let m=[];if(I<=0)return m;for(let v=0;v<N;v++){if(v===c)continue;let C=o[v];if(m.length===I&&C<=o[m[I-1]])continue;let P=m.length;while(P>0&&o[m[P-1]]<C)P--;if(m.splice(P,0,v),m.length>I)m.pop()}return m}var De={name:"mermaid",async render(o,N={}){let c=N.topN??en;return{files:ee(o,N.runId).map((v)=>{let C=v.cpu,{nodes:P,frames:U}=C,D=se(C),{selfUs:M,totalUs:O}=ke(C,D),{parentIx:A}=D,z=D.roots[0]??-1,K=tn(M,D.count,z,c),_=new Set(z!==-1?[z]:[]),J=[];for(let L of K){J.length=0;for(let j=L;j!==-1;j=A[j])J.push(j);for(let j=J.length-1;j>=0;j--)_.add(J[j])}let V=["graph TD"];for(let L of _){let j=P[L].id;V.push(` ${pe(j)}["${nn(U[P[L].frameIx].name,M[L],O[L])}"]`)}for(let L of _){let j=A[L];if(j!==-1&&_.has(j))V.push(` ${pe(P[j].id)} --> ${pe(P[L].id)}`)}return{path:`${v.id}.mermaid.md`,content:`${V.join(`
|
|
11
|
+
`)}
|
|
12
|
+
`}})}}};function Fe(o){if(!o?.entry)return;if(o.entry.group!==void 0)return o.entry.group;let N=o.entry.task,c=N.lastIndexOf("/");return c===-1?void 0:N.slice(0,c)}function ue(o){let N=Math.min(...o.map((m)=>m.run.timing.median)),c=new Map;for(let m of o){let v=Fe(m.workload);if(v===void 0)continue;let C=c.get(v);if(C)C.push(m);else c.set(v,[m])}let I=new Map;for(let m of o){let v=Fe(m.workload);if(v===void 0){I.set(m,N);continue}let C=c.get(v)??[m],P=C.find((U)=>U.workload?.baseline);I.set(m,P?P.run.timing.median:Math.min(...C.map((U)=>U.run.timing.median)))}return I}function X(o){return Number.isFinite(o)?Number(o.toPrecision(6)):o}function rn(o,N){return o?.entry?.task??o?.label??o?.command?.join(" ")??N.workloadId}function sn(o){let N=new Map(o.workloads.map((v)=>[v.id,v])),c=o.runs.filter((v)=>v.phase==="timing"&&v.timing!==void 0).map((v)=>({run:v,workload:N.get(v.workloadId)})),I=c.length>1?ue(c):void 0,m=new Map((o.comparisons??[]).map((v)=>[v.candidateRunId,v]));return c.map((v)=>{let{run:C,workload:P}=v,U=C.timing,D={task:rn(P,C),unit:"ns",samples:U.samples.length,mean:X(U.mean),median:X(U.median),stddev:X(U.stddev),stddevPct:X(U.mean===0?0:U.stddev/U.mean*100),min:X(U.min),max:X(U.max),warnings:C.warnings.map((O)=>O.data?{code:O.code,data:O.data}:{code:O.code})};if(P?.entry?.group!==void 0)D.group=P.entry.group;if(P?.description!==void 0)D.description=P.description;if(P?.groupDescription!==void 0)D.groupDescription=P.groupDescription;if(I)D.relative=X(U.median/(I.get(v)??U.median));if(P?.baseline)D.baseline=!0;let M=m.get(C.id);if(M?.timing)D.delta={medianPct:X(M.timing.medianDeltaPct),meanPct:X(M.timing.meanDeltaPct),verdict:M.timing.verdict,pass:M.verdict==="pass"};return D})}var Me={name:"minimal",async render(o){let N=sn(o).map((c)=>JSON.stringify(c));return{text:N.length>0?`${N.join(`
|
|
13
|
+
`)}
|
|
14
|
+
`:""}}};var on="https://www.speedscope.app/file-format-schema.json";function Se(o){return o?.label??o?.command?.join(" ")??o?.entry?.task??"profile"}var Be={name:"speedscope",async render(o,N={}){let c=ee(o,N.runId),I=new Map(o.workloads.map((v)=>[v.id,v]));return{files:c.map((v)=>{let C=v.cpu,{nodes:P}=C,U=se(C),D=C.samples?.nodeIds??[],M=C.samples?.timeDeltasUs??[],O=Array(U.count);for(let _ of U.order){let J=U.parentIx[_],V=P[_].frameIx;O[_]=J===-1?[V]:[...O[J],V]}let A=Array(D.length);for(let _=0;_<D.length;_++){let J=U.indexOf(D[_]);A[_]=J===-1?[]:O[J]}let z=0;for(let _=0;_<M.length;_++)z+=M[_];let K={$schema:on,exporter:"ostia",name:Se(I.get(v.workloadId)),activeProfileIndex:0,shared:{frames:C.frames.map((_)=>({name:_.name||"(anonymous)",file:_.url,line:_.line!==void 0?_.line+1:void 0}))},profiles:[{type:"sampled",name:Se(I.get(v.workloadId)),unit:"microseconds",startValue:0,endValue:z,samples:A,weights:M}]};return{path:`${v.id}.speedscope.json`,content:`${JSON.stringify(K,null,2)}
|
|
15
|
+
`}})}}};function oe(o){return(o/1e6).toFixed(3)}function me(o){return o.label??o.command?.join(" ")??o.entry?.task??o.id}var We={name:"table",async render(o){let N=o.runs.filter((O)=>O.phase==="timing"&&O.timing!==void 0),c=new Map(o.workloads.map((O)=>[O.id,O]));if(N.length===0){let O=Oe(o,c);return{text:O.length>0?`${O.join(`
|
|
16
|
+
`)}
|
|
17
|
+
`:`(no timing runs)
|
|
18
|
+
`}}let I=N.map((O)=>{let A=c.get(O.workloadId);return{run:O,workload:A,label:A?me(A):O.workloadId}}),m=I.length>1,v=ue(I),C=[],P=Math.max(7,...I.map((O)=>O.label.length)),U=m?`${"Command".padEnd(P)} Mean [ms] Min\u2026Max [ms] Relative`:`${"Command".padEnd(P)} Mean [ms] Min\u2026Max [ms]`;C.push(U),C.push("-".repeat(U.length));for(let O of I){let{run:A,label:z,workload:K}=O,_=A.timing,J=`${oe(_.mean)} \xB1 ${oe(_.stddev)}`,V=`${oe(_.min)}\u2026${oe(_.max)}`,L=`${z.padEnd(P)} ${J.padEnd(15)} ${V.padEnd(18)}`;if(m){let j=_.median/(v.get(O)??_.median);if(j===1)L+=K?.baseline?" 1.00\xD7 (baseline)":" 1.00\xD7";else if(j>1)L+=` ${j.toFixed(2)}\xD7 slower`;else L+=` ${(1/j).toFixed(2)}\xD7 faster`}C.push(L);for(let j of A.warnings)C.push(` ! ${j.message}`)}let D=cn(o,c);if(D.length>0)C.push(""),C.push(...D);let M=Oe(o,c);if(M.length>0)C.push(""),C.push(...M);return{text:`${C.join(`
|
|
19
|
+
`)}
|
|
20
|
+
`}}};function an(o,N,c){let I=o.runs.find((v)=>v.id===c),m=I?N.get(I.workloadId):void 0;return m?me(m):c}function Oe(o,N){if(!o.comparisons||o.comparisons.length===0)return[];let c=[];for(let I of o.comparisons){let m=an(o,N,I.candidateRunId),v=I.verdict==="pass"?"\u2713":"\u2717";if(c.push(`${v} ${m}`),I.timing){let C=I.timing.medianDeltaPct>0?"+":"";c.push(` timing: ${C}${I.timing.medianDeltaPct.toFixed(1)}% median (${I.timing.verdict})`)}if(I.frames)for(let C of I.frames.slice(0,Ee)){if(Math.abs(C.deltaPct)<0.5)continue;let P=C.deltaPct>0?"+":"";c.push(` frame ${C.name}: ${P}${C.deltaPct.toFixed(1)}% self-time (${(C.baseSelfUs/1000).toFixed(2)}ms -> ${(C.candSelfUs/1000).toFixed(2)}ms)`)}if(I.heapTypes)for(let C of I.heapTypes.slice(0,Ae)){if(Math.abs(C.deltaPct)<0.5)continue;let P=C.deltaPct>0?"+":"";c.push(` heap ${C.type}: ${P}${C.deltaPct.toFixed(1)}% count (${C.baseCount} -> ${C.candCount})`)}}return c}var Ee=5,Ae=5;function cn(o,N){let c=[];for(let I of o.runs){if(I.phase!=="cpu"&&I.phase!=="heap")continue;let m=N.get(I.workloadId),v=m?me(m):I.workloadId;if(I.phase==="cpu")if(I.cpu){c.push(`CPU capture - ${v} (instrumented, ${I.cpu.samplingIntervalUs}\xB5s interval, diagnostic wall ${oe(I.diagnosticWallNs??0)}ms)`);let C=I.cpu.totals.reduce((P,U)=>P+U.selfUs,0)||1;for(let P of I.cpu.totals.slice(0,Ee)){let U=I.cpu.frames[P.frameIx],D=(P.selfUs/C*100).toFixed(1);c.push(` ${D.padStart(5)}% ${(P.selfUs/1000).toFixed(2).padStart(8)}ms self ${U?.name??"?"}`)}}else c.push(`CPU capture - ${v} (instrumented, no evidence captured)`);else if(I.heap){let C=((I.heap.heapSizeBytes??0)/1e6).toFixed(2);c.push(`Heap snapshot - ${v} (instrumented, ${I.heap.objectCount??"?"} objects, ${C}MB)`);for(let P of I.heap.typeCounts.slice(0,Ae))c.push(` ${String(P.count).padStart(6)} ${P.type}`)}else c.push(`Heap snapshot - ${v} (instrumented, no evidence captured)`);for(let C of I.artifacts)c.push(` artifact: ${C.path}`);for(let C of I.warnings)c.push(` ! ${C.message}`)}return c}var n={table:We,json:$e,markdown:Ue,jsonl:ve,minimal:Me,collapsed:Te,mermaid:De,speedscope:Be,cpuprofile:Ie};var un="node_modules/.cache/ostia",de=1000;async function y(o){let N=s({runs:o.runs??null,warmup:o.warmup??null,cpu:o.cpu??!1,heap:o.heap??!1,cpuIntervalUs:o.cpuIntervalUs??de}),I=`${o.outDir??un}/artifacts`,m=[],v=[];for(let C of o.commands){let P=Array.isArray(C)?C:Re(C),U=u(P,Array.isArray(C)?void 0:C);m.push(U);let D=await g({argv:P,cwd:o.cwd,env:o.env,runs:o.runs,warmup:o.warmup}),M=i({workload:U,configFingerprint:N,trials:D.trials,timing:D.timing,warnings:D.warnings});if(v.push(M),o.cpu){let O=`${M.id}-cpu.cpuprofile`,A=await fe({argv:P,cwd:o.cwd,env:o.env,artifactDir:I,fileName:O,intervalUs:o.cpuIntervalUs??de});v.push(await je({workload:U,phase:"cpu",configFingerprint:N,diagnosticWallNs:A.diagnosticWallNs,exitCode:A.exitCode,cpu:A.cpu,artifactPath:A.artifactPath,artifactKind:"cpuprofile",warnings:A.warnings}))}if(o.heap){let O=`${M.id}-heap.heapsnapshot`,A=await he({argv:P,cwd:o.cwd,env:o.env,artifactDir:I,fileName:O});v.push(await je({workload:U,phase:"heap",configFingerprint:N,diagnosticWallNs:A.diagnosticWallNs,exitCode:A.exitCode,heap:A.heap,artifactPath:A.artifactPath,artifactKind:"heapsnapshot",warnings:A.warnings}))}}return r(m,v)}async function je(o){let N=`${o.workload.id}-${o.phase}-${o.configFingerprint}`,c=o.artifactPath?[await T(N,o.artifactKind,o.artifactPath)]:[];return b({workload:o.workload,phase:o.phase,configFingerprint:o.configFingerprint,diagnosticWallNs:o.diagnosticWallNs,exitCode:o.exitCode,cpu:o.cpu,heap:o.heap,warnings:o.warnings,artifacts:c})}async function S(o,N={}){let c=R(o),I=s({intervalUs:N.intervalUs??de,origin:N.origin??"inspector"}),m=(D)=>D.samples?.nodeIds.length===0?[{code:"empty-profile",message:"In-process capture produced zero samples."}]:[];if(N.origin==="jsc"){let{result:D,cpu:M,jit:O,diagnosticWallNs:A}=await xe(o,N),z=b({workload:c,phase:"cpu",configFingerprint:I,diagnosticWallNs:A,cpu:M,jit:O,warnings:m(M),artifacts:[]});return{result:D,run:z}}let{result:v,cpu:C,diagnosticWallNs:P}=await be(o,N),U=b({workload:c,phase:"cpu",configFingerprint:I,diagnosticWallNs:P,cpu:C,warnings:m(C),artifacts:[]});return{result:v,run:U}}
|
|
21
|
+
export{x,d,a,f,w,g,F,n,y,S};
|
package/cli.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{
|
|
4
|
-
`)}var X="node_modules/.cache/ostia",Q=".ostia/baselines",Y={runs:null,warmup:3,outDir:X,baselineDir:Q,baseline:"main",cpuIntervalUs:1000,thresholds:a,workloads:[]};async function W(
|
|
3
|
+
import{x,d,a,f,w,g,n,y}from"./chunk-tw064qem.js";import{e,c,r,u,i,s,o,t}from"./chunk-nfgy545q.js";function q(p){return e("cache",p.workloadId,p.phase,p.configFingerprint,p.bunVersion,p.toolVersion,p.instrumented,p.inputsDigest??null)}async function _(p,l=process.cwd()){if(p.length===0)return;let m=new Set;for(let b of p){let P=new Bun.Glob(b);for await(let C of P.scan({cwd:l,absolute:!1}))m.add(C)}let k=[...m].sort(),h=await Promise.all(k.map(async(b)=>{let P=await Bun.file(`${l}/${b}`).arrayBuffer();return{path:b,sha256:Bun.CryptoHasher.hash("sha256",P,"hex")}}));return e("inputs",h)}function L(p,l){return`${p}/cache/${l}.json`}async function M(p,l){let m=Bun.file(L(p,l));if(!await m.exists())return;return await m.json()}async function z(p,l,m){await Bun.write(L(p,l),`${JSON.stringify(m,null,2)}
|
|
4
|
+
`)}var X="node_modules/.cache/ostia",Q=".ostia/baselines",Y={runs:null,warmup:3,outDir:X,baselineDir:Q,baseline:"main",cpuIntervalUs:1000,thresholds:a,workloads:[]};async function W(p="ostia.config.json"){let l=Bun.file(p);if(!await l.exists())return;let m=await l.json();return{...Y,...m,thresholds:{...a,...m.thresholds??{}}}}function V(p,l){return`${p.baselineDir}/${l??p.baseline}.json`}class B extends Error{path;constructor(p){super(`No baseline document at ${p}. Create one with: ostia run --export-json ${p} <command...>`);this.path=p}}async function K(p){let{config:l}=p,m=V(l,p.baselineName);if(!await Bun.file(m).exists())throw new B(m);let h=await t(m),b=[],P=0,C=0,F=0;for(let j of l.workloads){let R=u(j.command,j.label),S=await _(j.inputs??[]),I=s({runs:l.runs,warmup:l.warmup}),H=q({workloadId:R.id,phase:"timing",configFingerprint:I,bunVersion:Bun.version,toolVersion:c,instrumented:!1,inputsDigest:S}),J=p.full?void 0:await M(l.outDir,H),T,O;if(J)T=J,O="cached",C++;else{P++;let U=await g({argv:j.command,runs:l.runs??void 0,warmup:l.warmup});T=i({workload:R,configFingerprint:I,trials:U.trials,timing:U.timing,warnings:U.warnings}),await z(l.outDir,H,T),O="executed",F++}b.push({workload:R,status:O,run:T})}let D=r(b.map((j)=>j.workload),b.map((j)=>j.run)),A=0,E=0,N=0;for(let j of b){let R=w(h,D,j.workload.id,l.thresholds);if(!R){N++;continue}if(j.comparison=R,R.verdict==="pass")A++;else E++}return D.comparisons=b.map((j)=>j.comparison).filter((j)=>j!==void 0),{document:D,summary:{total:l.workloads.length,affected:P,cached:C,executed:F,passed:A,regressed:E,missingBaseline:N,results:b}}}function G(p){let l=[];if(l.push(`${p.total} workloads`),l.push(`${p.affected} affected by this change`),l.push(`${p.cached} cached`),l.push(`${p.executed} executed`),p.missingBaseline>0)l.push(`${p.missingBaseline} skipped (no matching baseline workload)`);let m=p.results.filter((k)=>k.comparison?.verdict==="fail").map((k)=>{let h=k.comparison.timing,b=k.workload.label??k.workload.command?.join(" ")??k.workload.id;return h?`${h.medianDeltaPct>0?"+":""}${h.medianDeltaPct.toFixed(1)}% median on ${b}`:b});return l.push(`${p.passed} passed ${p.regressed} regressed${m.length>0?` (${m.join(", ")})`:""}`),l.push(""),l.push(`Profile CI: ${p.regressed>0?"\u2717":"\u2713"}`),`${l.join(`
|
|
5
5
|
`)}
|
|
6
|
-
`}async function
|
|
7
|
-
`)}else if(
|
|
8
|
-
${
|
|
6
|
+
`}async function v(p,l){if(p.text)process.stdout.write(p.text);if(!p.files||p.files.length===0)return;if(l)for(let m of p.files){let k=m.path?`${l}/${m.path}`:l;await Bun.write(k,m.content),process.stdout.write(`wrote ${k}
|
|
7
|
+
`)}else if(p.files.length===1)process.stdout.write(p.files[0].content);else for(let m of p.files)process.stdout.write(`--- ${m.path??"(unnamed)"} ---
|
|
8
|
+
${m.content}
|
|
9
9
|
`)}var ee=`ostia run [flags] <command...>
|
|
10
10
|
|
|
11
11
|
Run one or more commands N times with warmup and report timing statistics.
|
|
@@ -49,9 +49,21 @@ Flags:
|
|
|
49
49
|
Concurrent CPU-bound processes contend for cores, caches and turbo
|
|
50
50
|
headroom, so numbers taken at --jobs > 1 are noisier and not
|
|
51
51
|
like-for-like with a baseline measured at 1. "auto" = CPU count.
|
|
52
|
-
--gc Bun.gc(true) between trials (default: off - hides allocation cost)
|
|
52
|
+
--gc Bun.gc(true) between trials (default: off - hides allocation cost).
|
|
53
|
+
Per-task { gc } / per-group { gc } override this default.
|
|
53
54
|
--filter REGEX only run tasks whose "group/name" id matches this regex (substring,
|
|
54
55
|
case-sensitive; unmatched tasks are skipped, not timed)
|
|
56
|
+
--isolate give every task its own subprocess instead of sharing its suite
|
|
57
|
+
file's, isolating JIT tier state and heap shape between tasks the
|
|
58
|
+
way suite files are already isolated from each other. Per-task
|
|
59
|
+
{ isolate } / per-group { isolate } override this default.
|
|
60
|
+
--jobs then pools across those per-task processes, so pair a
|
|
61
|
+
higher --jobs with --isolate deliberately: overhead now scales
|
|
62
|
+
with task count, not file count.
|
|
63
|
+
--preload PATH script imported before each suite file loads, in the same
|
|
64
|
+
subprocess (repeatable; runs in the order given). Use it to
|
|
65
|
+
install globals (jsdom's document/window) or register a
|
|
66
|
+
Bun.plugin() file-loader before the suite's own code runs.
|
|
55
67
|
--out-dir PATH directory for scratch IPC files (default: node_modules/.cache/ostia)
|
|
56
68
|
--export-json PATH write the full ProfileDocument to PATH
|
|
57
69
|
--format FORMAT table | json | jsonl | markdown | minimal (default: table)
|
|
@@ -68,16 +80,28 @@ Suite files register tasks like:
|
|
|
68
80
|
task("small input", () => parse(smallBuf))
|
|
69
81
|
task("full pipeline", () => build(), { timeBudgetMs: 2000, minSamples: 10 })
|
|
70
82
|
}, { description: "parser throughput on representative inputs" })
|
|
71
|
-
Per-task options override --time-budget / --min-samples for that task
|
|
83
|
+
Per-task options override --time-budget / --min-samples / --gc / --isolate for that task
|
|
84
|
+
only; per-group { gc } / { isolate } set the default for every task in that group.
|
|
72
85
|
Optional { description } on group() and task() flows into the document (Workload.description
|
|
73
86
|
/ Workload.groupDescription) so the intent travels with the numbers.
|
|
74
87
|
|
|
88
|
+
Sweep a size dimension with range(start, end, multiplier?) (mitata's .range() point
|
|
89
|
+
generation, default multiplier 8, always ending on the end value):
|
|
90
|
+
import { group, task, range } from "<pkg>"
|
|
91
|
+
group("parse", () => {
|
|
92
|
+
for (const size of range(100, 10_000)) {
|
|
93
|
+
const input = buildInput(size) // setup, runs once per point, unmeasured
|
|
94
|
+
task(\`\${size} items\`, () => parse(input))
|
|
95
|
+
}
|
|
96
|
+
})
|
|
97
|
+
|
|
75
98
|
Examples:
|
|
76
99
|
ostia bench benches/parse.ts
|
|
77
100
|
ostia bench --time-budget 1000 --min-samples 50 benches/*.ts
|
|
78
101
|
ostia bench benches/*.ts --filter parse
|
|
79
102
|
ostia bench benches/*.ts --jobs auto --format minimal
|
|
80
|
-
|
|
103
|
+
ostia bench --preload ./bench/jsdom-setup.ts benches/*.dom.bench.ts
|
|
104
|
+
`,Z=`ostia compare <base.json> <candidate.json>
|
|
81
105
|
ostia compare <candidate.json> --baseline <path.json>
|
|
82
106
|
|
|
83
107
|
Compare two ProfileDocuments (matched by workload id) and rank timing/frame/heap deltas.
|
|
@@ -129,22 +153,22 @@ Flags:
|
|
|
129
153
|
--help show this message
|
|
130
154
|
|
|
131
155
|
Exit codes: 0 pass, 1 regression, 2 harness error (missing config/baseline, spawn failure).
|
|
132
|
-
`;function oe(
|
|
133
|
-
`),2;let
|
|
134
|
-
`),2}if(l.exportJson)await o(
|
|
156
|
+
`;function oe(p){let l=[],m,k,h=!1,b=!1,P,C,F,D="table",A=!1,E=!1;for(let N=0;N<p.length;N++){let j=p[N];switch(j){case"--runs":m=Number(p[++N]);break;case"--warmup":k=Number(p[++N]);break;case"--cpu":h=!0;break;case"--heap":b=!0;break;case"--cpu-interval":P=Number(p[++N]);break;case"--out-dir":C=p[++N];break;case"--export-json":F=p[++N];break;case"--format":D=p[++N];break;case"--quiet":A=!0;break;case"--help":case"-h":E=!0;break;default:l.push(j)}}return{commands:l,runs:m,warmup:k,cpu:h,heap:b,cpuIntervalUs:P,outDir:C,exportJson:F,format:D,quiet:A,help:E}}async function ae(p){let l=oe(p);if(l.help||l.commands.length===0)return process.stdout.write(ee),l.help?0:2;if(!(l.format in n))return process.stderr.write(`Unknown --format "${l.format}". Expected one of: ${Object.keys(n).join(", ")}
|
|
157
|
+
`),2;let m;try{m=await y({commands:l.commands,runs:l.runs,warmup:l.warmup,cpu:l.cpu,heap:l.heap,cpuIntervalUs:l.cpuIntervalUs,outDir:l.outDir})}catch(h){return process.stderr.write(`Run failed: ${h instanceof Error?h.message:String(h)}
|
|
158
|
+
`),2}if(l.exportJson)await o(m,l.exportJson);if(!l.quiet){let b=await n[l.format].render(m,{});await v(b)}return m.runs.some((h)=>h.trials.some((b)=>b.exitCode!==void 0&&b.exitCode!==0))?1:0}function ie(p){let l=[],m,k,h,b=!1,P,C=!1,F=[],D,A,E="table",N=!1,j=!1;for(let R=0;R<p.length;R++){let S=p[R];switch(S){case"--time-budget":m=Number(p[++R]);break;case"--min-samples":k=Number(p[++R]);break;case"--jobs":{let I=p[++R];h=I==="auto"?x():Number(I);break}case"--gc":b=!0;break;case"--filter":P=p[++R];break;case"--isolate":C=!0;break;case"--preload":F.push(p[++R]);break;case"--out-dir":D=p[++R];break;case"--export-json":A=p[++R];break;case"--format":E=p[++R];break;case"--quiet":N=!0;break;case"--help":case"-h":j=!0;break;default:l.push(S)}}return{suites:l,timeBudgetMs:m,minSamples:k,jobs:h,gc:b,filter:P,isolate:C,preload:F,outDir:D,exportJson:A,format:E,quiet:N,help:j}}async function ue(p){let l=ie(p);if(l.help||l.suites.length===0)return process.stdout.write(te),l.help?0:2;if(!(l.format in n))return process.stderr.write(`Unknown --format "${l.format}". Expected one of: ${Object.keys(n).join(", ")}
|
|
135
159
|
`),2;if(l.jobs!==void 0&&!(l.jobs>=1))return process.stderr.write(`--jobs expects a positive integer or "auto".
|
|
136
|
-
`),2;let
|
|
137
|
-
`),2}if(l.exportJson)await o(
|
|
138
|
-
`),2}let
|
|
139
|
-
`),2}let
|
|
140
|
-
`),2;let
|
|
141
|
-
`),2}let
|
|
160
|
+
`),2;let m;try{m=await d({suites:l.suites,timeBudgetMs:l.timeBudgetMs,minSamples:l.minSamples,jobs:l.jobs,gc:l.gc,filter:l.filter,isolate:l.isolate,preload:l.preload,outDir:l.outDir})}catch(k){return process.stderr.write(`Bench failed: ${k instanceof Error?k.message:String(k)}
|
|
161
|
+
`),2}if(l.exportJson)await o(m,l.exportJson);if(!l.quiet){let h=await n[l.format].render(m,{});await v(h)}return 0}function le(p){let l=[],m,k,h="table",b=!1,P=!1;for(let C=0;C<p.length;C++){let F=p[C];switch(F){case"--baseline":m=p[++C];break;case"--export-json":k=p[++C];break;case"--format":h=p[++C];break;case"--quiet":b=!0;break;case"--help":case"-h":P=!0;break;default:l.push(F)}}return{paths:l,baseline:m,exportJson:k,format:h,quiet:b,help:P}}async function ce(p){let l=le(p);if(l.help)return process.stdout.write(Z),0;let m,k;if(l.baseline)m=l.baseline,k=l.paths[0];else m=l.paths[0],k=l.paths[1];if(!m||!k)return process.stdout.write(Z),2;let h,b;try{[h,b]=await Promise.all([t(m),t(k)])}catch(D){return process.stderr.write(`Failed to load documents: ${D instanceof Error?D.message:String(D)}
|
|
162
|
+
`),2}let P=f(h,b),C={...b,comparisons:P};if(l.exportJson)await o(C,l.exportJson);if(!l.quiet){let A=await n[l.format].render(C,{});await v(A)}return P.some((D)=>D.verdict==="fail")?1:0}function de(p){let l,m="table",k=!1;for(let h=0;h<p.length;h++){let b=p[h];switch(b){case"--format":m=p[++h];break;case"--help":case"-h":k=!0;break;default:l=b}}return{path:l,format:m,help:k}}async function pe(p){let l=de(p);if(l.help||!l.path)return process.stdout.write(re),l.help?0:2;let m;try{m=await t(l.path)}catch(b){return process.stderr.write(`Failed to load ${l.path}: ${b instanceof Error?b.message:String(b)}
|
|
163
|
+
`),2}let h=await n[l.format].render(m,{});return await v(h),0}var me={ascii:"table"};function fe(p){let l,m,k,h,b=!1;for(let P=0;P<p.length;P++){let C=p[P];switch(C){case"--format":{let F=p[++P]??"";m=me[F]??F;break}case"--run":k=p[++P];break;case"--out-dir":h=p[++P];break;case"--help":case"-h":b=!0;break;default:l=C}}return{path:l,format:m,runId:k,outDir:h,help:b}}async function he(p){let l=fe(p);if(l.help||!l.path||!l.format)return process.stdout.write(se),l.help?0:2;if(!(l.format in n))return process.stderr.write(`Unknown --format "${l.format}". Expected one of: ${Object.keys(n).join(", ")}, ascii
|
|
164
|
+
`),2;let m;try{m=await t(l.path)}catch(b){return process.stderr.write(`Failed to load ${l.path}: ${b instanceof Error?b.message:String(b)}
|
|
165
|
+
`),2}let h=await n[l.format].render(m,{runId:l.runId});if(!h.text&&(!h.files||h.files.length===0))return process.stderr.write(l.runId?`No CPU evidence found for run "${l.runId}".
|
|
142
166
|
`:`No CPU evidence found in this document (no cpu-phase runs). Capture some with "ostia run --cpu ...".
|
|
143
|
-
`),2;return await
|
|
144
|
-
`),2;if(
|
|
145
|
-
`),2;let
|
|
146
|
-
`),2;return process.stderr.write(`CI run failed: ${
|
|
147
|
-
`),2}if(l.exportJson)await o(
|
|
167
|
+
`),2;return await v(h,l.outDir),0}function ge(p){let l=!1,m,k,h=!1,b=!1;for(let P=0;P<p.length;P++)switch(p[P]){case"--full":l=!0;break;case"--baseline":m=p[++P];break;case"--export-json":k=p[++P];break;case"--quiet":h=!0;break;case"--help":case"-h":b=!0;break}return{full:l,baseline:m,exportJson:k,quiet:h,help:b}}async function be(p){let l=ge(p);if(l.help)return process.stdout.write(ne),0;let m=await W();if(!m)return process.stderr.write(`No ostia.config.json found. "ostia ci" needs configured workloads.
|
|
168
|
+
`),2;if(m.workloads.length===0)return process.stderr.write(`ostia.config.json has no "workloads" configured.
|
|
169
|
+
`),2;let k;try{k=await K({config:m,full:l.full,baselineName:l.baseline})}catch(h){if(h instanceof B)return process.stderr.write(`${h.message}
|
|
170
|
+
`),2;return process.stderr.write(`CI run failed: ${h instanceof Error?h.message:String(h)}
|
|
171
|
+
`),2}if(l.exportJson)await o(k.document,l.exportJson);if(!l.quiet)process.stdout.write(G(k.summary));return k.summary.regressed>0?1:0}async function we(){let[p,...l]=process.argv.slice(2);switch(p){case"run":return ae(l);case"bench":return ue(l);case"compare":return ce(l);case"report":return pe(l);case"ci":return be(l);case"viz":return he(l);case void 0:case"--help":case"-h":return process.stdout.write(`ostia - Bun-native profile IR engine
|
|
148
172
|
|
|
149
173
|
Commands:
|
|
150
174
|
run Run commands N times and report timing/CPU/heap
|
|
@@ -155,5 +179,5 @@ Commands:
|
|
|
155
179
|
viz Render CPU evidence as collapsed/mermaid/speedscope/cpuprofile
|
|
156
180
|
|
|
157
181
|
Run "ostia <command> --help" for details.
|
|
158
|
-
`),
|
|
159
|
-
`),2}}if(import.meta.main)we().then((
|
|
182
|
+
`),p===void 0?2:0;default:return process.stderr.write(`Unknown subcommand "${p}". Run "ostia --help".
|
|
183
|
+
`),2}}if(import.meta.main)we().then((p)=>process.exit(p));
|
package/index.d.ts
CHANGED
|
@@ -63,6 +63,10 @@ export interface Workload {
|
|
|
63
63
|
/** The enclosing group's `group(name, fn, { description })`. Repeated on every
|
|
64
64
|
* workload in the group so each record is self-contained. */
|
|
65
65
|
groupDescription?: string;
|
|
66
|
+
/** Whether this task ran in a subprocess dedicated to it alone (`isolate`
|
|
67
|
+
* on the task, its group, or the suite), vs. sharing its suite file's
|
|
68
|
+
* subprocess with other tasks. */
|
|
69
|
+
isolated?: boolean;
|
|
66
70
|
}
|
|
67
71
|
|
|
68
72
|
type Phase = "timing" | "cpu" | "heap" | "memstats";
|
|
@@ -238,14 +242,33 @@ interface BenchOptions {
|
|
|
238
242
|
* 1). Files are independent by design, so this is a wall-clock win for
|
|
239
243
|
* multi-file suites, but concurrent CPU-bound processes contend for cores,
|
|
240
244
|
* caches, memory bandwidth and turbo headroom: timings taken under `jobs > 1`
|
|
241
|
-
* are noisier and not like-for-like with a baseline measured at 1.
|
|
245
|
+
* are noisier and not like-for-like with a baseline measured at 1. When
|
|
246
|
+
* `isolate` puts some tasks in their own subprocess, `jobs` pools across
|
|
247
|
+
* those per-task processes the same way - so the same noise/wall-clock
|
|
248
|
+
* tradeoff now scales with task count, not just file count. */
|
|
242
249
|
jobs?: number;
|
|
243
250
|
outDir?: string;
|
|
244
251
|
cwd?: string;
|
|
252
|
+
/** Give every task its own subprocess instead of sharing its suite file's,
|
|
253
|
+
* isolating each task's JIT tier state, inline caches and heap shape from
|
|
254
|
+
* every other task the way suite files are already isolated from each
|
|
255
|
+
* other. `TaskOptions.isolate` / `GroupOptions.isolate` override this per
|
|
256
|
+
* task or group for mixed suites (e.g. a few outlier-prone tasks isolated,
|
|
257
|
+
* many cheap ones sharing a process). Multiplies process-spawn overhead by
|
|
258
|
+
* task count instead of file count. */
|
|
259
|
+
isolate?: boolean;
|
|
260
|
+
/** Scripts run, in order, before each suite file loads - in the same
|
|
261
|
+
* subprocess, so they can install globals (jsdom's `document`/`window`) or
|
|
262
|
+
* register a `Bun.plugin()` file-loader (e.g. for `.svelte`/`.vue`) ahead
|
|
263
|
+
* of the suite's own top-level code. Consumer-authored; ostia ships no
|
|
264
|
+
* preload scripts itself. */
|
|
265
|
+
preload?: string[];
|
|
245
266
|
}
|
|
246
267
|
|
|
247
268
|
export declare function bench(opts: BenchOptions): Promise<ProfileDocument>;
|
|
248
269
|
|
|
270
|
+
export declare function range(start: number, end: number, multiplier?: number): number[];
|
|
271
|
+
|
|
249
272
|
export interface TaskOptions {
|
|
250
273
|
/** Marks this task as the Relative reference for its group in the table
|
|
251
274
|
* renderer, mirroring mitata's `baseline()`. At most one per group. */
|
|
@@ -258,12 +281,26 @@ export interface TaskOptions {
|
|
|
258
281
|
/** What this task measures and why. Flows into `Workload.description` so the
|
|
259
282
|
* intent travels with the numbers instead of living only in a source comment. */
|
|
260
283
|
description?: string;
|
|
284
|
+
/** Give this task its own subprocess instead of sharing its suite file's,
|
|
285
|
+
* isolating its JIT tier state and heap shape from every other task in the
|
|
286
|
+
* run. Overrides the group's and the suite-wide `bench({ isolate })` /
|
|
287
|
+
* `--isolate` default for this task only. */
|
|
288
|
+
isolate?: boolean;
|
|
289
|
+
/** Overrides the suite-wide `bench({ gc })` / `--gc` (and any
|
|
290
|
+
* `GroupOptions.gc`) for this task only. */
|
|
291
|
+
gc?: boolean;
|
|
261
292
|
}
|
|
262
293
|
|
|
263
294
|
export interface GroupOptions {
|
|
264
295
|
/** What this group measures and why. Flows into `Workload.groupDescription`
|
|
265
296
|
* on every task in the group. */
|
|
266
297
|
description?: string;
|
|
298
|
+
/** Default `isolate` for every task in this group, unless a task overrides
|
|
299
|
+
* it with its own `TaskOptions.isolate`. */
|
|
300
|
+
isolate?: boolean;
|
|
301
|
+
/** Default `gc` for every task in this group, unless a task overrides it
|
|
302
|
+
* with its own `TaskOptions.gc`. */
|
|
303
|
+
gc?: boolean;
|
|
267
304
|
}
|
|
268
305
|
|
|
269
306
|
export declare function group(name: string, fn: () => void, opts?: GroupOptions): void;
|
package/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import{
|
|
2
|
+
import{d,f,F,n,y,S}from"./chunk-tw064qem.js";import{o,t,U,M}from"./chunk-nfgy545q.js";export{d as bench,f as compareDocuments,U as group,t as loadDocument,S as profile,F as range,n as renderers,y as run,o as saveDocument,M as task};
|
package/package.json
CHANGED
package/runner.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
// @bun
|
|
3
|
-
import{r,P,i,s,o,l,
|
|
4
|
-
`),2;let
|
|
5
|
-
`),2;let f=
|
|
6
|
-
`),2;let
|
|
3
|
+
import{r,P,i,s,o,l,p,I,C,m,N,D,v}from"./chunk-nfgy545q.js";var z=500,H=20,A=3,j=10,X=2,q=0.1,K=1000,Q=1e4;function J(n){let e=Math.log10(Math.max(1,n)/1e6),a=Math.round(A+X*e);return Math.min(j,Math.max(A,a))}function V(n,e){let a=Math.floor(e/n);return Math.min(H,Math.max(a,J(n)))}var L=0;function O(n){if(typeof n==="number")L+=n;else if(n!==void 0&&n!==null)L+=1}function B(n){return n!==null&&typeof n==="object"&&typeof n.then==="function"}function G(n,e){return Math.max(1,Math.ceil(K/n),Math.ceil(e/(n*Q)))}async function U(n,e={}){let a=(e.timeBudgetMs??z)*1e6,u=a*(e.warmupFraction??q),T=Bun.nanoseconds(),f=0,b=0;while(b<u){let d=n();O(B(d)?await d:d),f++,b=Bun.nanoseconds()-T}let h;if(f>0)h=Math.max(1,b/f);else{let d=Bun.nanoseconds(),w=n();O(B(w)?await w:w),h=Math.max(1,Bun.nanoseconds()-d)}let t=G(h,a);if(t>1){let d=Bun.nanoseconds();for(let w=0;w<t;w++){let k=n();O(B(k)?await k:k)}h=Math.max(1,(Bun.nanoseconds()-d)/t),t=G(h,a)}let c=h*t,S=e.minSamples??V(c,a),g=[],M=Bun.nanoseconds(),_=0,R=0;while(R<S||_<a){let d=Bun.nanoseconds();for(let k=0;k<t;k++){let F=n();O(B(F)?await F:F)}let w=Bun.nanoseconds();if(g.push({i:R,wallNs:(w-d)/t}),R++,_=Bun.nanoseconds()-M,e.gc)Bun.gc(!0)}let W=g.map((d)=>d.wallNs),y=l(W),E=p(y,[],"inprocess"),x=J(c);if(g.length<x)E.push({code:"low-sample-count",message:`Only ${g.length} sample(s) at ~${Y(c)} per trial; ${x} is the floor for this cost class. Raise minSamples or the time budget for a steadier number.`,data:{samples:g.length,target:x,trialCostNs:c}});return{trials:g,timing:y,warnings:E}}function Y(n){if(n>=1e9)return`${(n/1e9).toFixed(2)}s`;if(n>=1e6)return`${(n/1e6).toFixed(1)}ms`;if(n>=1000)return`${(n/1000).toFixed(1)}\xB5s`;return`${n.toFixed(0)}ns`}async function Z(){let[n,e,a]=process.argv.slice(2);if(!n||!e)return process.stderr.write(`bench runner: usage: runner.ts <suiteFile> <outputPath> [optsJson]
|
|
4
|
+
`),2;let u=a?JSON.parse(a):{};for(let t of u.preload??[])await import(t);C(),await import(n);let T=I();if(T.length===0)return process.stderr.write(`bench runner: ${n} registered no tasks (no task() calls found).
|
|
5
|
+
`),2;let f=v(T,u.filter);if(u.taskIds){let t=new Set(u.taskIds);f=f.filter((c)=>t.has(m(c)))}if(f.length===0)return process.stderr.write(`bench runner: --filter ${JSON.stringify(u.filter)} matched zero of ${T.length} registered tasks in ${n}.
|
|
6
|
+
`),2;if(u.planOnly){let t=f.map((c)=>({id:m(c),isolate:N(c,u.isolate??!1)}));return await Bun.write(e,JSON.stringify({tasks:t})),0}let b=[],h=[];for(let t of f){let c=m(t),S=P(n,c,{label:c,baseline:t.baseline,group:t.groupName,description:t.opts?.description,groupDescription:t.groupDescription,isolated:u.markIsolated});b.push(S);let g={...u,...t.opts?.timeBudgetMs!==void 0&&{timeBudgetMs:t.opts.timeBudgetMs},...t.opts?.minSamples!==void 0&&{minSamples:t.opts.minSamples},gc:D(t,u.gc??!1)},M=await U(t.fn,g);h.push(i({workload:S,configFingerprint:s({timeBudgetMs:g.timeBudgetMs??null,minSamples:g.minSamples??null,gc:g.gc??!1}),trials:M.trials,timing:M.timing,warnings:M.warnings}))}return await o(r(b,h),e),0}Z().then((n)=>process.exit(n));
|
package/chunk-3rp84rbb.js
DELETED
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
function g(n){return JSON.stringify(O(n))}function O(n){if(Array.isArray(n))return n.map(O);if(n!==null&&typeof n==="object"){let a={};for(let d of Object.keys(n).sort())a[d]=O(n[d]);return a}return n}function e(n,...a){let d=Bun.CryptoHasher.hash("sha256",g(a),"hex");return`${n}_${d.slice(0,16)}`}var c="0.1.0";function r(n,a){return{schemaVersion:1,toolVersion:c,bunVersion:Bun.version,platform:{os:process.platform,arch:process.arch},createdAt:new Date().toISOString(),workloads:n,runs:a}}function u(n,a){return{id:e("wl","subprocess",n,process.cwd()),kind:"subprocess",command:n,label:a}}function R(n,a){return{id:e("wl","inprocess",n.name,n.toString()),kind:"inprocess",label:a}}function P(n,a,d={}){return{id:e("wl","inprocess-entry",n,a),kind:"inprocess",entry:{file:n,task:a,...d.group!==void 0&&{group:d.group}},...d.label!==void 0&&{label:d.label},...d.baseline!==void 0&&{baseline:d.baseline},...d.description!==void 0&&{description:d.description},...d.groupDescription!==void 0&&{groupDescription:d.groupDescription}}}function i(n){return{id:e("run",n.workload.id,"timing",n.configFingerprint,Bun.version,c),workloadId:n.workload.id,phase:"timing",instrumented:!1,configFingerprint:n.configFingerprint,trials:n.trials,timing:n.timing,warnings:n.warnings,artifacts:[],memory:U(n.trials)}}function U(n){let a=n.map((d)=>d.maxRssBytes).filter((d)=>d!==void 0);if(a.length===0)return;return{origin:"resourceUsage",perTrial:n.map((d)=>({rssBytes:d.maxRssBytes})),maxRssBytes:Math.max(...a)}}function h(n){return{id:e("run",n.workload.id,n.phase,n.configFingerprint,Bun.version,c),workloadId:n.workload.id,phase:n.phase,instrumented:!0,configFingerprint:n.configFingerprint,trials:[{i:0,wallNs:n.diagnosticWallNs,exitCode:n.exitCode}],diagnosticWallNs:n.diagnosticWallNs,cpu:n.cpu,heap:n.heap,jit:n.jit,warnings:n.warnings,artifacts:n.artifacts}}async function T(n,a,d){let p=await Bun.file(d).arrayBuffer(),k=new Bun.CryptoHasher("sha256");return k.update(p),{id:e("art",n,a,d),kind:a,path:d,sha256:k.digest("hex"),bytes:p.byteLength}}function s(n){return e("cfg",n)}function y(n){return`${JSON.stringify(O(n),null,2)}
|
|
3
|
-
`}async function o(n,a){await Bun.write(a,y(n))}async function t(n){let a=await Bun.file(n).text();return JSON.parse(a)}var _=[],S;function F(n,a,d){let f=S;S={name:n,description:d?.description};try{a()}finally{S=f}}function v(n,a,d){_.push({groupName:S?.name,groupDescription:S?.description,name:n,fn:a,baseline:d?.baseline,opts:d})}function C(){return _}function N(){_.length=0,S=void 0}function x(n){return n.groupName?`${n.groupName}/${n.name}`:n.name}function D(n,a){if(!a)return[...n];let d=new RegExp(a);return n.filter((f)=>d.test(x(f)))}function l(n){if(n.length===0)throw Error("computeTimingStats: samples must be non-empty");let a=n.length,d=L(n),f=0;for(let b=0;b<a;b++)f+=n[b];let p=f/a,k=B(d,0.5),w=0;for(let b=0;b<a;b++){let W=n[b]-p;w+=W*W}let M=Math.sqrt(w/a),H=d[0],E=d[a-1],A=B(d,0.25),q=B(d,0.75),I=q-A,z=A-1.5*I,V=q+1.5*I,G=A-3*I,K=q+3*I,J=0,j=0;for(let b=0;b<a;b++){let W=n[b];if(W<G||W>K)j++;else if(W<z||W>V)J++}return{unit:"ns",samples:n,mean:p,median:k,stddev:M,min:H,max:E,outliers:{mild:J,severe:j}}}function L(n){let a=new Float64Array(n.length);return a.set(n),a.sort(),a}function B(n,a){let d=n.length;if(d===1)return n[0];let f=a*(d-1),p=Math.floor(f),k=Math.ceil(f);if(p===k)return n[p];let w=f-p;return n[p]*(1-w)+n[k]*w}var Z=5000000,Q=200;function m(n,a,d="subprocess"){let f=[],p=n.samples[0];if(p!==void 0){let w=L(n.samples),M=B(w,0.25),E=B(w,0.75)-M;if(p>n.median+3*E&&E>0)f.push({code:"slow-first-run",message:`First run took ${(p/1e6).toFixed(2)}ms, much slower than the median ${(n.median/1e6).toFixed(2)}ms. Consider more warmup.`,data:{firstNs:p,medianNs:n.median}})}if(n.outliers.mild+n.outliers.severe>0)f.push({code:"outliers-detected",message:`${n.outliers.mild+n.outliers.severe} outlier(s) detected (${n.outliers.severe} severe, ${n.outliers.mild} mild).`,data:n.outliers});if(d==="subprocess"&&n.median<Z)f.push({code:"fast-command",message:`Median run time (${(n.median/1e6).toFixed(3)}ms) is very fast; results may be dominated by spawn overhead.`,data:{medianNs:n.median}});if(d==="inprocess"&&n.median<Q)f.push({code:"below-timer-resolution",message:`Median run time (${n.median.toFixed(0)}ns) is close to timer resolution; consider a larger batch size or a coarser operation.`,data:{medianNs:n.median}});let k=a.filter((w)=>w!==void 0&&w!==0);if(k.length>0)f.push({code:"nonzero-exit",message:`${k.length} of ${a.length} trial(s) exited non-zero.`,data:{exitCodes:k}});return f}
|
|
4
|
-
export{g,e,c,r,u,R,P,i,h,T,s,y,o,t,l,m,F,v,C,N,x,D};
|
package/chunk-s1d2tx3w.js
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
// @bun
|
|
2
|
-
import{g,e,r,u,R,i,h,T,s,y,t,l,m}from"./chunk-3rp84rbb.js";function Ae(o){return o.startsWith("file://")?o.slice(7):o}function oe(o,D,c){let C=o.nodes,x=C.length,v=new Map,N=[],P=new Map,U=new Int32Array(x);for(let W=0;W<x;W++){let O=C[W],S=O.callFrame,_=Ae(S.url),K=v.get(S.functionName);if(K===void 0)K=new Map,v.set(S.functionName,K);let G=K.get(_);if(G===void 0)G=N.length,K.set(_,G),N.push({key:e("fr",S.functionName,_),name:S.functionName,url:_||void 0,line:S.lineNumber>=0?S.lineNumber:void 0,col:S.columnNumber>=0?S.columnNumber:void 0});U[W]=G,P.set(O.id,W)}let M=Array(x);for(let W=0;W<x;W++){let O=C[W];M[W]={id:O.id,frameIx:U[P.get(O.id)],children:O.children??[]}}let F=new Float64Array(x),B=new Float64Array(x),{samples:A,timeDeltas:J}=o;for(let W=0;W<A.length;W++){let O=P.get(A[W]);if(O===void 0)continue;F[O]+=J[W]??0,B[O]+=1}let H=new Int32Array(x).fill(-1);for(let W=0;W<x;W++){let O=C[W].children;if(!O)continue;for(let S of O){let _=P.get(S);if(_!==void 0)H[_]=W}}let E=[],L=[];for(let W=x-1;W>=0;W--)if(H[W]===-1)L.push(W);while(L.length>0){let W=L.pop();E.push(W);let O=C[W].children;if(!O)continue;for(let S of O){let _=P.get(S);if(_!==void 0&&H[_]===W)L.push(_)}}let V=new Float64Array(x);for(let W=E.length-1;W>=0;W--){let O=E[W];V[O]+=F[O];let S=H[O];if(S>=0)V[S]+=V[O]}let z=Array(N.length),j=[];for(let W=0;W<x;W++){let O=M[W].frameIx,S=z[O];if(S)S.selfUs+=F[W],S.totalUs+=V[W],S.samples+=B[W];else{let _={frameIx:O,selfUs:F[W],totalUs:V[W],samples:B[W]};z[O]=_,j.push(_)}}return{origin:D,samplingIntervalUs:c,frames:N,nodes:M,totals:j.sort((W,O)=>O.selfUs-W.selfUs),samples:{nodeIds:o.samples,timeDeltasUs:o.timeDeltas}}}function je(o,D,c,C){let x=["--cpu-prof","--cpu-prof-dir",D,"--cpu-prof-name",c,"--cpu-prof-interval",String(C)],v=o[0];if(v==="bun"||v?.endsWith("/bun"))return[v,...x,...o.slice(1)];return o}async function de(o){let D=`${o.artifactDir}/${o.fileName}`,c=o.argv[0],C=c==="bun"||c?.endsWith("/bun"),x=je(o.argv,o.artifactDir,o.fileName,o.intervalUs),v=C?o.env:{...process.env,...o.env,BUN_OPTIONS:`--cpu-prof --cpu-prof-dir ${o.artifactDir} --cpu-prof-name ${o.fileName} --cpu-prof-interval ${o.intervalUs}`},N=Bun.nanoseconds(),U=await Bun.spawn(x,{cwd:o.cwd,env:v,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,M=Bun.nanoseconds()-N,F=Bun.file(D);if(!await F.exists())return{diagnosticWallNs:M,exitCode:U,warnings:[{code:"artifact-missing",message:`Expected a .cpuprofile at ${D} after exit ${U}, found nothing. The workload's argv[0] must be a \`bun\` binary for CPU capture.`,data:{artifactPath:D,argv:o.argv}}]};let B=await F.json(),A=oe(B,"cpu-prof",o.intervalUs),J=B.samples.length===0?[{code:"empty-profile",message:"CPU capture produced zero samples."}]:[];return{diagnosticWallNs:M,exitCode:U,artifactPath:D,cpu:A,warnings:J}}function fe(o,D="heap-prof"){let{node_fields:c,node_types:C}=o.snapshot.meta,x=c.indexOf("type"),v=c.indexOf("self_size"),N=c.length,P=C[0];if(x===-1||v===-1||!Array.isArray(P))return{origin:D,typeCounts:[],objectCount:o.snapshot.node_count};let U=P.length,M=Array(U),F=new Map,B=[],A=0,J=o.nodes,H=J.length;for(let j=0;j<H;j+=N){let W=J[j+x],O=J[j+v]??0;A+=O;let S;if(W>=0&&W<U){if(S=M[W],S===void 0)S={type:P[W],count:0,bytes:0},M[W]=S,B.push(S)}else{let _=`unknown(${W})`;if(S=F.get(_),S===void 0)S={type:_,count:0,bytes:0},F.set(_,S),B.push(S)}S.count++,S.bytes+=O}let E=B.sort((j,W)=>W.count-j.count),L=E.slice(0,20),V=E.slice(20),z=L.map(({type:j,count:W,bytes:O})=>({type:j,count:W,retainedBytes:O}));if(V.length>0){let j=0,W=0;for(let O of V)j+=O.count,W+=O.bytes;z.push({type:"other",count:j,retainedBytes:W})}return{origin:D,heapSizeBytes:A,objectCount:o.snapshot.node_count,typeCounts:z}}function _e(o,D,c){let C=["--heap-prof","--heap-prof-dir",D,"--heap-prof-name",c],x=o[0];if(x==="bun"||x?.endsWith("/bun"))return[x,...C,...o.slice(1)];return o}async function ge(o){let D=`${o.artifactDir}/${o.fileName}`,c=o.argv[0],C=c==="bun"||c?.endsWith("/bun"),x=_e(o.argv,o.artifactDir,o.fileName),v=C?o.env:{...process.env,...o.env,BUN_OPTIONS:`--heap-prof --heap-prof-dir ${o.artifactDir} --heap-prof-name ${o.fileName}`},N=Bun.nanoseconds(),U=await Bun.spawn(x,{cwd:o.cwd,env:v,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,M=Bun.nanoseconds()-N,F=Bun.file(D);if(!await F.exists())return{diagnosticWallNs:M,exitCode:U,warnings:[{code:"artifact-missing",message:`Expected a heap snapshot at ${D} after exit ${U}, found nothing. The workload's argv[0] must be a \`bun\` binary for heap capture.`,data:{artifactPath:D,argv:o.argv}}]};let B=await F.json(),A=fe(B,"heap-prof");return{diagnosticWallNs:M,exitCode:U,artifactPath:D,heap:A,warnings:[]}}import{Session as Le}from"inspector/promises";var He=1000;async function he(o,D={}){let c=D.intervalUs??He,C=new Le;C.connect();let x=Bun.nanoseconds();try{await C.post("Profiler.enable"),await C.post("Profiler.setSamplingInterval",{interval:c}),await C.post("Profiler.start");let v=await o(),{profile:N}=await C.post("Profiler.stop"),P=Bun.nanoseconds()-x,U=oe(N,"inspector",c);return{result:v,cpu:U,diagnosticWallNs:P}}finally{C.disconnect()}}import{profile as ze}from"bun:jsc";var Je=new Map([["LLInt","llint"],["Baseline","baseline"],["DFG","dfg"],["FTL","ftl"]]),be=4294967295;function ye(o,D){let c=D??o.interval*1e6,C=new Map,x=[];function v(S,_,K,G){let q=C.get(S);if(q===void 0)q=new Map,C.set(S,q);let Y=_??"",X=q.get(Y);if(X===void 0)X=x.length,q.set(Y,X),x.push({key:e("fr",S,Y),name:S,url:_,line:K,col:G});return X}function N(S){let _=S.line===be,K=_?void 0:S.line-1,G=_||S.column===be?void 0:S.column-1;return v(S.name,S.sourceURL,K,G)}let P=v("(root)",void 0,void 0,void 0),U=1,M={id:0,frameIx:P,children:new Map,selfUs:0,samples:0,totalUs:0},F=new Map([[0,M]]),B={llint:0,baseline:0,dfg:0,ftl:0},A=new Map,J=[],H=[];for(let S of o.traces){let _=S.frames,K=M;for(let Y=_.length-1;Y>=0;Y--){let X=N(_[Y]),ne=K.children.get(X);if(!ne)ne={id:U++,frameIx:X,children:new Map,selfUs:0,samples:0,totalUs:0},K.children.set(X,ne),F.set(ne.id,ne);K=ne}K.selfUs+=c,K.samples+=1,J.push(K.id),H.push(c);let G=_[0],q=G&&Je.get(G.category);if(q){B[q]++;let Y=A.get(q)??new Map;Y.set(K.frameIx,(Y.get(K.frameIx)??0)+1),A.set(q,Y)}}function E(S){let _=S.selfUs;for(let K of S.children.values())_+=E(K);return S.totalUs=_,_}E(M);let L=new Map;function V(S){let _=L.get(S.frameIx);if(_)_.selfUs+=S.selfUs,_.totalUs+=S.totalUs,_.samples+=S.samples;else L.set(S.frameIx,{frameIx:S.frameIx,selfUs:S.selfUs,totalUs:S.totalUs,samples:S.samples});for(let K of S.children.values())V(K)}V(M);let z=[...F.values()].map((S)=>({id:S.id,frameIx:S.frameIx,children:[...S.children.values()].map((_)=>_.id)})),j={origin:"jsc-profile",samplingIntervalUs:c,frames:x,nodes:z,totals:[...L.values()].sort((S,_)=>_.selfUs-S.selfUs),samples:{nodeIds:J,timeDeltasUs:H}},W=[...A.entries()].flatMap(([S,_])=>[..._.entries()].sort((K,G)=>G[1]-K[1]).slice(0,3).map(([K,G])=>({tier:S,frameKey:x[K].key,samples:G})));return{cpu:j,jit:{origin:"jsc-profile",tiers:B,topFramesByTier:W}}}var Ve=1000;async function we(o,D={}){let c=D.intervalUs??Ve,C,x=Bun.nanoseconds(),v=await ze(async()=>(C=await o(),C),c),N=Bun.nanoseconds()-x,{cpu:P,jit:U}=ye(v.stackTraces,c);return{result:C,cpu:P,jit:U,diagnosticWallNs:N}}async function ue(o){let D=Bun.nanoseconds(),c=Bun.spawn(o.argv,{cwd:o.cwd,env:o.env,stdout:"ignore",stderr:"ignore",stdin:"ignore"}),C=await c.exited,x=Bun.nanoseconds(),v=c.resourceUsage?.();return{wallNs:x-D,exitCode:C,userNs:v?Number(v.cpuTime.user)*1000:void 0,systemNs:v?Number(v.cpuTime.system)*1000:void 0,maxRssBytes:v?.maxRSS}}function Re(o){return o.trim().split(/\s+/).filter(Boolean)}var Ke=10,Ge=3000000000,Ye=3;async function f(o){let D=o.warmup??Ye;for(let F=0;F<D;F++)await ue(o);let c=[],C=o.runs??o.minRuns??Ke,x=o.runs!==void 0?0:o.minTotalNs??Ge,v=0,N=0;while(N<C||v<x){let F=await ue(o);if(c.push({i:N,wallNs:F.wallNs,exitCode:F.exitCode,userNs:F.userNs,systemNs:F.systemNs,maxRssBytes:F.maxRssBytes}),v+=F.wallNs,N++,o.runs!==void 0&&N>=o.runs)break}let P=c.map((F)=>F.wallNs),U=l(P),M=m(U,c.map((F)=>F.exitCode));return{trials:c,timing:U,warnings:M}}var qe=new URL("./runner.ts",import.meta.url).pathname,Qe="node_modules/.cache/ostia";function k(){return Math.max(1,navigator.hardwareConcurrency||1)}async function p(o){let c=`${o.outDir??Qe}/bench-tmp`,C=o.cwd??process.cwd(),x=Math.max(1,Math.floor(o.jobs??1)),v={timeBudgetMs:o.timeBudgetMs,minSamples:o.minSamples,gc:o.gc,filter:o.filter},N=Array(o.suites.length),P=new Set,U=0,M,F=async(H)=>{let E=o.suites[H],L=E.startsWith("/")?E:`${C}/${E}`,V=`${c}/${e("bench-out",L)}.json`,z=Bun.spawn(["bun",qe,L,V,JSON.stringify(v)],{cwd:C,stdout:"inherit",stderr:"inherit",stdin:"ignore"});P.add(z);let j=await z.exited;if(P.delete(z),j!==0)throw Error(`Bench suite failed: ${E} (runner exited ${j})`);N[H]=await t(V)},B=async()=>{while(M===void 0&&U<o.suites.length){let H=U++;try{await F(H)}catch(E){M??=E instanceof Error?E:Error(String(E));for(let L of P)L.kill()}}};try{if(await Promise.all(Array.from({length:Math.min(x,o.suites.length)},B)),M)throw M}finally{await Bun.spawn(["rm","-rf",c]).exited}let A=[],J=[];for(let H of N)A.push(...H.workloads),J.push(...H.runs);return r(A,J)}var a={timingPct:5,frameSelfPct:10,heapTypePct:10,minFrameSelfUs:1000};function ie(o,D){if(o===0)return D===0?0:1/0;return(D-o)/o*100}function te(o,D,c){return o.runs.find((C)=>C.workloadId===D&&C.phase===c)}function d(o,D,c=a){let C=new Set(D.workloads.map((v)=>v.id)),x=[];for(let v of o.workloads){if(!C.has(v.id))continue;let N=b(o,D,v.id,c);if(N)x.push(N)}return x}function b(o,D,c,C=a){let x=te(o,c,"timing"),v=te(D,c,"timing"),N=te(o,c,"cpu"),P=te(D,c,"cpu"),U=te(o,c,"heap"),M=te(D,c,"heap"),F=x?.id??N?.id??U?.id,B=v?.id??P?.id??M?.id;if(!F||!B)return;let A=!1,J;if(x?.timing&&v?.timing){let L=ie(x.timing.median,v.timing.median),V=ie(x.timing.mean,v.timing.mean),z=L>C.timingPct?"regressed":L<-C.timingPct?"improved":"unchanged";if(z==="regressed")A=!0;J={medianDeltaPct:L,meanDeltaPct:V,verdict:z}}let H;if(N?.cpu&&P?.cpu){let L=new Map(N.cpu.totals.map((O)=>[N.cpu.frames[O.frameIx].key,O])),V=new Map(P.cpu.totals.map((O)=>[P.cpu.frames[O.frameIx].key,O])),z=new Map(N.cpu.frames.map((O)=>[O.key,O.name])),j=new Map(P.cpu.frames.map((O)=>[O.key,O.name]));H=[...new Set([...L.keys(),...V.keys()])].map((O)=>{let S=L.get(O)?.selfUs??0,_=V.get(O)?.selfUs??0;return{frameKey:O,name:j.get(O)??z.get(O)??O,baseSelfUs:S,candSelfUs:_,deltaPct:ie(S,_)}}).sort((O,S)=>Math.abs(S.deltaPct)-Math.abs(O.deltaPct));for(let O of H)if((O.baseSelfUs>=C.minFrameSelfUs||O.candSelfUs>=C.minFrameSelfUs)&&O.deltaPct>C.frameSelfPct)A=!0}let E;if(U?.heap&&M?.heap){let L=new Map(U.heap.typeCounts.map((j)=>[j.type,j])),V=new Map(M.heap.typeCounts.map((j)=>[j.type,j]));E=[...new Set([...L.keys(),...V.keys()])].map((j)=>{let W=L.get(j),O=V.get(j);return{type:j,baseCount:W?.count??0,candCount:O?.count??0,baseBytes:W?.retainedBytes,candBytes:O?.retainedBytes,deltaPct:ie(W?.count??0,O?.count??0)}}).sort((j,W)=>Math.abs(W.deltaPct)-Math.abs(j.deltaPct));for(let j of E)if(j.deltaPct>C.heapTypePct)A=!0}return{id:e("cmp",F,B),baselineRunId:F,candidateRunId:B,timing:J,frames:H,heapTypes:E,thresholds:C,verdict:A?"fail":"pass"}}function Z(o,D){if(D){let c=o.runs.find((C)=>C.id===D);return c?.cpu?[c]:[]}return o.runs.filter((c)=>c.phase==="cpu"&&c.cpu)}function re(o){let D=o.nodes,c=D.length,C=Xe(o),x=new Int32Array(c).fill(-1);for(let U=0;U<c;U++)for(let M of D[U].children){let F=C(M);if(F!==-1)x[F]=U}let v=[];for(let U=0;U<c;U++)if(x[U]===-1)v.push(U);let N=[],P=[];for(let U=v.length-1;U>=0;U--)P.push(v[U]);while(P.length>0){let U=P.pop();N.push(U);for(let M of D[U].children){let F=C(M);if(F!==-1&&x[F]===U)P.push(F)}}return{count:c,indexOf:C,parentIx:x,roots:v,order:N}}function Xe(o){let D=o.nodes,c=D.length,C=1/0,x=-1/0,v=!0;for(let P=0;P<c;P++){let U=D[P].id;if(!Number.isInteger(U)){v=!1;break}if(U<C)C=U;if(U>x)x=U}if(v&&c>0&&x-C<c*4+64){let P=x-C+1,U=new Int32Array(P).fill(-1);for(let M=0;M<c;M++)U[D[M].id-C]=M;return(M)=>{let F=M-C;return F>=0&&F<P?U[F]:-1}}let N=new Map;for(let P=0;P<c;P++)N.set(D[P].id,P);return(P)=>N.get(P)??-1}function xe(o,D){let{count:c,indexOf:C,parentIx:x,order:v}=D,N=new Float64Array(c),P=new Float64Array(c),U=o.samples?.nodeIds??[],M=o.samples?.timeDeltasUs??[];for(let B=0;B<U.length;B++){let A=C(U[B]);if(A===-1)continue;N[A]+=M[B]??0,P[A]+=1}let F=new Float64Array(c);for(let B=v.length-1;B>=0;B--){let A=v[B];F[A]+=N[A];let J=x[A];if(J>=0)F[J]+=F[A]}return{selfUs:N,totalUs:F,samples:P}}var Pe={name:"collapsed",async render(o,D={}){return{files:Z(o,D.runId).map((x)=>{let v=x.cpu,{nodes:N,frames:P}=v,U=re(v),M=Array(U.count);for(let H of U.order){let E=P[N[H].frameIx].name||"(anonymous)",L=U.parentIx[H];M[H]=L===-1?E:`${M[L]};${E}`}let F=new Float64Array(U.count),B=[],A=v.samples?.nodeIds??[];for(let H=0;H<A.length;H++){let E=U.indexOf(A[H]);if(E===-1)continue;if(F[E]++===0)B.push(E)}let J=Array(B.length);for(let H=0;H<B.length;H++){let E=B[H];J[H]=`${M[E]} ${F[E]}`}return{path:`${x.id}.collapsed.txt`,content:J.join(`
|
|
3
|
-
`)+(J.length>0?`
|
|
4
|
-
`:"")}})}}};var Te={name:"cpuprofile",async render(o,D={}){let c=Z(o,D.runId),C=[],x=[];for(let v of c){if(v.cpu?.origin!=="cpu-prof"&&v.cpu?.origin!=="inspector"){x.push(`${v.id} (origin ${v.cpu?.origin??"unknown"} has no .cpuprofile artifact to pass through)`);continue}let N=v.artifacts.find((U)=>U.kind==="cpuprofile");if(!N){x.push(`${v.id} (no cpuprofile artifact recorded on this run)`);continue}let P=Bun.file(N.path);if(!await P.exists()){x.push(`${v.id} (artifact missing on disk: ${N.path})`);continue}C.push({path:`${v.id}.cpuprofile`,content:await P.text()})}if(C.length===0&&x.length>0)return{text:`No .cpuprofile artifacts available:
|
|
5
|
-
${x.map((v)=>` - ${v}`).join(`
|
|
6
|
-
`)}
|
|
7
|
-
`};return{files:C}}};var $e={name:"json",async render(o){return{text:y(o)}}};var ke={name:"jsonl",async render(o){let{runs:D,...c}=o;return{text:`${[g(c),...D.map((x)=>g(x))].join(`
|
|
8
|
-
`)}
|
|
9
|
-
`}}};function ee(o){return(o/1e6).toFixed(3)}function ae(o){return o?.label??o?.command?.join(" ")??o?.entry?.task??o?.id??"unknown"}var ve=10,Ce=10,Ne={name:"markdown",async render(o){let D=new Map(o.workloads.map((x)=>[x.id,x])),c=[];c.push("# Profile Report",""),c.push(`Bun ${o.bunVersion} \xB7 ostia ${o.toolVersion} \xB7 ${o.platform.os}/${o.platform.arch} \xB7 ${o.createdAt}`,"");let C=o.runs.filter((x)=>x.phase==="timing"&&x.timing!==void 0);if(C.length>0){c.push("## Timing",""),c.push("| Command | Mean \xB1 SD (ms) | Min\u2026Max (ms) | Median (ms) |","|---|---|---|---|");for(let v of C){let N=ae(D.get(v.workloadId)),P=v.timing;c.push(`| ${N} | ${ee(P.mean)} \xB1 ${ee(P.stddev)} | ${ee(P.min)}\u2026${ee(P.max)} | ${ee(P.median)} |`)}c.push("");let x=C.filter((v)=>v.warnings.length>0);if(x.length>0){c.push("### Warnings","");for(let v of x){let N=ae(D.get(v.workloadId));for(let P of v.warnings)c.push(`- **${N}**: ${P.message} (\`${P.code}\`)`)}c.push("")}}for(let x of o.runs){if(x.phase!=="cpu"&&x.phase!=="heap")continue;let v=ae(D.get(x.workloadId));if(x.phase==="cpu"){if(c.push(`## CPU capture - ${v}`,""),c.push(`instrumented, diagnostic wall ${ee(x.diagnosticWallNs??0)}ms`,""),x.cpu){c.push(`origin: \`${x.cpu.origin}\`, interval: ${x.cpu.samplingIntervalUs}\xB5s`,""),c.push("| Self % | Self (ms) | Total (ms) | Frame |","|---|---|---|---|");let N=x.cpu.totals.reduce((P,U)=>P+U.selfUs,0)||1;for(let P of x.cpu.totals.slice(0,ve)){let U=x.cpu.frames[P.frameIx],M=(P.selfUs/N*100).toFixed(1);c.push(`| ${M}% | ${(P.selfUs/1000).toFixed(2)} | ${(P.totalUs/1000).toFixed(2)} | ${U?.name||"(anonymous)"} |`)}if(c.push(""),x.jit){let P=x.jit.tiers;c.push(`JIT tiers: LLInt ${P.llint} \xB7 Baseline ${P.baseline} \xB7 DFG ${P.dfg} \xB7 FTL ${P.ftl}`,"")}}}else if(c.push(`## Heap snapshot - ${v}`,""),c.push(`instrumented, diagnostic wall ${ee(x.diagnosticWallNs??0)}ms`,""),x.heap){c.push(`${x.heap.objectCount??"?"} objects, ${((x.heap.heapSizeBytes??0)/1e6).toFixed(2)}MB`,""),c.push("| Count | Type |","|---|---|");for(let N of x.heap.typeCounts.slice(0,Ce))c.push(`| ${N.count} | ${N.type} |`);c.push("")}for(let N of x.artifacts)c.push(`- artifact: \`${N.path}\``);for(let N of x.warnings)c.push(`- ! ${N.message} (\`${N.code}\`)`);if(x.artifacts.length>0||x.warnings.length>0)c.push("")}if(o.comparisons&&o.comparisons.length>0){c.push("## Comparisons","");for(let x of o.comparisons){let v=o.runs.find((P)=>P.id===x.candidateRunId),N=ae(v?D.get(v.workloadId):void 0);if(c.push(`### ${x.verdict==="pass"?"\u2713":"\u2717"} ${N}`,""),x.timing){let P=x.timing.medianDeltaPct>0?"+":"";c.push(`- timing: ${P}${x.timing.medianDeltaPct.toFixed(1)}% median (**${x.timing.verdict}**)`)}for(let P of x.frames?.slice(0,ve)??[]){if(Math.abs(P.deltaPct)<0.5)continue;let U=P.deltaPct>0?"+":"";c.push(`- frame \`${P.name}\`: ${U}${P.deltaPct.toFixed(1)}% self-time (${(P.baseSelfUs/1000).toFixed(2)}ms \u2192 ${(P.candSelfUs/1000).toFixed(2)}ms)`)}for(let P of x.heapTypes?.slice(0,Ce)??[]){if(Math.abs(P.deltaPct)<0.5)continue;let U=P.deltaPct>0?"+":"";c.push(`- heap \`${P.type}\`: ${U}${P.deltaPct.toFixed(1)}% count (${P.baseCount} \u2192 ${P.candCount})`)}c.push("")}}return{text:c.join(`
|
|
10
|
-
`)}}};var Ze=15;function pe(o){return`n${o}`}function en(o,D,c){return`${(o||"(anonymous)").replace(/"/g,"'")} (self ${(D/1000).toFixed(2)}ms, total ${(c/1000).toFixed(2)}ms)`}function nn(o,D,c,C){let x=[];if(C<=0)return x;for(let v=0;v<D;v++){if(v===c)continue;let N=o[v];if(x.length===C&&N<=o[x[C-1]])continue;let P=x.length;while(P>0&&o[x[P-1]]<N)P--;if(x.splice(P,0,v),x.length>C)x.pop()}return x}var Ie={name:"mermaid",async render(o,D={}){let c=D.topN??Ze;return{files:Z(o,D.runId).map((v)=>{let N=v.cpu,{nodes:P,frames:U}=N,M=re(N),{selfUs:F,totalUs:B}=xe(N,M),{parentIx:A}=M,J=M.roots[0]??-1,H=nn(F,M.count,J,c),E=new Set(J!==-1?[J]:[]),L=[];for(let z of H){L.length=0;for(let j=z;j!==-1;j=A[j])L.push(j);for(let j=L.length-1;j>=0;j--)E.add(L[j])}let V=["graph TD"];for(let z of E){let j=P[z].id;V.push(` ${pe(j)}["${en(U[P[z].frameIx].name,F[z],B[z])}"]`)}for(let z of E){let j=A[z];if(j!==-1&&E.has(j))V.push(` ${pe(P[j].id)} --> ${pe(P[z].id)}`)}return{path:`${v.id}.mermaid.md`,content:`${V.join(`
|
|
11
|
-
`)}
|
|
12
|
-
`}})}}};function Ue(o){if(!o?.entry)return;if(o.entry.group!==void 0)return o.entry.group;let D=o.entry.task,c=D.lastIndexOf("/");return c===-1?void 0:D.slice(0,c)}function ce(o){let D=Math.min(...o.map((x)=>x.run.timing.median)),c=new Map;for(let x of o){let v=Ue(x.workload);if(v===void 0)continue;let N=c.get(v);if(N)N.push(x);else c.set(v,[x])}let C=new Map;for(let x of o){let v=Ue(x.workload);if(v===void 0){C.set(x,D);continue}let N=c.get(v)??[x],P=N.find((U)=>U.workload?.baseline);C.set(x,P?P.run.timing.median:Math.min(...N.map((U)=>U.run.timing.median)))}return C}function Q(o){return Number.isFinite(o)?Number(o.toPrecision(6)):o}function tn(o,D){return o?.entry?.task??o?.label??o?.command?.join(" ")??D.workloadId}function rn(o){let D=new Map(o.workloads.map((v)=>[v.id,v])),c=o.runs.filter((v)=>v.phase==="timing"&&v.timing!==void 0).map((v)=>({run:v,workload:D.get(v.workloadId)})),C=c.length>1?ce(c):void 0,x=new Map((o.comparisons??[]).map((v)=>[v.candidateRunId,v]));return c.map((v)=>{let{run:N,workload:P}=v,U=N.timing,M={task:tn(P,N),unit:"ns",samples:U.samples.length,mean:Q(U.mean),median:Q(U.median),stddev:Q(U.stddev),stddevPct:Q(U.mean===0?0:U.stddev/U.mean*100),min:Q(U.min),max:Q(U.max),warnings:N.warnings.map((B)=>B.data?{code:B.code,data:B.data}:{code:B.code})};if(P?.entry?.group!==void 0)M.group=P.entry.group;if(P?.description!==void 0)M.description=P.description;if(P?.groupDescription!==void 0)M.groupDescription=P.groupDescription;if(C)M.relative=Q(U.median/(C.get(v)??U.median));if(P?.baseline)M.baseline=!0;let F=x.get(N.id);if(F?.timing)M.delta={medianPct:Q(F.timing.medianDeltaPct),meanPct:Q(F.timing.meanDeltaPct),verdict:F.timing.verdict,pass:F.verdict==="pass"};return M})}var De={name:"minimal",async render(o){let D=rn(o).map((c)=>JSON.stringify(c));return{text:D.length>0?`${D.join(`
|
|
13
|
-
`)}
|
|
14
|
-
`:""}}};var sn="https://www.speedscope.app/file-format-schema.json";function Fe(o){return o?.label??o?.command?.join(" ")??o?.entry?.task??"profile"}var Me={name:"speedscope",async render(o,D={}){let c=Z(o,D.runId),C=new Map(o.workloads.map((v)=>[v.id,v]));return{files:c.map((v)=>{let N=v.cpu,{nodes:P}=N,U=re(N),M=N.samples?.nodeIds??[],F=N.samples?.timeDeltasUs??[],B=Array(U.count);for(let E of U.order){let L=U.parentIx[E],V=P[E].frameIx;B[E]=L===-1?[V]:[...B[L],V]}let A=Array(M.length);for(let E=0;E<M.length;E++){let L=U.indexOf(M[E]);A[E]=L===-1?[]:B[L]}let J=0;for(let E=0;E<F.length;E++)J+=F[E];let H={$schema:sn,exporter:"ostia",name:Fe(C.get(v.workloadId)),activeProfileIndex:0,shared:{frames:N.frames.map((E)=>({name:E.name||"(anonymous)",file:E.url,line:E.line!==void 0?E.line+1:void 0}))},profiles:[{type:"sampled",name:Fe(C.get(v.workloadId)),unit:"microseconds",startValue:0,endValue:J,samples:A,weights:F}]};return{path:`${v.id}.speedscope.json`,content:`${JSON.stringify(H,null,2)}
|
|
15
|
-
`}})}}};function se(o){return(o/1e6).toFixed(3)}function le(o){return o.label??o.command?.join(" ")??o.entry?.task??o.id}var Be={name:"table",async render(o){let D=o.runs.filter((B)=>B.phase==="timing"&&B.timing!==void 0),c=new Map(o.workloads.map((B)=>[B.id,B]));if(D.length===0){let B=Se(o,c);return{text:B.length>0?`${B.join(`
|
|
16
|
-
`)}
|
|
17
|
-
`:`(no timing runs)
|
|
18
|
-
`}}let C=D.map((B)=>{let A=c.get(B.workloadId);return{run:B,workload:A,label:A?le(A):B.workloadId}}),x=C.length>1,v=ce(C),N=[],P=Math.max(7,...C.map((B)=>B.label.length)),U=x?`${"Command".padEnd(P)} Mean [ms] Min\u2026Max [ms] Relative`:`${"Command".padEnd(P)} Mean [ms] Min\u2026Max [ms]`;N.push(U),N.push("-".repeat(U.length));for(let B of C){let{run:A,label:J,workload:H}=B,E=A.timing,L=`${se(E.mean)} \xB1 ${se(E.stddev)}`,V=`${se(E.min)}\u2026${se(E.max)}`,z=`${J.padEnd(P)} ${L.padEnd(15)} ${V.padEnd(18)}`;if(x){let j=E.median/(v.get(B)??E.median);if(j===1)z+=H?.baseline?" 1.00\xD7 (baseline)":" 1.00\xD7";else if(j>1)z+=` ${j.toFixed(2)}\xD7 slower`;else z+=` ${(1/j).toFixed(2)}\xD7 faster`}N.push(z);for(let j of A.warnings)N.push(` ! ${j.message}`)}let M=an(o,c);if(M.length>0)N.push(""),N.push(...M);let F=Se(o,c);if(F.length>0)N.push(""),N.push(...F);return{text:`${N.join(`
|
|
19
|
-
`)}
|
|
20
|
-
`}}};function on(o,D,c){let C=o.runs.find((v)=>v.id===c),x=C?D.get(C.workloadId):void 0;return x?le(x):c}function Se(o,D){if(!o.comparisons||o.comparisons.length===0)return[];let c=[];for(let C of o.comparisons){let x=on(o,D,C.candidateRunId),v=C.verdict==="pass"?"\u2713":"\u2717";if(c.push(`${v} ${x}`),C.timing){let N=C.timing.medianDeltaPct>0?"+":"";c.push(` timing: ${N}${C.timing.medianDeltaPct.toFixed(1)}% median (${C.timing.verdict})`)}if(C.frames)for(let N of C.frames.slice(0,We)){if(Math.abs(N.deltaPct)<0.5)continue;let P=N.deltaPct>0?"+":"";c.push(` frame ${N.name}: ${P}${N.deltaPct.toFixed(1)}% self-time (${(N.baseSelfUs/1000).toFixed(2)}ms -> ${(N.candSelfUs/1000).toFixed(2)}ms)`)}if(C.heapTypes)for(let N of C.heapTypes.slice(0,Oe)){if(Math.abs(N.deltaPct)<0.5)continue;let P=N.deltaPct>0?"+":"";c.push(` heap ${N.type}: ${P}${N.deltaPct.toFixed(1)}% count (${N.baseCount} -> ${N.candCount})`)}}return c}var We=5,Oe=5;function an(o,D){let c=[];for(let C of o.runs){if(C.phase!=="cpu"&&C.phase!=="heap")continue;let x=D.get(C.workloadId),v=x?le(x):C.workloadId;if(C.phase==="cpu")if(C.cpu){c.push(`CPU capture - ${v} (instrumented, ${C.cpu.samplingIntervalUs}\xB5s interval, diagnostic wall ${se(C.diagnosticWallNs??0)}ms)`);let N=C.cpu.totals.reduce((P,U)=>P+U.selfUs,0)||1;for(let P of C.cpu.totals.slice(0,We)){let U=C.cpu.frames[P.frameIx],M=(P.selfUs/N*100).toFixed(1);c.push(` ${M.padStart(5)}% ${(P.selfUs/1000).toFixed(2).padStart(8)}ms self ${U?.name??"?"}`)}}else c.push(`CPU capture - ${v} (instrumented, no evidence captured)`);else if(C.heap){let N=((C.heap.heapSizeBytes??0)/1e6).toFixed(2);c.push(`Heap snapshot - ${v} (instrumented, ${C.heap.objectCount??"?"} objects, ${N}MB)`);for(let P of C.heap.typeCounts.slice(0,Oe))c.push(` ${String(P.count).padStart(6)} ${P.type}`)}else c.push(`Heap snapshot - ${v} (instrumented, no evidence captured)`);for(let N of C.artifacts)c.push(` artifact: ${N.path}`);for(let N of C.warnings)c.push(` ! ${N.message}`)}return c}var n={table:Be,json:$e,markdown:Ne,jsonl:ke,minimal:De,collapsed:Pe,mermaid:Ie,speedscope:Me,cpuprofile:Te};var cn="node_modules/.cache/ostia",me=1000;async function w(o){let D=s({runs:o.runs??null,warmup:o.warmup??null,cpu:o.cpu??!1,heap:o.heap??!1,cpuIntervalUs:o.cpuIntervalUs??me}),C=`${o.outDir??cn}/artifacts`,x=[],v=[];for(let N of o.commands){let P=Array.isArray(N)?N:Re(N),U=u(P,Array.isArray(N)?void 0:N);x.push(U);let M=await f({argv:P,cwd:o.cwd,env:o.env,runs:o.runs,warmup:o.warmup}),F=i({workload:U,configFingerprint:D,trials:M.trials,timing:M.timing,warnings:M.warnings});if(v.push(F),o.cpu){let B=`${F.id}-cpu.cpuprofile`,A=await de({argv:P,cwd:o.cwd,env:o.env,artifactDir:C,fileName:B,intervalUs:o.cpuIntervalUs??me});v.push(await Ee({workload:U,phase:"cpu",configFingerprint:D,diagnosticWallNs:A.diagnosticWallNs,exitCode:A.exitCode,cpu:A.cpu,artifactPath:A.artifactPath,artifactKind:"cpuprofile",warnings:A.warnings}))}if(o.heap){let B=`${F.id}-heap.heapsnapshot`,A=await ge({argv:P,cwd:o.cwd,env:o.env,artifactDir:C,fileName:B});v.push(await Ee({workload:U,phase:"heap",configFingerprint:D,diagnosticWallNs:A.diagnosticWallNs,exitCode:A.exitCode,heap:A.heap,artifactPath:A.artifactPath,artifactKind:"heapsnapshot",warnings:A.warnings}))}}return r(x,v)}async function Ee(o){let D=`${o.workload.id}-${o.phase}-${o.configFingerprint}`,c=o.artifactPath?[await T(D,o.artifactKind,o.artifactPath)]:[];return h({workload:o.workload,phase:o.phase,configFingerprint:o.configFingerprint,diagnosticWallNs:o.diagnosticWallNs,exitCode:o.exitCode,cpu:o.cpu,heap:o.heap,warnings:o.warnings,artifacts:c})}async function I(o,D={}){let c=R(o),C=s({intervalUs:D.intervalUs??me,origin:D.origin??"inspector"}),x=(M)=>M.samples?.nodeIds.length===0?[{code:"empty-profile",message:"In-process capture produced zero samples."}]:[];if(D.origin==="jsc"){let{result:M,cpu:F,jit:B,diagnosticWallNs:A}=await we(o,D),J=h({workload:c,phase:"cpu",configFingerprint:C,diagnosticWallNs:A,cpu:F,jit:B,warnings:x(F),artifacts:[]});return{result:M,run:J}}let{result:v,cpu:N,diagnosticWallNs:P}=await he(o,D),U=h({workload:c,phase:"cpu",configFingerprint:C,diagnosticWallNs:P,cpu:N,warnings:x(N),artifacts:[]});return{result:v,run:U}}
|
|
21
|
-
export{k,p,a,d,b,f,n,w,I};
|