ostia 0.2.1 → 0.2.3

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.
@@ -0,0 +1,22 @@
1
+ // @bun
2
+ import{R,e,h,i,S,I,O,z,N,b,t,k,q,m,d,K,a,V,r,p,F,E,x,X,v,P}from"./chunk-2s4xk1mg.js";function Le(c,y,w){let H=c[0];if(H==="bun"||H?.endsWith("/bun"))return{argv:[H,...y,...c.slice(1)],env:w};return{argv:c,env:{...process.env,...w,BUN_OPTIONS:y.join(" ")}}}function Hn(c){return c.startsWith("file://")?c.slice(7):c}function _e(c,y,w){let H=c.nodes,A=H.length,ie=new Map,Y=[],D=new Map,se=new Int32Array(A);for(let ae=0;ae<A;ae++){let fe=H[ae],ce=fe.callFrame,ye=Hn(ce.url),ke=ie.get(ce.functionName);if(ke===void 0)ke=new Map,ie.set(ce.functionName,ke);let Pe=ke.get(ye);if(Pe===void 0)Pe=Y.length,ke.set(ye,Pe),Y.push({key:e("fr",ce.functionName,ye),name:ce.functionName,url:ye||void 0,line:ce.lineNumber>=0?ce.lineNumber:void 0,col:ce.columnNumber>=0?ce.columnNumber:void 0});se[ae]=Pe,D.set(fe.id,ae)}let le=Array(A);for(let ae=0;ae<A;ae++){let fe=H[ae];le[ae]={id:fe.id,frameIx:se[D.get(fe.id)],children:fe.children??[]}}let re=new Float64Array(A),ue=new Float64Array(A),{samples:oe,timeDeltas:me}=c;for(let ae=0;ae<oe.length;ae++){let fe=D.get(oe[ae]);if(fe===void 0)continue;re[fe]+=me[ae]??0,ue[fe]+=1}let pe=new Int32Array(A).fill(-1);for(let ae=0;ae<A;ae++){let fe=H[ae].children;if(!fe)continue;for(let ce of fe){let ye=D.get(ce);if(ye!==void 0)pe[ye]=ae}}let de=[],ge=[];for(let ae=A-1;ae>=0;ae--)if(pe[ae]===-1)ge.push(ae);while(ge.length>0){let ae=ge.pop();de.push(ae);let fe=H[ae].children;if(!fe)continue;for(let ce of fe){let ye=D.get(ce);if(ye!==void 0&&pe[ye]===ae)ge.push(ye)}}let he=new Float64Array(A);for(let ae=de.length-1;ae>=0;ae--){let fe=de[ae];he[fe]+=re[fe];let ce=pe[fe];if(ce>=0)he[ce]+=he[fe]}let xe=Array(Y.length),we=[];for(let ae=0;ae<A;ae++){let fe=le[ae].frameIx,ce=xe[fe];if(ce)ce.selfUs+=re[ae],ce.totalUs+=he[ae],ce.samples+=ue[ae];else{let ye={frameIx:fe,selfUs:re[ae],totalUs:he[ae],samples:ue[ae]};xe[fe]=ye,we.push(ye)}}return{origin:y,samplingIntervalUs:w,frames:Y,nodes:le,totals:we.sort((ae,fe)=>fe.selfUs-ae.selfUs),samples:{nodeIds:c.samples,timeDeltasUs:c.timeDeltas}}}async function nn(c){let y=`${c.artifactDir}/${c.fileName}`,{argv:w,env:H}=Le(c.argv,["--cpu-prof","--cpu-prof-dir",c.artifactDir,"--cpu-prof-name",c.fileName,"--cpu-prof-interval",String(c.intervalUs)],c.env),A=Bun.nanoseconds(),Y=await Bun.spawn(w,{cwd:c.cwd,env:H,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,D=Bun.nanoseconds()-A,se=Bun.file(y);if(!await se.exists())return{diagnosticWallNs:D,exitCode:Y,warnings:[{code:"artifact-missing",message:`Expected a .cpuprofile at ${y} after exit ${Y}, found nothing. The workload's argv[0] must be a \`bun\` binary for CPU capture.`,data:{artifactPath:y,argv:c.argv}}]};let le=await se.json(),re=_e(le,"cpu-prof",c.intervalUs),ue=le.samples.length===0?[{code:"empty-profile",message:"CPU capture produced zero samples."}]:[];return{diagnosticWallNs:D,exitCode:Y,artifactPath:y,cpu:re,warnings:ue}}function tn(c,y="heap-prof"){let{node_fields:w,node_types:H}=c.snapshot.meta,A=w.indexOf("type"),ie=w.indexOf("self_size"),Y=w.length,D=H[0];if(A===-1||ie===-1||!Array.isArray(D))return{origin:y,typeCounts:[],objectCount:c.snapshot.node_count};let se=D.length,le=Array(se),re=new Map,ue=[],oe=0,me=c.nodes,pe=me.length;for(let we=0;we<pe;we+=Y){let ae=me[we+A],fe=me[we+ie]??0;oe+=fe;let ce;if(ae>=0&&ae<se){if(ce=le[ae],ce===void 0)ce={type:D[ae],count:0,bytes:0},le[ae]=ce,ue.push(ce)}else{let ye=`unknown(${ae})`;if(ce=re.get(ye),ce===void 0)ce={type:ye,count:0,bytes:0},re.set(ye,ce),ue.push(ce)}ce.count++,ce.bytes+=fe}let de=ue.sort((we,ae)=>ae.count-we.count),ge=de.slice(0,20),he=de.slice(20),xe=ge.map(({type:we,count:ae,bytes:fe})=>({type:we,count:ae,retainedBytes:fe}));if(he.length>0){let we=0,ae=0;for(let fe of he)we+=fe.count,ae+=fe.bytes;xe.push({type:"other",count:we,retainedBytes:ae})}return{origin:y,heapSizeBytes:oe,objectCount:c.snapshot.node_count,typeCounts:xe}}async function rn(c){let y=`${c.artifactDir}/${c.fileName}`,{argv:w,env:H}=Le(c.argv,["--heap-prof","--heap-prof-dir",c.artifactDir,"--heap-prof-name",c.fileName],c.env),A=Bun.nanoseconds(),Y=await Bun.spawn(w,{cwd:c.cwd,env:H,stdout:"ignore",stderr:"ignore",stdin:"ignore"}).exited,D=Bun.nanoseconds()-A,se=Bun.file(y);if(!await se.exists())return{diagnosticWallNs:D,exitCode:Y,warnings:[{code:"artifact-missing",message:`Expected a heap snapshot at ${y} after exit ${Y}, found nothing. The workload's argv[0] must be a \`bun\` binary for heap capture.`,data:{artifactPath:y,argv:c.argv}}]};let le=await se.json(),re=tn(le,"heap-prof");return{diagnosticWallNs:D,exitCode:Y,artifactPath:y,heap:re,warnings:[]}}import{Session as zn}from"inspector/promises";var Gn=1000;async function sn(c,y={}){let w=y.intervalUs??Gn,H=new zn;H.connect();let A=Bun.nanoseconds();try{await H.post("Profiler.enable"),await H.post("Profiler.setSamplingInterval",{interval:w}),await H.post("Profiler.start");let ie=await c(),{profile:Y}=await H.post("Profiler.stop"),D=Bun.nanoseconds()-A,se=_e(Y,"inspector",w);return{result:ie,cpu:se,diagnosticWallNs:D}}finally{H.disconnect()}}function Kn(c){let y=c>>>0;return()=>{y=y+1831565813|0;let w=Math.imul(y^y>>>15,1|y);return w=w+Math.imul(w^w>>>7,61|w)^w,((w^w>>>14)>>>0)/4294967296}}var je=2000,Jn=2000;function mn(c){let y=c.length,w=y>>1;return y%2===0?(c[w-1]+c[w])/2:c[w]}function on(c,y,w){if(c.length<=w)return c;let H=[...c];for(let A=0;A<w;A++){let ie=A+Math.floor(y()*(H.length-A)),Y=H[A];H[A]=H[ie],H[ie]=Y}return H.slice(0,w)}function an(c,y){let w=c.length,H=new Float64Array(w);for(let A=0;A<w;A++)H[A]=c[Math.floor(y()*w)];return H.sort(),mn(H)}function cn(c,y,w={}){let H=w.seed??(Date.now()^Math.imul(c.length,2654435761))>>>0,A=Kn(H),ie=w.iterations??Jn,Y=c.length>je||y.length>je,D=on(c,A,je),se=on(y,A,je),le=new Float64Array(D);le.sort();let re=mn(le),ue=new Float64Array(ie);for(let oe=0;oe<ie;oe++){let me=an(D,A),pe=an(se,A);ue[oe]=re===0?pe-me===0?0:1/0:(pe-me)/re*100}return ue.sort(),{ci95:[i(ue,0.025),i(ue,0.975)],seed:H,data:{subsampled:Y,iterations:ie}}}function Yn(c){let y=c<0?-1:1,w=Math.abs(c),H=0.254829592,A=-0.284496736,ie=1.421413741,Y=-1.453152027,D=1.061405429,se=0.3275911,le=1/(1+0.3275911*w),re=1-((((1.061405429*le+-1.453152027)*le+1.421413741)*le+-0.284496736)*le+0.254829592)*le*Math.exp(-w*w);return y*re}function qn(c){return 0.5*(1+Yn(c/Math.SQRT2))}function un(c,y){let w=c.length,H=y.length,A=w+H,ie=[...c.map((de)=>({v:de,group:0})),...y.map((de)=>({v:de,group:1}))].sort((de,ge)=>de.v-ge.v),Y=new Float64Array(A),D=0,se=0;while(se<A){let de=se;while(de+1<A&&ie[de+1].v===ie[se].v)de++;let ge=(se+de)/2+1;for(let xe=se;xe<=de;xe++)Y[xe]=ge;let he=de-se+1;if(he>1)D+=he**3-he;se=de+1}let le=0;for(let de=0;de<A;de++)if(ie[de].group===0)le+=Y[de];let re=le-w*(w+1)/2,ue=w*H/2,oe=Math.sqrt(w*H*(A+1-D/(A*(A-1)))/12),me=oe===0?0:(re-ue)/oe,pe=Math.min(1,Math.max(0,2*(1-qn(Math.abs(me)))));return{u:re,z:me,pValue:pe}}var u={timingPct:5,frameSelfPct:10,heapTypePct:10,minFrameSelfUs:1000,alpha:0.01,bootstrapIterations:2000},Ye=5;function Ve(c,y){if(c===0)return y===0?0:1/0;return(y-c)/c*100}function Oe(c,y,w){return c.measurements.find((H)=>H.workloadId===y&&H.phase===w)}function Qn(c,y){let w=[];if(c.platform.os!==y.platform.os)w.push({field:"platform.os",base:c.platform.os,cand:y.platform.os});if(c.platform.arch!==y.platform.arch)w.push({field:"platform.arch",base:c.platform.arch,cand:y.platform.arch});if(c.bunVersion!==y.bunVersion)w.push({field:"bunVersion",base:c.bunVersion,cand:y.bunVersion});if(c.environment&&y.environment){if(c.environment.cpuModel!==y.environment.cpuModel)w.push({field:"cpuModel",base:c.environment.cpuModel,cand:y.environment.cpuModel});if(c.environment.cores!==y.environment.cores)w.push({field:"cores",base:c.environment.cores,cand:y.environment.cores})}if(w.length===0)return;return{code:"environment-mismatch",message:`Base and candidate were measured on different environments (${w.map((H)=>H.field).join(", ")}); a timing delta may reflect that instead of the code change.`,data:{fields:w}}}function B(c){let y=[];for(let H of c){if(!H.timing)continue;let A=1+H.timing.medianDeltaPct/100;if(Number.isFinite(A)&&A>0)y.push(Math.log(A))}if(y.length===0)return null;let w=y.reduce((H,A)=>H+A,0)/y.length;return(Math.exp(w)-1)*100}function M(c,y,w=u){let H=new Set(c.workloads.map((oe)=>oe.id)),A=new Set(y.workloads.map((oe)=>oe.id)),ie=[];for(let oe of c.workloads){if(!A.has(oe.id))continue;let me=U(c,y,oe.id,w);if(me)ie.push(me)}let Y=c.workloads.filter((oe)=>!A.has(oe.id)),D=y.workloads.filter((oe)=>!H.has(oe.id)),se=0,le=0,re=0;for(let oe of ie){if(!oe.timing)continue;if(oe.timing.verdict==="regressed")se++;else if(oe.timing.verdict==="improved")le++;else re++}let ue=Math.max(w.timingPct,c.environment?.noise.floorPct??0,y.environment?.noise.floorPct??0);return{comparisons:ie,unmatched:{baseOnly:Y,candOnly:D},summary:{matched:ie.length,regressed:se,improved:le,unchanged:re,geomeanPct:B(ie),effectiveTimingPct:ue,verdict:ie.some((oe)=>oe.verdict==="fail")?"fail":"pass"}}}function U(c,y,w,H=u){let A=Oe(c,w,"timing"),ie=Oe(y,w,"timing"),Y=Oe(c,w,"cpu"),D=Oe(y,w,"cpu"),se=Oe(c,w,"heap"),le=Oe(y,w,"heap"),re=y.workloads.find((ae)=>ae.id===w),ue=A?.id??Y?.id??se?.id,oe=ie?.id??D?.id??le?.id??re?.id;if(!ue||!oe)return;let me=!1,pe=[],de=Qn(c,y);if(de)pe.push(de);let ge=Math.max(H.timingPct,c.environment?.noise.floorPct??0,y.environment?.noise.floorPct??0),he;if(A?.timing&&re?.skipped&&!ie?.timing)he={medianDeltaPct:0,meanDeltaPct:0,effectPct:0,verdict:"unchanged"},pe.push({code:"skipped",message:"Candidate has no timing measurement for this workload (task.skip()); treated as unchanged.",data:{workloadId:w}});else if(A?.timing&&ie?.timing){let ae=A.timing.samples,fe=ie.timing.samples,ce=Ve(A.timing.median,ie.timing.median),ye=Ve(A.timing.mean,ie.timing.mean),ke=(Pe,be)=>{if(Pe>ge)return"regressed";if(be<-ge)return"improved";return"unchanged"};if(ae.length<Ye||fe.length<Ye){let Pe=ke(ce,ce);if(Pe==="regressed")me=!0;he={medianDeltaPct:ce,meanDeltaPct:ye,effectPct:ce,verdict:Pe},pe.push({code:"thin-comparison",message:`Only ${ae.length} baseline / ${fe.length} candidate sample(s); falling back to a point-estimate threshold instead of a bootstrap CI and Mann-Whitney test (needs ${Ye}+ per side).`,data:{baseSamples:ae.length,candSamples:fe.length}})}else{let Pe=cn(ae,fe,{iterations:H.bootstrapIterations}),be=un(ae,fe),Me=be.pValue<H.alpha?ke(Pe.ci95[0],Pe.ci95[1]):"unchanged";if(Me==="regressed")me=!0;he={medianDeltaPct:ce,meanDeltaPct:ye,effectPct:ce,ci95:Pe.ci95,pValue:be.pValue,seed:Pe.seed,verdict:Me}}}let xe;if(Y?.cpu&&D?.cpu){let ae=new Map(Y.cpu.totals.map((Pe)=>[Y.cpu.frames[Pe.frameIx].key,Pe])),fe=new Map(D.cpu.totals.map((Pe)=>[D.cpu.frames[Pe.frameIx].key,Pe])),ce=new Map(Y.cpu.frames.map((Pe)=>[Pe.key,Pe.name])),ye=new Map(D.cpu.frames.map((Pe)=>[Pe.key,Pe.name]));xe=[...new Set([...ae.keys(),...fe.keys()])].map((Pe)=>{let be=ae.get(Pe)?.selfUs??0,Me=fe.get(Pe)?.selfUs??0;return{frameKey:Pe,name:ye.get(Pe)??ce.get(Pe)??Pe,baseSelfUs:be,candSelfUs:Me,deltaPct:Ve(be,Me)}}).sort((Pe,be)=>Math.abs(be.deltaPct)-Math.abs(Pe.deltaPct));for(let Pe of xe)if((Pe.baseSelfUs>=H.minFrameSelfUs||Pe.candSelfUs>=H.minFrameSelfUs)&&Pe.deltaPct>H.frameSelfPct)me=!0}let we;if(se?.heap&&le?.heap){let ae=new Map(se.heap.typeCounts.map((ye)=>[ye.type,ye])),fe=new Map(le.heap.typeCounts.map((ye)=>[ye.type,ye]));we=[...new Set([...ae.keys(),...fe.keys()])].map((ye)=>{let ke=ae.get(ye),Pe=fe.get(ye);return{type:ye,baseCount:ke?.count??0,candCount:Pe?.count??0,baseBytes:ke?.retainedBytes,candBytes:Pe?.retainedBytes,deltaPct:Ve(ke?.count??0,Pe?.count??0)}}).sort((ye,ke)=>Math.abs(ke.deltaPct)-Math.abs(ye.deltaPct));for(let ye of we)if(ye.deltaPct>H.heapTypePct)me=!0}return{id:e("cmp",ue,oe),baselineMeasurementId:ue,candidateMeasurementId:oe,timing:he,...pe.length>0&&{warnings:pe},frames:xe,heapTypes:we,thresholds:{...H,effectiveTimingPct:ge},verdict:me?"fail":"pass"}}var Ue="node_modules/.cache/ostia",Xn=".ostia/baselines",Zn={runs:null,warmup:3,outDir:Ue,baselineDir:Xn,baseline:"main",cpuIntervalUs:1000,thresholds:u,workloads:[]};function pn(c){return{...Zn,...c,thresholds:{...u,...c.thresholds??{}}}}async function ln(c){let y=Bun.file(c);if(!await y.exists())return;return pn(await y.json())}async function dn(c){let y=c.startsWith("/")?c:`${process.cwd()}/${c}`;if(!await Bun.file(y).exists())return;let w=await import(y);return pn(w.default??{})}async function T(c){if(c!==void 0)return c.endsWith(".ts")?dn(c):ln(c);return await dn("ostia.config.ts")??ln("ostia.config.json")}function s(c,y){return`${c.baselineDir}/${y??c.baseline}.json`}async function W(){if(await Bun.file("ostia.config.ts").exists())return"ostia.config.ts";if(await Bun.file("ostia.config.json").exists())return"ostia.config.json";return}var et=10,nt=3000000000,tt=3;function qe(c){if(c.timeSource)I(c.timeSource);let y=c.warmup??tt,w=c.samples,H=c.minSamples??et,A=w??H,ie=w!==void 0?0:c.budgetMs!==void 0?c.budgetMs*1e6:nt,Y=c.timeSource!==void 0,D=c.ignoreExitCodes??[],se=new Set(D),le=[],re=0,ue=0,oe=!1,me;function pe(){if(oe)return!0;if(w!==void 0)return ue>=w;return ue>=A&&re>=ie}async function de(ge,he){if(c.prepare)await N(c.prepare,{phase:ge,index:he},{cwd:c.cwd,env:c.env,timeoutMs:c.timeoutMs,signal:c.signal});return z(c)}return{async warmup(){for(let ge=0;ge<y;ge++){if(c.signal?.aborted)return;await de("warmup",ge)}},async step(){if(pe()||c.signal?.aborted)return!1;let ge=await de("timing",ue);if(c.signal?.aborted)return!1;if(ge.timeSourceNoMatch)me??=ge.timeSourceMissOutput;if(le.push({i:ue,wallNs:ge.wallNs,exitCode:ge.exitCode??void 0,userNs:ge.userNs,systemNs:ge.systemNs,maxRssBytes:ge.maxRssBytes,...ge.reportedNs!==void 0&&{reportedNs:ge.reportedNs},...ge.timedOut?{timedOut:!0}:{},...ge.timeSourceNoMatch?{timeSourceNoMatch:!0}:{}}),re+=ge.wallNs,ue++,c.failOnNonzero&&ge.exitCode!==null&&ge.exitCode!==0&&!se.has(ge.exitCode))oe=!0;return!0},done:pe,result(){let ge=le.filter((ce)=>!ce.timedOut&&!ce.timeSourceNoMatch),he=ge.map((ce)=>Y?ce.reportedNs:ce.wallNs),xe=[],we=le.filter((ce)=>ce.timedOut).length;if(we>0)xe.push({code:"timeout",message:`${we} of ${le.length} trial(s) timed out after ${c.timeoutMs}ms.`,data:{timeoutMs:c.timeoutMs,trials:we}});let ae=le.filter((ce)=>ce.timeSourceNoMatch).length;if(ae>0&&c.timeSource){let{pattern:ce}=c.timeSource;xe.push({code:"time-source-no-match",message:`${ae} of ${le.length} trial(s) didn't match the timeSource pattern.`,data:{pattern:typeof ce==="string"?ce:ce.source,trials:ae,...me!==void 0&&{output:me}}})}if(he.length===0)return{trials:le,warnings:xe};let fe=h(he);return xe.push(...S(fe,ge.map((ce)=>ce.exitCode),Y?"reported":"subprocess",D)),{trials:le,timing:fe,warnings:xe}}}}async function Qe(c){await c.warmup();while(await c.step());}async function J(c){let y=qe(c);return await Qe(y),y.result()}async function C(c,y){let w=new Set;for(let H of c)for await(let A of new Bun.Glob(H).scan({cwd:y,absolute:!1}))w.add(A);return[...w].sort()}var fn=new URL("./runner.ts",import.meta.url).pathname;function j(){return Math.max(1,navigator.hardwareConcurrency||1)}async function L(c,y){return C(c,y)}function rt(c){if(c===void 0)return;return c==="auto"?j():c}async function G(c,y,w=process.cwd()){return{suites:c.suites.length>0?c.suites:y?.suites?await L(y.suites,w):[],budgetMs:c.budgetMs??y?.budgetMs,samples:c.samples??y?.samples,minSamples:c.minSamples??y?.minSamples,jobs:c.jobs??rt(y?.jobs),gc:c.gc??y?.gc??!1,cpu:c.cpu??y?.cpu??!1,alloc:c.alloc??y?.alloc??!1,filter:c.filter??y?.filter,isolate:c.isolate??y?.isolate??!1,preload:c.preload.length>0?c.preload:y?.preload??[],bunFlags:c.bunFlags,outDir:c.outDir??y?.outDir,noiseCheck:c.noiseCheck,timeoutMs:c.timeoutMs??y?.timeoutMs,cwd:w}}async function f(c){if(c.samples!==void 0&&(!Number.isFinite(c.samples)||c.samples<1))throw RangeError(`bench: samples must be >= 1, got ${c.samples}`);if(c.minSamples!==void 0&&(!Number.isFinite(c.minSamples)||c.minSamples<1))throw RangeError(`bench: minSamples must be >= 1, got ${c.minSamples}`);if(c.budgetMs!==void 0&&!Number.isFinite(c.budgetMs))throw RangeError(`bench: budgetMs must be finite, got ${c.budgetMs}`);let w=`${c.outDir??Ue}/bench-tmp`,H=c.cwd??process.cwd(),A=Math.max(1,Math.floor(c.jobs??1)),ie={budgetMs:c.budgetMs,samples:c.samples,minSamples:c.minSamples,gc:c.gc,cpu:c.cpu,alloc:c.alloc,noiseCheck:c.noiseCheck},Y=(ue)=>ue.startsWith("/")?ue:`${H}/${ue}`,D=c.suites.map(Y),se=(c.preload??[]).map(Y),le=c.bunFlags??[],re=async(ue,oe)=>{let me=new Set,pe=0,de,ge=async()=>{while(de===void 0&&!c.signal?.aborted&&pe<ue.length){let he=pe++;try{let xe=!1,we=c.timeoutMs!==void 0?AbortSignal.timeout(c.timeoutMs):void 0;we?.addEventListener("abort",()=>{xe=!0},{once:!0});let ae=O(we,c.signal),fe=Bun.spawn(ue[he],{cwd:H,stdout:"inherit",stderr:"inherit",stdin:"ignore",...ae&&{signal:ae,killSignal:"SIGKILL"}});me.add(fe);let ce=await fe.exited;if(me.delete(fe),c.signal?.aborted)return;if(xe)throw Error(`Bench suite timed out after ${c.timeoutMs}ms: ${oe(he)}`);if(ce!==0)throw Error(`Bench suite failed: ${oe(he)} (runner exited ${ce})`)}catch(xe){de??=xe instanceof Error?xe:Error(String(xe));for(let we of me)we.kill()}}};if(await Promise.all(Array.from({length:Math.min(A,ue.length)},ge)),de)throw de};try{let ue=D.map((ce)=>`${w}/${e("bench-plan",ce)}.json`),oe=D.map((ce)=>`${w}/${e("bench-primary",ce)}.json`),me=D.map((ce,ye)=>["bun",...le,fn,ce,oe[ye],JSON.stringify({...ie,filter:c.filter,isolate:c.isolate,preload:se,planPath:ue[ye]})]);await re(me,(ce)=>c.suites[ce]);let pe=await Promise.all(ue.map(async(ce)=>{if(!await Bun.file(ce).exists())return[];let{tasks:ye}=await Bun.file(ce).json();return ye})),de=await Promise.all(oe.map(async(ce)=>await Bun.file(ce).exists()?r(ce):void 0)),ge=[];for(let ce=0;ce<pe.length;ce++)for(let ye of pe[ce])if(ye.isolate)ge.push({suiteIndex:ce,taskIds:[ye.id]});let he=ge.map((ce,ye)=>`${w}/${e("bench-item",D[ce.suiteIndex],ye)}.json`),xe=ge.map((ce,ye)=>["bun",...le,fn,D[ce.suiteIndex],he[ye],JSON.stringify({...ie,taskIds:ce.taskIds,preload:se,markIsolated:!0})]);await re(xe,(ce)=>c.suites[ge[ce].suiteIndex]);let we=await Promise.all(he.map(async(ce)=>await Bun.file(ce).exists()?r(ce):void 0)),ae=[],fe=[];for(let ce=0;ce<pe.length;ce++){let ye=de[ce];if(!ye)continue;let ke=new Map;for(let Me of ye.measurements){let $e=ke.get(Me.workloadId)??[];$e.push(Me),ke.set(Me.workloadId,$e)}let Pe=0,be=new Map;ge.forEach((Me,$e)=>{let Ce=we[$e];if(Me.suiteIndex===ce&&Ce)be.set(Me.taskIds[0],Ce)});for(let Me of pe[ce])if(Me.isolate){let $e=be.get(Me.id);if(!$e)continue;let Ce=$e.workloads[0];ae.push(Ce);for(let Ae of $e.measurements)if(Ae.workloadId===Ce.id)fe.push(Ae)}else{let $e=ye.workloads[Pe];ae.push($e),Pe++;for(let Ce of ke.get($e.id)??[])fe.push(Ce)}}if(c.signal?.aborted&&fe.length>0){let ce=fe[fe.length-1];ce.warnings=[...ce.warnings,{code:"aborted",message:"Run was cancelled before it finished; this document holds whatever suites/tasks had already completed."}]}return t(ae,fe,de.find((ce)=>ce!==void 0)?.environment)}finally{await Bun.spawn(["rm","-rf",w]).exited}}function Z(c,y,w=8){if(w<=1)throw RangeError(`range: multiplier must be > 1, got ${w}`);if(c<=0)throw RangeError(`range: start must be > 0, got ${c}`);let H=[];for(let A=c;A<=y;A*=w)H.push(A);if(!H.includes(y))H.push(y);return H}function Se(c,y){if(y){let w=c.measurements.find((H)=>H.id===y);return w?.cpu?[w]:[]}return c.measurements.filter((w)=>w.phase==="cpu"&&w.cpu)}function Ne(c){let y=c.nodes,w=y.length,H=it(c),A=new Int32Array(w).fill(-1);for(let se=0;se<w;se++)for(let le of y[se].children){let re=H(le);if(re!==-1)A[re]=se}let ie=[];for(let se=0;se<w;se++)if(A[se]===-1)ie.push(se);let Y=[],D=[];for(let se=ie.length-1;se>=0;se--)D.push(ie[se]);while(D.length>0){let se=D.pop();Y.push(se);for(let le of y[se].children){let re=H(le);if(re!==-1&&A[re]===se)D.push(re)}}return{count:w,indexOf:H,parentIx:A,roots:ie,order:Y}}function it(c){let y=c.nodes,w=y.length,H=1/0,A=-1/0,ie=!0;for(let D=0;D<w;D++){let se=y[D].id;if(!Number.isInteger(se)){ie=!1;break}if(se<H)H=se;if(se>A)A=se}if(ie&&w>0&&A-H<w*4+64){let D=A-H+1,se=new Int32Array(D).fill(-1);for(let le=0;le<w;le++)se[y[le].id-H]=le;return(le)=>{let re=le-H;return re>=0&&re<D?se[re]:-1}}let Y=new Map;for(let D=0;D<w;D++)Y.set(y[D].id,D);return(D)=>Y.get(D)??-1}function gn(c,y){let{count:w,indexOf:H,parentIx:A,order:ie}=y,Y=new Float64Array(w),D=new Float64Array(w),se=c.samples?.nodeIds??[],le=c.samples?.timeDeltasUs??[];for(let ue=0;ue<se.length;ue++){let oe=H(se[ue]);if(oe===-1)continue;Y[oe]+=le[ue]??0,D[oe]+=1}let re=new Float64Array(w);for(let ue=ie.length-1;ue>=0;ue--){let oe=ie[ue];re[oe]+=Y[oe];let me=A[oe];if(me>=0)re[me]+=re[oe]}return{selfUs:Y,totalUs:re,samples:D}}var hn={name:"collapsed",async render(c,y={}){return{files:Se(c,y.measurementId).map((A)=>{let ie=A.cpu,{nodes:Y,frames:D}=ie,se=Ne(ie),le=Array(se.count);for(let pe of se.order){let de=D[Y[pe].frameIx].name||"(anonymous)",ge=se.parentIx[pe];le[pe]=ge===-1?de:`${le[ge]};${de}`}let re=new Float64Array(se.count),ue=[],oe=ie.samples?.nodeIds??[];for(let pe=0;pe<oe.length;pe++){let de=se.indexOf(oe[pe]);if(de===-1)continue;if(re[de]++===0)ue.push(de)}let me=Array(ue.length);for(let pe=0;pe<ue.length;pe++){let de=ue[pe];me[pe]=`${le[de]} ${re[de]}`}return{path:`${A.id}.collapsed.txt`,content:me.join(`
3
+ `)+(me.length>0?`
4
+ `:"")}})}}};var bn={name:"cpuprofile",async render(c,y={}){let w=Se(c,y.measurementId),H=[],A=[];for(let ie of w){if(ie.cpu?.origin!=="cpu-prof"&&ie.cpu?.origin!=="inspector"){A.push(`${ie.id} (origin ${ie.cpu?.origin??"unknown"} has no .cpuprofile artifact to pass through)`);continue}let Y=ie.artifacts.find((se)=>se.kind==="cpuprofile");if(!Y){A.push(`${ie.id} (no cpuprofile artifact recorded on this run)`);continue}let D=Bun.file(Y.path);if(!await D.exists()){A.push(`${ie.id} (artifact missing on disk: ${Y.path})`);continue}H.push({path:`${ie.id}.cpuprofile`,content:await D.text()})}if(H.length===0&&A.length>0)return{text:`No .cpuprofile artifacts available:
5
+ ${A.map((ie)=>` - ${ie}`).join(`
6
+ `)}
7
+ `};return{files:H}}};var wn={name:"json",async render(c){return{text:V(c)}}};var yn={name:"jsonl",async render(c){let{measurements:y,...w}=c;return{text:`${[R({kind:"document",...w}),...y.map((A)=>R({kind:"measurement",...A}))].join(`
8
+ `)}
9
+ `}}};var Fe=0.5,st={ns:1,\u{b5}s:1000,ms:1e6,s:1e9};function Be(c){let y=Math.abs(c);if(y>=1e9)return"s";if(y>=1e6)return"ms";if(y>=1000)return"\xB5s";return"ns"}function ot(c){let y=Math.floor(Math.log10(Math.max(Math.abs(c),1)))+1;return Math.max(1,3-y)}function ve(c,y=Be(c)){let w=c/st[y];return`${w.toFixed(ot(w))} ${y}`}function He(c){return`${c.cpuModel} \xB7 ${c.cores} cores \xB7 load ${c.loadAvg1.toFixed(1)} \xB7 noise floor ${c.noise.floorPct.toFixed(1)}%`}function g(c){return`${c.sha} (${c.branch}${c.dirty?", dirty":""})`}function n(c){return c?.label??c?.command?.join(" ")??c?.entry?.task??c?.id??"unknown"}function ze(c,y){if(c===1)return y?"1.00\xD7 (baseline)":"1.00\xD7";if(c>1)return`${c.toFixed(2)}\xD7 slower`;return`${(1/c).toFixed(2)}\xD7 faster`}function xn(c){return c.replace(/\|/g,"\\|").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/`/g,"\\`").replace(/\r\n|\r|\n/g,"<br>")}function Ge(c){if(!c?.entry)return;if(c.entry.group!==void 0)return c.entry.group;let y=c.entry.task,w=y.lastIndexOf("/");return w===-1?void 0:y.slice(0,w)}function We(c){let y=Math.min(...c.map((A)=>A.run.timing.median)),w=new Map;for(let A of c){let ie=Ge(A.workload);if(ie===void 0)continue;let Y=w.get(ie);if(Y)Y.push(A);else w.set(ie,[A])}let H=new Map;for(let A of c){let ie=Ge(A.workload);if(ie===void 0){H.set(A,y);continue}let Y=w.get(ie)??[A],D=Y.find((se)=>se.workload?.baseline);H.set(A,D?D.run.timing.median:Math.min(...Y.map((se)=>se.run.timing.median)))}return H}function Pn(c){return(c/1e6).toFixed(3)}function Mn(c){if(!c?.params)return"";return` (${Object.entries(c.params).map(([w,H])=>`${w}=${H}`).join(", ")})`}function Te(c){return xn(String(c))}function at(c){let y;for(let w of c){let H=w?.params?Object.keys(w.params):void 0;if(H?.length!==2)return;if(y===void 0)y=H;else if(H.length!==y.length||H.some((A,ie)=>A!==y[ie]))return}return y}var kn=10,Rn=10,$n={name:"markdown",async render(c){let y=new Map(c.workloads.map((D)=>[D.id,D])),w=[];w.push("# Profile Report","");let H=c.git?` \xB7 ${g(c.git)}`:"";if(w.push(`Bun ${c.bunVersion} \xB7 ostia ${c.toolVersion} \xB7 ${c.platform.os}/${c.platform.arch} \xB7 ${c.createdAt}${H}`,""),c.environment)w.push(He(c.environment),"");let A=(c.comparisons??[]).flatMap((D)=>D.warnings??[]).find((D)=>D.code==="environment-mismatch");if(A)w.push(`> \u26A0 ${A.message}`,"");let ie=c.measurements.filter((D)=>D.phase==="timing"&&D.timing!==void 0),Y=c.workloads.filter((D)=>D.skipped&&!ie.some((se)=>se.workloadId===D.id));if(ie.length>0||Y.length>0){w.push("## Timing","");let D=new Map,se=[];for(let ue of ie){let oe=y.get(ue.workloadId)?.entry?.group;if(oe===void 0){se.push(ue);continue}let me=D.get(oe);if(me)me.push(ue);else D.set(oe,[ue])}let le=new Map;for(let[ue,oe]of D){let me=at(oe.map((pe)=>y.get(pe.workloadId)));if(me)le.set(ue,{keys:me,runs:oe});else se.push(...oe)}if(se.length>0||Y.length>0){let ue=ie.map((he)=>({run:he,workload:y.get(he.workloadId)})),oe=ue.length>1,me=oe?We(ue):void 0,pe=new Map(ue.map((he)=>[he.run.id,me?.get(he)??he.run.timing.median])),de=oe?" Relative |":"",ge=oe?"---|":"";w.push(`| Task | Median | Spread (p75\u2026p99) | Mean \xB1 SD | Range | MAD |${de}`,`|---|---|---|---|---|---|${ge}`);for(let he of se){let xe=y.get(he.workloadId),we=Te(n(xe)+Mn(xe)),ae=he.timing,fe=Be(ae.median),ce=ae.p75??ae.median,ye=ae.p99??ae.max,ke=ae.mad!==void 0?ve(ae.mad,fe):"-",Pe=oe?` ${ze(ae.median/(pe.get(he.id)??ae.median),!!xe?.baseline)} |`:"";w.push(`| ${we} | ${ve(ae.median,fe)} | ${ve(ce,fe)}\u2026${ve(ye,fe)} | ${ve(ae.mean,fe)} \xB1 ${ve(ae.stddev,fe)} | ${ve(ae.min,fe)}\u2026${ve(ae.max,fe)} | ${ke} |${Pe}`)}for(let he of Y){let xe=Te(n(he)+Mn(he)),we=oe?" - |":"";w.push(`| ${xe} | - skipped | - | - | - | - |${we}`)}w.push("")}for(let[ue,{keys:oe,runs:me}]of le){let[pe,de]=oe,ge=[],he=[],xe=new Map;for(let we of me){let ae=y.get(we.workloadId).params,fe=ae[pe],ce=ae[de];if(!ge.includes(fe))ge.push(fe);if(!he.includes(ce))he.push(ce);xe.set(`${fe}\x00${ce}`,we)}w.push(`### ${Te(ue)} (${Te(pe)} \xD7 ${Te(de)})`,""),w.push(`| ${Te(pe)} \\ ${Te(de)} | ${he.map(Te).join(" | ")} |`,`|---|${he.map(()=>"---").join("|")}|`);for(let we of ge){let ae=he.map((fe)=>{let ce=xe.get(`${we}\x00${fe}`);return ce?ve(ce.timing.median):"-"});w.push(`| ${Te(we)} | ${ae.join(" | ")} |`)}w.push("")}let re=ie.filter((ue)=>ue.warnings.length>0);if(re.length>0){w.push("### Warnings","");for(let ue of re){let oe=n(y.get(ue.workloadId));for(let me of ue.warnings)w.push(`- **${oe}**: ${me.message} (\`${me.code}\`)`)}w.push("")}}for(let D of c.measurements){if(D.phase!=="cpu"&&D.phase!=="heap")continue;let se=n(y.get(D.workloadId));if(D.phase==="cpu"){if(w.push(`## CPU capture - ${se}`,""),w.push(`instrumented, diagnostic wall ${Pn(D.diagnosticWallNs??0)}ms`,""),D.cpu){w.push(`origin: \`${D.cpu.origin}\`, interval: ${D.cpu.samplingIntervalUs}\xB5s`,""),w.push("| Self % | Self (ms) | Total (ms) | Frame |","|---|---|---|---|");let le=D.cpu.totals.reduce((re,ue)=>re+ue.selfUs,0)||1;for(let re of D.cpu.totals.slice(0,kn)){let ue=D.cpu.frames[re.frameIx],oe=(re.selfUs/le*100).toFixed(1);w.push(`| ${oe}% | ${(re.selfUs/1000).toFixed(2)} | ${(re.totalUs/1000).toFixed(2)} | ${Te(ue?.name||"(anonymous)")} |`)}if(w.push(""),D.jit){let re=D.jit.tiers;w.push(`JIT tiers: LLInt ${re.llint} \xB7 Baseline ${re.baseline} \xB7 DFG ${re.dfg} \xB7 FTL ${re.ftl}`,"")}}}else if(w.push(`## Heap snapshot - ${se}`,""),w.push(`instrumented, diagnostic wall ${Pn(D.diagnosticWallNs??0)}ms`,""),D.heap){w.push(`${D.heap.objectCount??"?"} objects, ${((D.heap.heapSizeBytes??0)/1e6).toFixed(2)}MB`,""),w.push("| Count | Type |","|---|---|");for(let le of D.heap.typeCounts.slice(0,Rn))w.push(`| ${le.count} | ${Te(le.type)} |`);w.push("")}for(let le of D.artifacts)w.push(`- artifact: \`${le.path}\``);for(let le of D.warnings)w.push(`- ! ${le.message} (\`${le.code}\`)`);if(D.artifacts.length>0||D.warnings.length>0)w.push("")}if(c.comparisons&&c.comparisons.length>0){w.push("## Comparisons","");for(let D of c.comparisons){let se=c.measurements.find((re)=>re.id===D.candidateMeasurementId),le=n(se?y.get(se.workloadId):y.get(D.candidateMeasurementId));if(w.push(`### ${D.verdict==="pass"?"\u2713":"\u2717"} ${le}`,""),D.timing){let re=D.timing.medianDeltaPct>0?"+":"",ue=D.timing.verdict==="unchanged"&&D.timing.pValue!==void 0&&D.timing.pValue>=D.thresholds.alpha?"~":"",oe=[];if(se?.timing)oe.push(`n=${se.timing.samples.length}`);if(D.timing.ci95)oe.push(`95% CI [${D.timing.ci95[0]>0?"+":""}${D.timing.ci95[0].toFixed(1)}%, ${D.timing.ci95[1]>0?"+":""}${D.timing.ci95[1].toFixed(1)}%]`);if(D.timing.pValue!==void 0)oe.push(`p=${D.timing.pValue.toFixed(4)}`);oe.push(`threshold ${D.thresholds.effectiveTimingPct.toFixed(1)}%`),w.push(`- timing: ${ue}${re}${D.timing.medianDeltaPct.toFixed(1)}% median, ${oe.join(", ")} (**${D.timing.verdict}**)`)}for(let re of D.frames?.slice(0,kn)??[]){if(Math.abs(re.deltaPct)<Fe)continue;let ue=re.deltaPct>0?"+":"";w.push(`- frame \`${Te(re.name)}\`: ${ue}${re.deltaPct.toFixed(1)}% self-time (${(re.baseSelfUs/1000).toFixed(2)}ms \u2192 ${(re.candSelfUs/1000).toFixed(2)}ms)`)}for(let re of D.heapTypes?.slice(0,Rn)??[]){if(Math.abs(re.deltaPct)<Fe)continue;let ue=re.deltaPct>0?"+":"";w.push(`- heap \`${Te(re.type)}\`: ${ue}${re.deltaPct.toFixed(1)}% count (${re.baseCount} \u2192 ${re.candCount})`)}for(let re of D.warnings??[]){if(re.code==="environment-mismatch")continue;w.push(`- ! ${re.message} (\`${re.code}\`)`)}w.push("")}}return{text:w.join(`
10
+ `)}}};var mt=15;function Xe(c){return`n${c}`}function ct(c,y,w){return`${(c||"(anonymous)").replace(/"/g,"'")} (self ${(y/1000).toFixed(2)}ms, total ${(w/1000).toFixed(2)}ms)`}function ut(c,y,w,H){let A=[];if(H<=0)return A;for(let ie=0;ie<y;ie++){if(ie===w)continue;let Y=c[ie];if(A.length===H&&Y<=c[A[H-1]])continue;let D=A.length;while(D>0&&c[A[D-1]]<Y)D--;if(A.splice(D,0,ie),A.length>H)A.pop()}return A}var vn={name:"mermaid",async render(c,y={}){let w=y.topN??mt;return{files:Se(c,y.measurementId).map((ie)=>{let Y=ie.cpu,{nodes:D,frames:se}=Y,le=Ne(Y),{selfUs:re,totalUs:ue}=gn(Y,le),{parentIx:oe}=le,me=le.roots[0]??-1,pe=ut(re,le.count,me,w),de=new Set(me!==-1?[me]:[]),ge=[];for(let xe of pe){ge.length=0;for(let we=xe;we!==-1;we=oe[we])ge.push(we);for(let we=ge.length-1;we>=0;we--)de.add(ge[we])}let he=["graph TD"];for(let xe of de){let we=D[xe].id;he.push(` ${Xe(we)}["${ct(se[D[xe].frameIx].name,re[xe],ue[xe])}"]`)}for(let xe of de){let we=oe[xe];if(we!==-1&&de.has(we))he.push(` ${Xe(D[we].id)} --> ${Xe(D[xe].id)}`)}return{path:`${ie.id}.mermaid.md`,content:`${he.join(`
11
+ `)}
12
+ `}})}}};var l=1;function Re(c){return Number.isFinite(c)?Number(c.toPrecision(6)):c}function Ze(c,y){return c?.entry?.task??c?.label??c?.command?.join(" ")??y}function Cn(c,y){if(y?.entry?.group!==void 0)c.group=y.entry.group;if(y?.description!==void 0)c.description=y.description;if(y?.groupDescription!==void 0)c.groupDescription=y.groupDescription;if(y?.params!==void 0)c.params=y.params}function Tn(c){if(!c?.timing)return;let y={medianPct:Re(c.timing.medianDeltaPct),meanPct:Re(c.timing.meanDeltaPct),verdict:c.timing.verdict,pass:c.verdict==="pass",effectiveTimingPct:Re(c.thresholds.effectiveTimingPct),matched:!0};if(c.timing.ci95)y.ci95=[Re(c.timing.ci95[0]),Re(c.timing.ci95[1])];if(c.timing.pValue!==void 0)y.pValue=Re(c.timing.pValue);return y}function lt(c,y,w,H){let A={event:"run",protocolVersion:l,schemaVersion:c.schemaVersion,workloadId:y.id,task:Ze(y,y.id),skipped:!0,batch:1,warnings:(w?.warnings??[]).map((Y)=>Y.data?{code:Y.code,data:Y.data}:{code:Y.code})};if(Cn(A,y),H!==void 0)A.noiseFloorPct=Re(H);let ie=Tn(w);if(ie)A.delta=ie;return A}function dt(c){let y=new Map(c.workloads.map((re)=>[re.id,re])),w=c.environment?.noise.floorPct,H=c.measurements.filter((re)=>re.phase==="timing"&&re.timing!==void 0).map((re)=>({run:re,workload:y.get(re.workloadId)})),A=H.length>1?We(H):void 0,ie=new Map((c.comparisons??[]).map((re)=>[re.candidateMeasurementId,re])),Y=new Set(H.map((re)=>re.run.workloadId)),D=new Map;for(let re of c.measurements){if(re.phase!=="cpu"||re.warnings.length===0)continue;let ue=D.get(re.workloadId)??[];D.set(re.workloadId,[...ue,...re.warnings])}let se=c.workloads.filter((re)=>re.skipped&&!Y.has(re.id)).map((re)=>lt(c,re,ie.get(re.id),w));return[...H.map((re)=>{let{run:ue,workload:oe}=re,me=ue.timing,pe=ie.get(ue.id),de={event:"run",protocolVersion:l,schemaVersion:c.schemaVersion,workloadId:ue.workloadId,task:Ze(oe,ue.workloadId),unit:"ns",samples:me.samples.length,batch:me.batch??1,mean:Re(me.mean),median:Re(me.median),stddev:Re(me.stddev),stddevPct:Re(me.mean===0?0:me.stddev/me.mean*100),min:Re(me.min),max:Re(me.max),warnings:[...ue.warnings,...D.get(ue.workloadId)??[],...pe?.warnings??[]].map((he)=>he.data?{code:he.code,data:he.data}:{code:he.code})};if(me.p75!==void 0)de.p75=Re(me.p75);if(me.p99!==void 0)de.p99=Re(me.p99);if(me.mad!==void 0)de.mad=Re(me.mad);if(Cn(de,oe),A)de.relative=Re(me.median/(A.get(re)??me.median));if(oe?.baseline)de.baseline=!0;if(w!==void 0)de.noiseFloorPct=Re(w);let ge=Tn(pe);if(ge)de.delta=ge;return de}),...se]}function pt(c){if(!c.unmatched)return[];let y=(w,H)=>({event:"unmatched",protocolVersion:l,workloadId:w.id,task:Ze(w,w.id),side:H});return[...c.unmatched.baseOnly.map((w)=>y(w,"base")),...c.unmatched.candOnly.map((w)=>y(w,"cand"))]}function ft(c,y){let w=c.comparisonSummary,H=(y.unmatched?.baseOnly.length??0)+(y.unmatched?.candOnly.length??0),A={event:"summary",protocolVersion:l,command:y.command,matched:w?.matched??0,regressed:w?.regressed??0,improved:w?.improved??0,unchanged:w?.unchanged??0,unmatched:H,geomeanPct:w?.geomeanPct!==void 0?w.geomeanPct:null,effectiveTimingPct:Re(w?.effectiveTimingPct??0),verdict:y.exitCode===0?"pass":"fail",exitCode:y.exitCode};if(y.command==="ci"){if(A.cached=y.cached??0,A.executed=y.executed??0,A.failed=y.failed??0,A.missingBaseline=y.missingBaseline??0,y.baseline)A.baseline=y.baseline}if(c.environment)A.noiseFloorPct=Re(c.environment.noise.floorPct);if(y.baseGit||y.candGit)A.git={...y.baseGit&&{base:y.baseGit},...y.candGit&&{cand:y.candGit}};if(y.exportedTo)A.exportedTo=y.exportedTo;return A}var In={name:"minimal",async render(c,y={}){let w=[...dt(c)];if(y.protocol)w.push(...pt(y.protocol)),w.push(ft(c,y.protocol));let H=w.map((A)=>JSON.stringify(A));return{text:H.length>0?`${H.join(`
13
+ `)}
14
+ `:""}}};var gt="https://www.speedscope.app/file-format-schema.json";function Sn(c){return c?.label??c?.command?.join(" ")??c?.entry?.task??"profile"}var Dn={name:"speedscope",async render(c,y={}){let w=Se(c,y.measurementId),H=new Map(c.workloads.map((ie)=>[ie.id,ie]));return{files:w.map((ie)=>{let Y=ie.cpu,{nodes:D}=Y,se=Ne(Y),le=Y.samples?.nodeIds??[],re=Y.samples?.timeDeltasUs??[],ue=Array(se.count);for(let de of se.order){let ge=se.parentIx[de],he=D[de].frameIx;ue[de]=ge===-1?[he]:[...ue[ge],he]}let oe=Array(le.length);for(let de=0;de<le.length;de++){let ge=se.indexOf(le[de]);oe[de]=ge===-1?[]:ue[ge]}let me=0;for(let de=0;de<re.length;de++)me+=re[de];let pe={$schema:gt,exporter:"ostia",name:Sn(H.get(ie.workloadId)),activeProfileIndex:0,shared:{frames:Y.frames.map((de)=>({name:de.name||"(anonymous)",file:de.url,line:de.line!==void 0?de.line+1:void 0}))},profiles:[{type:"sampled",name:Sn(H.get(ie.workloadId)),unit:"microseconds",startValue:0,endValue:me,samples:oe,weights:re}]};return{path:`${ie.id}.speedscope.json`,content:`${JSON.stringify(pe,null,2)}
15
+ `}})}}};function ht(c){return(c/1e6).toFixed(3)}function bt(c){if(c<1024)return`${c.toFixed(0)}B`;if(c<1048576)return`${(c/1024).toFixed(2)}KB`;return`${(c/1048576).toFixed(2)}MB`}var Nn={name:"table",async render(c){let y=c.measurements.filter((be)=>be.phase==="timing"&&be.timing!==void 0),w=new Map(c.workloads.map((be)=>[be.id,be])),H=c.environment?[He(c.environment),""]:[],A=c.workloads.filter((be)=>be.skipped&&!y.some((Me)=>Me.workloadId===be.id));if(y.length===0&&A.length===0){let be=On(c,w);return{text:be.length>0?`${[...H,...be].join(`
16
+ `)}
17
+ `:`(no timing runs)
18
+ `}}let ie=new Map(y.map((be)=>[be.workloadId,be])),Y=[],D=[];for(let be of c.workloads){let Me=ie.get(be.id),$e=n(be);if(Me){let Ce={kind:"measured",run:Me,workload:be,label:$e};Y.push(Ce),D.push(Ce)}else if(be.skipped)Y.push({kind:"skipped",workload:be,label:$e})}let se=new Map(c.measurements.filter((be)=>be.phase==="memstats"&&be.memory?.bytesPerOp!==void 0).map((be)=>[be.workloadId,be.memory.bytesPerOp])),le=se.size>0,re=D.length>1,ue=We(D),oe=new Map,me=new Map,pe;for(let be of Y){let Me=Ge(be.workload);if(Me!==pe){if(Me!==void 0)me.set(be,Me);pe=Me}oe.set(be,Me!==void 0?" ":"")}let de=Math.max(4,...Y.map((be)=>oe.get(be).length+be.label.length)),ge=10,he=18,xe=18,we=10,ae=[...H],fe=le?` ${"Alloc/op".padEnd(we)}`:"",ce=`${"Task".padEnd(de)} ${"Median".padEnd(ge)} ${"Spread".padEnd(he)} ${"Range".padEnd(xe)}${fe}${re?" Relative":""}`;ae.push(ce),ae.push("-".repeat(ce.length));let ye=[];for(let be of Y){let Me=me.get(be);if(Me!==void 0)ae.push(`${Me}:`);let $e=oe.get(be);if(be.kind==="skipped"){ae.push(`${($e+be.label).padEnd(de)} - skipped`);continue}let{run:Ce,label:Ae,workload:Ke}=be,Ie=Ce.timing,Ee=Be(Ie.median),Bn=Ie.p75??Ie.median,An=Ie.p99??Ie.max,Ln=ve(Ie.median,Ee),_n=`${ve(Bn,Ee)}\u2026${ve(An,Ee)}`,jn=`${ve(Ie.min,Ee)}\u2026${ve(Ie.max,Ee)}`,Je=`${($e+Ae).padEnd(de)} ${Ln.padEnd(ge)} ${_n.padEnd(he)} ${jn.padEnd(xe)}`;if(le){let De=Ke?se.get(Ke.id):void 0,Vn=De!==void 0?bt(De):"";Je+=` ${Vn.padEnd(we)}`}if(re){let De=Ie.median/(ue.get(be)??Ie.median);Je+=` ${ze(De,!!Ke?.baseline)}`}if(ae.push(Je),Ce.warnings.length>0)ae.push(`${" ".repeat($e.length)} ! ${Ce.warnings.map((De)=>De.code).join(", ")}`),ye.push(be)}if(ye.length>0){ae.push(""),ae.push("Warnings:");for(let be of ye)for(let Me of be.run.warnings)ae.push(` ${be.label}: ${Me.message}`)}let ke=wt(c,w);if(ke.length>0)ae.push(""),ae.push(...ke);let Pe=On(c,w);if(Pe.length>0)ae.push(""),ae.push(...Pe);return{text:`${ae.map((be)=>be.trimEnd()).join(`
19
+ `)}
20
+ `}}};function On(c,y){if(!c.comparisons||c.comparisons.length===0)return[];let w=[],H=new Map(c.measurements.map((Y)=>[Y.id,Y])),A=c.comparisons.flatMap((Y)=>Y.warnings??[]).find((Y)=>Y.code==="environment-mismatch");if(A)w.push(`\u26A0 ${A.message}`,"");let ie=[];for(let Y of c.comparisons){let D=H.get(Y.candidateMeasurementId),se=y.get(D?.workloadId??Y.candidateMeasurementId),le=se?n(se):Y.candidateMeasurementId,re=Y.verdict==="pass"?"\u2713":"\u2717";if(w.push(`${re} ${le}`),Y.timing){let oe=(me)=>`${me>=0?"+":""}${me.toFixed(1)}%`;if(Y.timing.ci95&&Y.timing.pValue!==void 0){let me=Y.timing.pValue<0.001?"p<0.001":`p=${Y.timing.pValue.toFixed(3)}`;w.push(` timing: ${oe(Y.timing.medianDeltaPct)} median, 95% CI [${oe(Y.timing.ci95[0])}, ${oe(Y.timing.ci95[1])}], ${me} (${Y.timing.verdict})`)}else w.push(` timing: ${oe(Y.timing.medianDeltaPct)} median (${Y.timing.verdict})`)}if(Y.frames)for(let oe of Y.frames.slice(0,Fn)){if(Math.abs(oe.deltaPct)<Fe)continue;let me=oe.deltaPct>0?"+":"";w.push(` frame ${oe.name}: ${me}${oe.deltaPct.toFixed(1)}% self-time (${(oe.baseSelfUs/1000).toFixed(2)}ms -> ${(oe.candSelfUs/1000).toFixed(2)}ms)`)}if(Y.heapTypes)for(let oe of Y.heapTypes.slice(0,Wn)){if(Math.abs(oe.deltaPct)<Fe)continue;let me=oe.deltaPct>0?"+":"";w.push(` heap ${oe.type}: ${me}${oe.deltaPct.toFixed(1)}% count (${oe.baseCount} -> ${oe.candCount})`)}let ue=(Y.warnings??[]).filter((oe)=>oe.code!=="environment-mismatch");if(ue.length>0){w.push(` ! ${ue.map((oe)=>oe.code).join(", ")}`);for(let oe of ue)ie.push({label:le,message:oe.message})}}if(ie.length>0){w.push("","Comparison warnings:");for(let Y of ie)w.push(` ${Y.label}: ${Y.message}`)}return w}var Fn=5,Wn=5;function wt(c,y){let w=[];for(let H of c.measurements){if(H.phase!=="cpu"&&H.phase!=="heap")continue;let A=y.get(H.workloadId),ie=A?n(A):H.workloadId;if(H.phase==="cpu")if(H.cpu){w.push(`CPU capture - ${ie} (instrumented, ${H.cpu.samplingIntervalUs}\xB5s interval, diagnostic wall ${ht(H.diagnosticWallNs??0)}ms)`);let Y=H.cpu.totals.reduce((D,se)=>D+se.selfUs,0)||1;for(let D of H.cpu.totals.slice(0,Fn)){let se=H.cpu.frames[D.frameIx],le=(D.selfUs/Y*100).toFixed(1);w.push(` ${le.padStart(5)}% ${(D.selfUs/1000).toFixed(2).padStart(8)}ms self ${se?.name??"?"}`)}}else w.push(`CPU capture - ${ie} (instrumented, no evidence captured)`);else if(H.heap){let Y=((H.heap.heapSizeBytes??0)/1e6).toFixed(2);w.push(`Heap snapshot - ${ie} (instrumented, ${H.heap.objectCount??"?"} objects, ${Y}MB)`);for(let D of H.heap.typeCounts.slice(0,Wn))w.push(` ${String(D.count).padStart(6)} ${D.type}`)}else w.push(`Heap snapshot - ${ie} (instrumented, no evidence captured)`);for(let Y of H.artifacts)w.push(` artifact: ${Y.path}`);for(let Y of H.warnings)w.push(` ! ${Y.message}`)}return w}var o={table:Nn,json:wn,markdown:$n,jsonl:yn,minimal:In,collapsed:hn,mermaid:vn,speedscope:Dn,cpuprofile:bn};async function Q(c={}){let y=x();if(y.length===0)throw Error("run(): no tasks registered - call group()/task() before run() in the same file.");let w=y.filter((D)=>D.only),H=w.length>0?w:y;if(w.length>0)process.stderr.write(`bench: ${w.length} task(s) selected by .only
21
+ `);let A=v(H,c.filter);if(A.length===0)throw Error(`run(): filter ${JSON.stringify(c.filter)} matched zero of ${H.length} registered task(s).`);let ie=Bun.main,Y=await P(ie,A,c);if(!c.quiet){let D=c.format??"table",{text:se}=await o[D].render(Y,{});if(se)process.stdout.write(se)}return Y}function ee(c,y){let w=Object.keys(c),H=(A,ie)=>{if(A===w.length){X(ie,()=>y(ie));return}let Y=w[A];for(let D of c[Y])H(A+1,{...ie,[Y]:D})};H(0,{})}function ne(c){return c}var en=1000;async function _(c){if(c.samples!==void 0&&(!Number.isFinite(c.samples)||c.samples<1))throw RangeError(`time: samples must be >= 1, got ${c.samples}`);if(c.minSamples!==void 0&&(!Number.isFinite(c.minSamples)||c.minSamples<1))throw RangeError(`time: minSamples must be >= 1, got ${c.minSamples}`);if(c.warmup!==void 0&&(!Number.isFinite(c.warmup)||c.warmup<0))throw RangeError(`time: warmup must be >= 0, got ${c.warmup}`);if(c.budgetMs!==void 0&&!Number.isFinite(c.budgetMs))throw RangeError(`time: budgetMs must be finite, got ${c.budgetMs}`);let y=a({samples:c.samples??null,budgetMs:c.budgetMs??null,minSamples:c.minSamples??null,warmup:c.warmup??null,cpu:c.cpu??!1,heap:c.heap??!1,cpuIntervalUs:c.cpuIntervalUs??en}),H=`${c.outDir??Ue}/artifacts`,A=c.noiseCheck===!1?void 0:p(),ie=A?F(A):void 0,Y=[],D=[],se=c.commands.map((me)=>{let pe=typeof me==="string"||Array.isArray(me)?{command:me}:me,de=Array.isArray(pe.command)?pe.command:b(pe.command),ge=pe.prepare??c.prepare,he=pe.timeSource??c.timeSource,xe=pe.timeoutMs??c.timeoutMs,we=pe.ignoreExitCodes??c.ignoreExitCodes,ae=pe.failOnNonzero??c.failOnNonzero,fe=k(de,pe.label??(Array.isArray(pe.command)?void 0:pe.command),{prepare:ge,timeSource:he});return{argv:de,workload:fe,prepare:ge,timeSource:he,timeoutMs:xe,ignoreExitCodes:we,failOnNonzero:ae}}),le=(c.interleave??!0)&&se.length>1,re=(me)=>({argv:me.argv,cwd:c.cwd,env:c.env,samples:c.samples,budgetMs:c.budgetMs,minSamples:c.minSamples,warmup:c.warmup,prepare:me.prepare,timeSource:me.timeSource,timeoutMs:me.timeoutMs,ignoreExitCodes:me.ignoreExitCodes,failOnNonzero:me.failOnNonzero,signal:c.signal}),ue=se.map((me)=>qe(re(me))),oe=async(me)=>{let{argv:pe,workload:de,prepare:ge}=se[me];Y.push(de);let he=ue[me].result(),xe=m({workload:de,configFingerprint:y,trials:he.trials,timing:he.timing,warnings:ie&&D.length===0?[...he.warnings,ie]:he.warnings,interleaved:le?!0:void 0});if(D.push(xe),!c.signal?.aborted)D.push(...await yt({workload:de,argv:pe,timingMeasurementId:xe.id,cfgFp:y,opts:c,artifactDir:H,prepare:ge}))};if(le){for(let pe of ue)await pe.warmup();let me=!0;while(me){me=!1;for(let pe of ue)if(await pe.step())me=!0}for(let pe=0;pe<se.length;pe++)await oe(pe)}else for(let me=0;me<se.length;me++)await Qe(ue[me]),await oe(me);if(c.signal?.aborted&&D.length>0){let me=D[D.length-1];me.warnings=[...me.warnings,Un()]}return t(Y,D,A)}function Un(){return{code:"aborted",message:"Run was cancelled before it finished; this document holds whatever measurements had already completed."}}async function yt({workload:c,argv:y,timingMeasurementId:w,cfgFp:H,opts:A,artifactDir:ie,prepare:Y}){let D=[],se=async(le)=>{if(Y)await N(Y,{phase:le,index:0},{cwd:A.cwd,env:A.env})};if(A.cpu){await se("cpu");let le=`${w}-cpu.cpuprofile`,re=await nn({argv:y,cwd:A.cwd,env:A.env,artifactDir:ie,fileName:le,intervalUs:A.cpuIntervalUs??en});D.push(await En({workload:c,phase:"cpu",configFingerprint:H,diagnosticWallNs:re.diagnosticWallNs,exitCode:re.exitCode,cpu:re.cpu,artifactPath:re.artifactPath,artifactKind:"cpuprofile",warnings:re.warnings}))}if(A.heap){await se("heap");let le=`${w}-heap.heapsnapshot`,re=await rn({argv:y,cwd:A.cwd,env:A.env,artifactDir:ie,fileName:le});D.push(await En({workload:c,phase:"heap",configFingerprint:H,diagnosticWallNs:re.diagnosticWallNs,exitCode:re.exitCode,heap:re.heap,artifactPath:re.artifactPath,artifactKind:"heapsnapshot",warnings:re.warnings}))}return D}async function En(c){let y=`${c.workload.id}-${c.phase}-${c.configFingerprint}`,w=c.artifactPath?[await K(y,c.artifactKind,c.artifactPath)]:[];return d({workload:c.workload,phase:c.phase,configFingerprint:c.configFingerprint,diagnosticWallNs:c.diagnosticWallNs,exitCode:c.exitCode,cpu:c.cpu,heap:c.heap,warnings:c.warnings,artifacts:w})}async function te(c,y={}){let w=q(c),H=a({intervalUs:y.intervalUs??en,origin:y.origin??"inspector"}),A=(D)=>D.samples?.nodeIds.length===0?[{code:"empty-profile",message:"In-process capture produced zero samples."}]:[];if(y.signal?.aborted){let D=Bun.nanoseconds(),se=await c(),le=d({workload:w,phase:"cpu",configFingerprint:H,diagnosticWallNs:Bun.nanoseconds()-D,warnings:[Un()],artifacts:[]});return{result:se,measurement:le,document:t([w],[le])}}let ie=y.origin==="jsc"?await E(c,y):{...await sn(c,y),jit:void 0},Y=d({workload:w,phase:"cpu",configFingerprint:H,diagnosticWallNs:ie.diagnosticWallNs,cpu:ie.cpu,jit:ie.jit,warnings:A(ie.cpu),artifacts:[]});return{result:ie.result,measurement:Y,document:t([w],[Y])}}
22
+ export{u,B,M,U,T,s,W,C,j,L,G,f,J,g,n,Z,l,o,Q,ee,ne,_,te};
package/cli.js CHANGED
@@ -1,17 +1,30 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- import{v,R,N,c,l,b,M,w,r,C}from"./chunk-h6579788.js";import{e,m,n,p,i,o,s,t}from"./chunk-9dqf5cxf.js";function G(u){return e("cache",u.workloadId,u.phase,u.configFingerprint,u.bunVersion,u.toolVersion,u.instrumented,u.inputsDigest??null)}async function z(u,a=process.cwd()){if(u.length===0)return;let f=new Set;for(let k of u){let g=new Bun.Glob(k);for await(let y of g.scan({cwd:a,absolute:!1}))f.add(y)}let d=[...f].sort(),h=await Promise.all(d.map(async(k)=>{let g=await Bun.file(`${a}/${k}`).arrayBuffer();return{path:k,sha256:Bun.CryptoHasher.hash("sha256",g,"hex")}}));return e("inputs",h)}function K(u,a){return`${u}/cache/${a}.json`}async function X(u,a){let f=Bun.file(K(u,a));if(!await f.exists())return;return await f.json()}async function Z(u,a,f){await Bun.write(K(u,a),`${JSON.stringify(f,null,2)}
4
- `)}var ce="node_modules/.cache/ostia",ue=".ostia/baselines",me={runs:null,warmup:3,outDir:ce,baselineDir:ue,baseline:"main",cpuIntervalUs:1000,thresholds:l,workloads:[]};function ee(u){return{...me,...u,thresholds:{...l,...u.thresholds??{}}}}async function Q(u){let a=Bun.file(u);if(!await a.exists())return;return ee(await a.json())}async function Y(u){let a=u.startsWith("/")?u:`${process.cwd()}/${u}`;if(!await Bun.file(a).exists())return;let f=await import(a);return ee(f.default??{})}async function O(u){if(u!==void 0)return u.endsWith(".ts")?Y(u):Q(u);return await Y("ostia.config.ts")??Q("ostia.config.json")}function U(u,a){return`${u.baselineDir}/${a??u.baseline}.json`}class L extends Error{path;constructor(u){super(`No baseline document at ${u}. Create one with: ostia time --export-json ${u} <command...>`);this.path=u}}async function V(u,a){let f=[];for(let d of u.workloads){if(d.suites){let j=await R(d.suites,process.cwd()),F=await c({suites:j,outDir:u.outDir,noiseCheck:!1,budgetMs:u.bench?.budgetMs,samples:u.bench?.samples,minSamples:u.bench?.minSamples,gc:u.bench?.gc,cpu:u.bench?.cpu,alloc:u.bench?.alloc,filter:u.bench?.filter,isolate:u.bench?.isolate,preload:u.bench?.preload,jobs:typeof u.bench?.jobs==="number"?u.bench.jobs:void 0});for(let P of F.workloads){let A=F.measurements.find((B)=>B.workloadId===P.id&&B.phase==="timing");if(!A)continue;f.push({workload:P,status:"executed",run:A})}continue}let h=p(d.command,d.label,{prepare:d.prepare,timeSource:d.timeSource}),k=await z(d.inputs??[]),g=o({runs:u.runs,warmup:u.warmup}),y=typeof d.prepare!=="function",E=G({workloadId:h.id,phase:"timing",configFingerprint:g,bunVersion:Bun.version,toolVersion:m,instrumented:!1,inputsDigest:k}),S=a||!y?void 0:await X(u.outDir,E),D,T;if(S)D=S,T="cached";else{let j=await w({argv:d.command,samples:u.runs??void 0,warmup:u.warmup,prepare:d.prepare,timeSource:d.timeSource});if(D=i({workload:h,configFingerprint:g,trials:j.trials,timing:j.timing,warnings:j.warnings}),y)await Z(u.outDir,E,D);T="executed"}f.push({workload:h,status:T,run:D})}return f}async function te(u){let{config:a}=u,f=U(a,u.baselineName);if(!await Bun.file(f).exists())throw new L(f);let h=await t(f),g=(await V(a,u.full)).map((P)=>({...P})),y=g.filter((P)=>P.status==="executed").length,E=g.filter((P)=>P.status==="cached").length,S=y,D=n(g.map((P)=>P.workload),g.map((P)=>P.run)),T=0,j=0,F=0;for(let P of g){let A=M(h,D,P.workload.id,a.thresholds);if(!A){F++;continue}if(P.comparison=A,A.verdict==="pass")T++;else j++}return D.comparisons=g.map((P)=>P.comparison).filter((P)=>P!==void 0),{document:D,summary:{total:g.length,affected:y,cached:E,executed:S,passed:T,regressed:j,missingBaseline:F,results:g}}}function se(u){let a=[];if(a.push(`${u.total} workloads`),a.push(`${u.affected} affected by this change`),a.push(`${u.cached} cached`),a.push(`${u.executed} executed`),u.missingBaseline>0)a.push(`${u.missingBaseline} skipped (no matching baseline workload)`);let f=u.results.filter((d)=>d.comparison?.verdict==="fail").map((d)=>{let h=d.comparison.timing,k=d.workload.label??d.workload.command?.join(" ")??d.workload.id;return h?`${h.medianDeltaPct>0?"+":""}${h.medianDeltaPct.toFixed(1)}% median on ${k}`:k});return a.push(`${u.passed} passed ${u.regressed} regressed${f.length>0?` (${f.join(", ")})`:""}`),a.push(""),a.push(`Profile CI: ${u.regressed>0?"\u2717":"\u2713"}`),`${a.join(`
3
+ import{e,b,w,t,k,m,a,c,r,p}from"./chunk-2s4xk1mg.js";import{u,B,M,U,T,s,W,C,j,L,G,f,J,g,n,l,o,_}from"./chunk-dpxy38mq.js";function he(d){return e("cache",d.workloadId,d.phase,d.configFingerprint,d.bunVersion,d.toolVersion,d.instrumented,d.inputsDigest??null)}async function ge(d,i=process.cwd()){if(d.length===0)return;let h=await C(d,i),v=await Promise.all(h.map(async(y)=>{let x=await Bun.file(`${i}/${y}`).arrayBuffer();return{path:y,sha256:Bun.CryptoHasher.hash("sha256",x,"hex")}}));return e("inputs",v)}function be(d,i){return`${d}/cache/${i}.json`}async function we(d,i){let h=Bun.file(be(d,i));if(!await h.exists())return;return await h.json()}async function ke(d,i,h){await Bun.write(be(d,i),`${JSON.stringify(h,null,2)}
4
+ `)}var ye=600000;class ne extends Error{path;constructor(d){super(`No baseline document at ${d}. Create one with: ostia time --export-json ${d} <command...>`);this.path=d}}class se extends Error{path;missing;total;constructor(d,i,h){super(`${i} of ${h} configured workload(s) have no matching row in baseline ${d} (by workload id). Re-seed with: ostia baseline save`);this.path=d;this.missing=i;this.total=h}}function Re(d,i,h){if(d)return d;return i===h?"fail":"warn"}function De(d,i=[]){let h=new Set(i),v=d.filter((y)=>!y.timedOut&&!y.timeSourceNoMatch).map((y)=>y.exitCode).filter((y)=>y!==void 0);return v.length>0&&v.every((y)=>y!==0&&!h.has(y))}async function le(d,i){let h=d.noiseCheck===!1?void 0:p(),v=[];for(let y of d.workloads){if(y.suites){let S=await L(y.suites,process.cwd()),I=await f({suites:S,outDir:d.outDir,noiseCheck:!1,budgetMs:d.bench?.budgetMs,samples:d.bench?.samples,minSamples:d.bench?.minSamples,gc:d.bench?.gc,cpu:d.bench?.cpu,alloc:d.bench?.alloc,filter:d.bench?.filter,isolate:d.bench?.isolate,preload:d.bench?.preload,jobs:typeof d.bench?.jobs==="number"?d.bench.jobs:void 0,timeoutMs:d.bench?.timeoutMs??ye});for(let H of I.workloads){let K=I.measurements.find((X)=>X.workloadId===H.id&&X.phase==="timing");if(!K)continue;v.push({workload:H,status:"executed",run:K,harnessFailed:!1})}continue}let x=k(y.command,y.label,{prepare:y.prepare,timeSource:y.timeSource}),A=await ge(y.inputs??[]),N=a({runs:d.runs,warmup:d.warmup}),E=typeof y.prepare!=="function",q=he({workloadId:x.id,phase:"timing",configFingerprint:N,bunVersion:Bun.version,toolVersion:w,instrumented:!1,inputsDigest:A}),V=i||!E?void 0:await we(d.outDir,q),R,D;if(V)R=V,D="cached";else{let S=await J({argv:y.command,samples:d.runs??void 0,warmup:d.warmup,prepare:y.prepare,timeSource:y.timeSource,timeoutMs:y.timeoutMs??ye,ignoreExitCodes:y.ignoreExitCodes,failOnNonzero:y.failOnNonzero});if(R=m({workload:x,configFingerprint:N,trials:S.trials,timing:S.timing,warnings:S.warnings}),E)await ke(d.outDir,q,R);D="executed"}v.push({workload:x,status:D,run:R,harnessFailed:De(R.trials,y.ignoreExitCodes)})}return{results:v,environment:h}}async function ve(d){let{config:i}=d,h=s(i,d.baselineName);if(!await Bun.file(h).exists())throw new ne(h);let y=await r(h),{results:x,environment:A}=await le(i,d.full),N=x.map((P)=>({...P})),E=N.filter((P)=>P.status==="executed").length,q=N.length-E,V=N.filter((P)=>P.harnessFailed).length,R=t(N.map((P)=>P.workload),N.map((P)=>P.run),A),D=0,S=0,I=0;for(let P of N){let ie=U(y,R,P.workload.id,i.thresholds);if(!ie){I++;continue}if(P.comparison=ie,ie.verdict==="pass")D++;else S++}if(I>0){if(Re(i.onMissingBaseline,I,N.length)==="fail")throw new se(h,I,N.length)}let H=N.map((P)=>P.comparison).filter((P)=>P!==void 0);R.comparisons=H;let K=new Set(y.workloads.map((P)=>P.id)),X=new Set(R.workloads.map((P)=>P.id)),re={baseOnly:y.workloads.filter((P)=>!X.has(P.id)),candOnly:R.workloads.filter((P)=>!K.has(P.id))};R.unmatched={baseOnly:re.baseOnly.map((P)=>P.id),candOnly:re.candOnly.map((P)=>P.id)};let de=0,pe=0,fe=0;for(let P of H){if(!P.timing)continue;if(P.timing.verdict==="regressed")de++;else if(P.timing.verdict==="improved")pe++;else fe++}let Ie=Math.max(i.thresholds.timingPct,y.environment?.noise.floorPct??0,A?.noise.floorPct??0);return R.comparisonSummary={matched:H.length,regressed:de,improved:pe,unchanged:fe,geomeanPct:B(H),effectiveTimingPct:Ie,verdict:H.some((P)=>P.verdict==="fail")?"fail":"pass"},{document:R,summary:{total:N.length,cached:q,executed:E,passed:D,regressed:S,missingBaseline:I,failed:V,results:N,unmatched:re},baseline:y}}function Ce(d){let i=[];if(i.push(`${d.total} workloads`),i.push(`${d.cached} cached`),i.push(`${d.executed} executed`),d.missingBaseline>0)i.push(`${d.missingBaseline} skipped (no matching baseline workload)`);if(d.failed>0){let v=d.results.filter((y)=>y.harnessFailed).map((y)=>n(y.workload));i.push(`${d.failed} failed (harness error, every trial exited non-zero: ${v.join(", ")})`)}let h=d.results.filter((v)=>v.comparison?.verdict==="fail").map((v)=>{let y=v.comparison.timing,x=n(v.workload);return y?`${y.medianDeltaPct>0?"+":""}${y.medianDeltaPct.toFixed(1)}% median on ${x}`:x});return i.push(`${d.passed} passed ${d.regressed} regressed${h.length>0?` (${h.join(", ")})`:""}`),i.push(""),i.push(`Profile CI: ${d.regressed>0||d.failed>0?"\u2717":"\u2713"}`),`${i.join(`
5
5
  `)}
6
- `}async function ne(u,a){let f=await V(u,!1),d=n(f.map((k)=>k.workload),f.map((k)=>k.run)),h=U(u,a);return await s(d,h),h}async function re(u){let a=[];try{let d=new Bun.Glob("*.json");for await(let h of d.scan({cwd:u.baselineDir,absolute:!1}))a.push(h.replace(/\.json$/,""))}catch{return[]}a.sort();let f=[];for(let d of a){let h=U(u,d);try{let k=await t(h);f.push({name:d,path:h,createdAt:k.createdAt,toolVersion:k.toolVersion,bunVersion:k.bunVersion,workloads:k.workloads.length,...k.git!==void 0&&{git:k.git}})}catch{}}return f}async function q(u,a){if(u.text)process.stdout.write(u.text);if(!u.files||u.files.length===0)return;if(a)for(let f of u.files){let d=f.path?`${a}/${f.path}`:a;await Bun.write(d,f.content),process.stdout.write(`wrote ${d}
7
- `)}else if(u.files.length===1)process.stdout.write(u.files[0].content);else for(let f of u.files)process.stdout.write(`--- ${f.path??"(unnamed)"} ---
8
- ${f.content}
9
- `)}var de=`ostia time [flags] <command...>
6
+ `}async function xe(d,i){let{results:h,environment:v}=await le(d,!1),y=t(h.map((A)=>A.workload),h.map((A)=>A.run),v),x=s(d,i);return await c(y,x),x}async function Pe(d){let i=[];try{let v=new Bun.Glob("*.json");for await(let y of v.scan({cwd:d.baselineDir,absolute:!1}))i.push(y.replace(/\.json$/,""))}catch{return[]}return i.sort(),(await Promise.all(i.map(async(v)=>{let y=s(d,v);try{let x=await r(y);return{name:v,path:y,createdAt:x.createdAt,toolVersion:x.toolVersion,bunVersion:x.bunVersion,workloads:x.workloads.length,...x.git!==void 0&&{git:x.git}}}catch{return}}))).filter((v)=>v!==void 0)}function Z(d){return d instanceof Error?d.message:String(d)}class F extends Error{}function O(d,i,h){process.stderr.write(i.endsWith(`
7
+ `)?i:`${i}
8
+ `),process.stderr.write(`${JSON.stringify({event:"error",protocolVersion:l,code:d,message:i.split(`
9
+ `)[0],...h&&{data:h}})}
10
+ `)}function Q(d,i){if(!(d instanceof F))throw d;return O("invalid-flag",`${d.message}
11
+ Run 'ostia ${i} --help'.`),2}function z(d,i,h={}){if(h.allowAuto&&i==="auto")return j();let v=h.min??1,y=Number(i);if(!Number.isInteger(y)||y<v)throw new F(`Invalid ${d} "${i}": expected an integer \u2265 ${v}${h.allowAuto?' (or "auto")':""}`);return y}function $e(d,i,h={}){let v=h.min??0,y=Number(i);if(!Number.isFinite(y)||y<v)throw new F(`Invalid ${d} "${i}": expected a number \u2265 ${v}`);return y}var ee=["table","json","jsonl","markdown","minimal"],me=["collapsed","mermaid","speedscope","cpuprofile"],Fe=[...ee,...me];function te(d,i){if(i.includes(d))return!0;return O("invalid-flag",`Unknown --format "${d}". Expected one of: ${i.join(", ")}`),!1}var ce=`No CPU evidence in this document; rerun with --cpu (ostia time) or --cpu (ostia bench)
12
+ `;function Ae(d){return d.measurements.some((i)=>i.phase==="cpu")}async function ue(d,i,h={}){if(i.exportJson)await c(d,i.exportJson);if(i.quiet)return 0;if(me.includes(i.format)&&!Ae(d))return O("no-cpu-evidence",ce),2;return await Y(await o[i.format].render(d,h)),0}async function ae(d){let i=await T();if(!i){O("config-missing",d?`No ostia.config.json found. "${d}" needs configured workloads.`:"No ostia.config.json found.");return}if(d&&i.workloads.length===0){let h=await W()??"ostia.config.json";O("config-missing",`${h} has no "workloads" configured.`);return}return i}async function Y(d,i){if(d.text)process.stdout.write(d.text);if(!d.files||d.files.length===0)return;if(i)for(let h of d.files){let v=h.path?`${i}/${h.path}`:i;await Bun.write(v,h.content),process.stdout.write(`wrote ${v}
13
+ `)}else if(d.files.length===1)process.stdout.write(d.files[0].content);else for(let h of d.files)process.stdout.write(`--- ${h.path??"(unnamed)"} ---
14
+ ${h.content}
15
+ `)}var Be=`ostia time [flags] <command...>
16
+ ostia time [flags] -- <argv...>
10
17
 
11
- Time one or more commands N times with warmup and report timing statistics.
18
+ Time one or more commands N times with warmup and report timing statistics. Each
19
+ <command> is a string, whitespace-split into argv exactly like hyperfine -N (no shell,
20
+ so no quoting/globbing/pipes/redirection) - it can't express an argument containing a
21
+ space. \`-- <argv...>\` is the escape hatch: everything after -- is one command's argv
22
+ verbatim, space-preserving, not further flag-parsed. It's one more command alongside any
23
+ given as regular arguments, not a replacement for them.
12
24
 
13
25
  Flags:
14
- --samples N exact number of timed trials
26
+ --samples N exact number of timed trials per command (each command gets its
27
+ own N trials, not a total split across them)
15
28
  --budget MS wall-clock time budget for the sampling loop (default: a
16
29
  hyperfine-style ~3s min-total-time loop when neither
17
30
  --samples nor --budget is given)
@@ -26,18 +39,36 @@ Flags:
26
39
  command. Interleaved measurements carry Measurement.interleaved: true.
27
40
  --prepare CMD run CMD before every trial (warmup and --cpu/--heap trials
28
41
  included), unmeasured, in the same cwd; it must exit 0. Whitespace-
29
- split like the commands themselves (no shell). Given once it applies
30
- to every command; given once per command it pairs up in order, so the
31
- same command can be timed warm and cold side by side.
42
+ split like the commands themselves (no shell) - there's no --
43
+ equivalent for --prepare, so a hook needing an argument with a
44
+ space needs ostia.config.ts's array form (prepare: ["a", "b c"])
45
+ instead. Given once it applies to every command; given once per
46
+ command it pairs up in order, so the same command can be timed
47
+ warm and cold side by side. Its stderr is captured (bounded to
48
+ 1 MiB) rather than streamed live, and folded into the error on a
49
+ trial where it times out or exits non-zero.
32
50
  --time-source REGEX take each trial's time from the first REGEX match in the command's
33
51
  own stdout (then stderr), capture group 1, instead of its wall clock -
34
52
  e.g. --time-source "built in (\\d+)ms" for a build tool whose own
35
- summary excludes runtime startup. Every trial must match or the run
36
- aborts. Trials keep wallNs alongside the reported value.
53
+ summary excludes runtime startup. A trial whose output doesn't match
54
+ contributes no sample (a time-source-no-match warning records it); if
55
+ every trial misses, that command has no timing stats. Trials keep
56
+ wallNs alongside the reported value.
37
57
  --time-unit UNIT unit of the --time-source number: ns | us | ms | s (default: ms)
38
58
  --cpu capture one instrumented CPU-profile trial (subprocess --cpu-prof)
39
59
  --heap capture one instrumented heap-snapshot trial (subprocess --heap-prof)
40
60
  --cpu-interval USEC CPU sampling interval in microseconds (default: 1000)
61
+ --timeout MS kill a trial (or --prepare hook) with SIGKILL if it hasn't finished
62
+ after this many ms. No default: unset never times out. A timed-out
63
+ trial contributes no sample; if every trial of a command times out,
64
+ that command has no timing stats.
65
+ --ignore-failure[=CODE,...]
66
+ treat the given exit codes as success (default with no value: every
67
+ code). A matching trial still contributes its sample and gets no
68
+ nonzero-exit warning, as if it had exited 0. Repeatable.
69
+ --fail-on-nonzero stop a command's trial loop after its first non-zero, non-ignored
70
+ exit (that trial's sample is still recorded) instead of always
71
+ running its full sample count.
41
72
  --out-dir PATH directory for captured artifacts (default: node_modules/.cache/ostia)
42
73
  --no-noise-check skip the ~200ms machine noise floor reference measurement
43
74
  --export-json PATH write the full ProfileDocument to PATH
@@ -48,6 +79,11 @@ Flags:
48
79
  Instrumented runs (--cpu, --heap) are labeled separately from clean timing and never
49
80
  mixed into the timing statistics.
50
81
 
82
+ Exit codes: 0 pass, 2 harness error (a command had a non-zero, non-ignored exit; a
83
+ timed-out or --time-source-mismatched command had no timing stats at all; or a bad flag).
84
+ 130 if cancelled with Ctrl-C. 1 is never returned by "time" - it's reserved for
85
+ "compare"/"ci" regressions.
86
+
51
87
  Examples:
52
88
  ostia time "bun ./fixtures/work.ts"
53
89
  ostia time --samples 25 --warmup 3 "bun a.ts" "bun b.ts"
@@ -56,7 +92,10 @@ Examples:
56
92
  ostia time --time-source "built in (\\d+)ms" "bun build.ts"
57
93
  ostia time --cpu --heap "bun src/server.ts"
58
94
  ostia time --format json "bun a.ts"
59
- `,oe=`ostia bench [flags] <suite.ts...>
95
+ ostia time --ignore-failure=3 "bun flaky.ts"
96
+ ostia time --fail-on-nonzero "bun might-hang-if-broken.ts"
97
+ ostia time -- bun -e "console.log('a b')" # argument with a space, unsplit
98
+ `,Ue=Array.from({length:255},(d,i)=>i+1),je=`ostia bench [flags] <suite.ts...>
60
99
 
61
100
  Run in-process benchmark suites (registered via group()/task()). Each suite file runs
62
101
  in its own spawned child process (isolated from CLI startup state).
@@ -77,25 +116,30 @@ Flags:
77
116
  Concurrent CPU-bound processes contend for cores, caches and turbo
78
117
  headroom, so numbers taken at --jobs > 1 are noisier and not
79
118
  like-for-like with a baseline measured at 1. "auto" = CPU count.
80
- --gc Bun.gc(true) between trials (default: off - hides allocation cost).
81
- Per-task { gc } / per-group { gc } override this default.
82
- --cpu capture an extra phase: "cpu" measurement per task (200ms of the
119
+ --gc / --no-gc Bun.gc(true) between trials (default: off - hides allocation cost).
120
+ Per-task { gc } / per-group { gc } override this default; --no-gc /
121
+ --gc on the CLI overrides those and ostia.config.json individually,
122
+ so a config-wide default can be turned off for one invocation.
123
+ --cpu / --no-cpu capture an extra phase: "cpu" measurement per task (200ms of the
83
124
  task looped under the JSC sampling profiler, JIT tiers included) on
84
125
  top of its timing numbers. Per-task { cpu } / per-group { cpu }
85
126
  override this default. Once captured, "ostia compare" reports
86
127
  per-frame CPU deltas the same way it already does for "ostia time --cpu".
87
- --alloc capture an extra phase: "memstats" measurement per task: bytes
128
+ --alloc / --no-alloc capture an extra phase: "memstats" measurement per task: bytes
88
129
  allocated per call, from a Bun.gc(true)-bracketed batch of 100 calls.
89
130
  Per-task { alloc } / per-group { alloc } override this default.
90
131
  --filter REGEX only run tasks whose "group/name" id matches this regex (substring,
91
132
  case-sensitive; unmatched tasks are skipped, not timed)
92
- --isolate give every task its own subprocess instead of sharing its suite
93
- file's, isolating JIT tier state and heap shape between tasks the
94
- way suite files are already isolated from each other. Per-task
133
+ --isolate / --no-isolate give every task its own subprocess instead of sharing its
134
+ suite file's, isolating JIT tier state and heap shape between tasks
135
+ the way suite files are already isolated from each other. Per-task
95
136
  { isolate } / per-group { isolate } override this default.
96
137
  --jobs then pools across those per-task processes, so pair a
97
138
  higher --jobs with --isolate deliberately: overhead now scales
98
139
  with task count, not file count.
140
+ --timeout MS kill a suite file's subprocess (or, under --isolate, one task's
141
+ dedicated subprocess) with SIGKILL if it hasn't finished after this
142
+ many ms. No default: unset never times out.
99
143
  --preload PATH script imported before each suite file loads, in the same
100
144
  subprocess (repeatable; runs in the order given). Use it to
101
145
  install globals (jsdom's document/window) or register a
@@ -109,9 +153,11 @@ Flags:
109
153
  --no-noise-check skip the ~200ms machine noise floor reference measurement
110
154
  --export-json PATH write the full ProfileDocument to PATH
111
155
  --format FORMAT table | json | jsonl | markdown | minimal (default: table)
112
- "minimal" is one compact JSON object per task with no raw sample
113
- array: {task, group, description, params, samples, mean, median,
114
- stddevPct, relative, warnings[{code,data}]} in ns - built to pipe
156
+ "minimal" is protocol v1 (see README's "Using ostia from an AI
157
+ agent"): one JSON "run" event per task, {event, protocolVersion,
158
+ schemaVersion, workloadId, task, group, description, params,
159
+ samples, batch, mean, median, stddevPct, relative,
160
+ warnings[{code,data}]} in ns, no raw sample array - built to pipe
115
161
  into an LLM agent's context.
116
162
  --quiet suppress the rendered report (still writes --export-json)
117
163
  --help show this message
@@ -165,7 +211,7 @@ Examples:
165
211
  ostia bench --preload ./bench/jsdom-setup.ts benches/*.dom.bench.ts
166
212
  ostia bench --bun-flags="--conditions=browser" bench/*.dom.bench.ts
167
213
  ostia bench # picks up suites/preload/jobs from ostia.config.json
168
- `,ae=`ostia compare <base.json> <candidate.json>
214
+ `,Me=`ostia compare <base.json> <candidate.json>
169
215
  ostia compare <candidate.json> --baseline <path.json>
170
216
 
171
217
  Compare two ProfileDocuments (matched by workload id) and rank timing/frame/heap deltas.
@@ -173,14 +219,27 @@ Compare two ProfileDocuments (matched by workload id) and rank timing/frame/heap
173
219
  Flags:
174
220
  --export-json PATH write the resulting document (with comparisons) to PATH
175
221
  --format FORMAT table | json | jsonl | markdown | minimal (default: table)
176
- "minimal" adds delta: {medianPct, verdict, pass} to each task line
222
+ "minimal" is protocol v1 (see README's "Using ostia from an AI
223
+ agent"): a "run" event per task with delta: {medianPct, meanPct,
224
+ verdict, pass, ci95?, pValue?, effectiveTimingPct, matched}, an
225
+ "unmatched" event per workload absent from one side, and a
226
+ trailing "summary" event with the overall verdict and exitCode.
227
+ --timing-pct N override thresholds.timingPct (percent)
228
+ --alpha N override thresholds.alpha (Mann-Whitney significance level)
229
+ --no-config ignore ostia.config.ts/.json; use DEFAULT_THRESHOLDS
177
230
  --quiet suppress the rendered report (still writes --export-json)
178
231
  --help show this message
179
232
 
233
+ Reads ostia.config.ts/.json's "thresholds" when present (same discovery as "ostia ci"),
234
+ else DEFAULT_THRESHOLDS; --timing-pct/--alpha override individual fields on top.
235
+
236
+ Exit codes: 0 pass, 1 at least one workload regressed, 2 nothing was compared (zero
237
+ matched workloads) or a harness error (documents failed to load, or a bad flag).
238
+
180
239
  Examples:
181
240
  ostia compare before.json after.json
182
241
  ostia compare after.json --baseline .ostia/baselines/main.json
183
- `,pe=`ostia report <document.json> [flags]
242
+ `,We=`ostia report <document.json> [flags]
184
243
 
185
244
  Render a saved ProfileDocument. Files, not a GUI for the visualization formats -
186
245
  hand the output to speedscope.app, flamegraph.pl, or a Mermaid renderer.
@@ -208,23 +267,31 @@ Examples:
208
267
  ostia report doc.json --format markdown
209
268
  ostia report doc.json --format speedscope --out-dir node_modules/.cache/ostia/viz
210
269
  ostia report doc.json --format collapsed | flamegraph.pl > flame.svg
211
- `,fe=`ostia ci [--full] [--baseline NAME] [--save-baseline]
270
+ `,Le=`ostia ci [--full] [--baseline NAME] [--save-baseline]
212
271
 
213
272
  Load ostia.config.json, run configured workloads (reusing cached results when their
214
273
  fingerprint is unchanged), compare against the named baseline, and gate on regressions.
215
274
 
216
275
  Flags:
217
- --full ignore the cache; rerun every configured workload
218
- --baseline NAME baseline name (default: config's "baseline" field, or "main")
219
- --save-baseline after a pass (no regressions), write the just-measured document as
220
- the new baseline at the same path just compared against - promotes
221
- today's numbers to tomorrow's floor in one step.
222
- --export-json PATH write the resulting document (with comparisons) to PATH
223
- --quiet suppress the rendered report (still writes --export-json)
224
- --help show this message
276
+ --full ignore the cache; rerun every configured workload
277
+ --baseline NAME baseline name (default: config's "baseline" field, or "main")
278
+ --save-baseline after a pass (no regressions, no harness failures), write the
279
+ just-measured document as the new baseline at the same path
280
+ just compared against - promotes today's numbers to
281
+ tomorrow's floor in one step.
282
+ --export-json PATH write the resulting document (with comparisons) to PATH
283
+ --format FORMAT table | json | jsonl | markdown | minimal (default: table)
284
+ --on-missing-baseline POLICY "warn" or "fail" when a configured workload has no matching
285
+ row in the baseline (default: "fail" when every configured
286
+ workload is missing, "warn" otherwise)
287
+ --no-noise-check skip the ~200ms noise-floor reference measurement (default:
288
+ on; same as ostia.config's noiseCheck: false)
289
+ --quiet suppress the rendered report entirely (still writes --export-json)
290
+ --help show this message
225
291
 
226
- Exit codes: 0 pass, 1 regression, 2 harness error (missing config/baseline, spawn failure).
227
- `,_=`ostia baseline <save|list|show> [args]
292
+ Exit codes: 0 pass, 1 regression, 2 harness error (missing config/baseline, every trial of
293
+ a workload exited non-zero, an "onMissingBaseline: fail" mismatch, or a spawn failure).
294
+ `,oe=`ostia baseline <save|list|show> [args]
228
295
 
229
296
  Manage the baseline ProfileDocuments "ostia ci" gates against and "ostia compare --baseline"
230
297
  reads.
@@ -243,33 +310,24 @@ Examples:
243
310
  ostia baseline list
244
311
  ostia baseline show main
245
312
  ostia baseline show main --format markdown
246
- `;function he(u){let a=[],f=[],d,h,k,g,y,E,S=!0,D=!1,T=!1,j,F,P=!0,A,B="table",W=!1,J=!1;for(let x=0;x<u.length;x++){let I=u[x];switch(I){case"--samples":k=Number(u[++x]);break;case"--budget":g=Number(u[++x]);break;case"--min-samples":y=Number(u[++x]);break;case"--warmup":E=Number(u[++x]);break;case"--no-interleave":S=!1;break;case"--prepare":f.push(u[++x]??"");break;case"--time-source":d=u[++x];break;case"--time-unit":h=u[++x];break;case"--cpu":D=!0;break;case"--heap":T=!0;break;case"--cpu-interval":j=Number(u[++x]);break;case"--out-dir":F=u[++x];break;case"--no-noise-check":P=!1;break;case"--export-json":A=u[++x];break;case"--format":B=u[++x];break;case"--quiet":W=!0;break;case"--help":case"-h":J=!0;break;default:a.push(I)}}return{commands:a,prepare:f,timeSource:d,timeUnit:h,samples:k,budgetMs:g,minSamples:y,warmup:E,interleave:S,cpu:D,heap:T,cpuIntervalUs:j,outDir:F,noiseCheck:P,exportJson:A,format:B,quiet:W,help:J}}var ie=["ns","us","ms","s"];async function be(u){let a=he(u);if(a.help||a.commands.length===0)return process.stdout.write(de),a.help?0:2;if(!(a.format in r))return process.stderr.write(`Unknown --format "${a.format}". Expected one of: ${Object.keys(r).join(", ")}
247
- `),2;if(a.prepare.length>1&&a.prepare.length!==a.commands.length)return process.stderr.write(`--prepare given ${a.prepare.length} times for ${a.commands.length} command(s): give it once (applies to all) or once per command.
248
- `),2;if(a.timeUnit!==void 0&&!ie.includes(a.timeUnit))return process.stderr.write(`Unknown --time-unit "${a.timeUnit}". Expected one of: ${ie.join(", ")}
249
- `),2;if(a.timeSource!==void 0)try{new RegExp(a.timeSource)}catch(g){return process.stderr.write(`Invalid --time-source regex: ${g instanceof Error?g.message:String(g)}
250
- `),2}let f=a.timeSource!==void 0?{pattern:a.timeSource,unit:a.timeUnit}:void 0,d=a.commands.map((g,y)=>({command:g,prepare:a.prepare.length===1?a.prepare[0]:a.prepare[y]})),h;try{h=await C({commands:d,timeSource:f,samples:a.samples,budgetMs:a.budgetMs,minSamples:a.minSamples,warmup:a.warmup,interleave:a.interleave,cpu:a.cpu,heap:a.heap,cpuIntervalUs:a.cpuIntervalUs,outDir:a.outDir,noiseCheck:a.noiseCheck})}catch(g){return process.stderr.write(`Run failed: ${g instanceof Error?g.message:String(g)}
251
- `),2}if(a.exportJson)await s(h,a.exportJson);if(!a.quiet){let y=await r[a.format].render(h,{});await q(y)}return h.measurements.some((g)=>g.trials.some((y)=>y.exitCode!==void 0&&y.exitCode!==0))?1:0}function ge(u){let a=[],f,d,h,k,g=!1,y=!1,E=!1,S,D=!1,T=[],j=[],F,P=!0,A,B="table",W=!1,J=!1;for(let x=0;x<u.length;x++){let I=u[x];if(I==="--bun-flags"||I.startsWith("--bun-flags=")){let H=I.startsWith("--bun-flags=")?I.slice(12):u[++x]??"";j.push(...H.split(/\s+/).filter(Boolean));continue}switch(I){case"--budget":f=Number(u[++x]);break;case"--samples":d=Number(u[++x]);break;case"--min-samples":h=Number(u[++x]);break;case"--jobs":{let H=u[++x];k=H==="auto"?v():Number(H);break}case"--gc":g=!0;break;case"--cpu":y=!0;break;case"--alloc":E=!0;break;case"--filter":S=u[++x];break;case"--isolate":D=!0;break;case"--preload":T.push(u[++x]);break;case"--out-dir":F=u[++x];break;case"--no-noise-check":P=!1;break;case"--export-json":A=u[++x];break;case"--format":B=u[++x];break;case"--quiet":W=!0;break;case"--help":case"-h":J=!0;break;default:a.push(I)}}return{suites:a,budgetMs:f,samples:d,minSamples:h,jobs:k,gc:g,cpu:y,alloc:E,filter:S,isolate:D,preload:T,bunFlags:j,outDir:F,noiseCheck:P,exportJson:A,format:B,quiet:W,help:J}}async function we(u){let a=ge(u);if(a.help)return process.stdout.write(oe),0;if(!(a.format in r))return process.stderr.write(`Unknown --format "${a.format}". Expected one of: ${Object.keys(r).join(", ")}
252
- `),2;let f=await O(),d=await N(a,f?.bench);if(d.suites.length===0)return process.stdout.write(oe),2;if(d.jobs!==void 0&&!(d.jobs>=1))return process.stderr.write(`--jobs expects a positive integer or "auto".
253
- `),2;let h;try{h=await c(d)}catch(k){return process.stderr.write(`Bench failed: ${k instanceof Error?k.message:String(k)}
254
- `),2}if(a.exportJson)await s(h,a.exportJson);if(!a.quiet){let g=await r[a.format].render(h,{});await q(g)}return 0}function ke(u){let a=[],f,d,h="table",k=!1,g=!1;for(let y=0;y<u.length;y++){let E=u[y];switch(E){case"--baseline":f=u[++y];break;case"--export-json":d=u[++y];break;case"--format":h=u[++y];break;case"--quiet":k=!0;break;case"--help":case"-h":g=!0;break;default:a.push(E)}}return{paths:a,baseline:f,exportJson:d,format:h,quiet:k,help:g}}async function ye(u){let a=ke(u);if(a.help)return process.stdout.write(ae),0;let f,d;if(a.baseline)f=a.baseline,d=a.paths[0];else f=a.paths[0],d=a.paths[1];if(!f||!d)return process.stdout.write(ae),2;let h,k;try{[h,k]=await Promise.all([t(f),t(d)])}catch(S){return process.stderr.write(`Failed to load documents: ${S instanceof Error?S.message:String(S)}
255
- `),2}let g=b(h,k),y={...k,comparisons:g};if(a.exportJson)await s(y,a.exportJson);if(!a.quiet){if(h.git&&k.git){let T=(j)=>`${j.sha} (${j.branch}${j.dirty?", dirty":""})`;process.stdout.write(`base ${T(h.git)} \u2192 cand ${T(k.git)}
256
- `)}let D=await r[a.format].render(y,{});await q(D)}return g.some((S)=>S.verdict==="fail")?1:0}function xe(u){let a,f="table",d,h,k=!1;for(let g=0;g<u.length;g++){let y=u[g];switch(y){case"--format":f=u[++g]??"";break;case"--measurement":d=u[++g];break;case"--out-dir":h=u[++g];break;case"--help":case"-h":k=!0;break;default:a=y}}return{path:a,format:f,measurementId:d,outDir:h,help:k}}async function le(u){let a=xe(u);if(a.help||!a.path)return process.stdout.write(pe),a.help?0:2;if(!(a.format in r))return process.stderr.write(`Unknown --format "${a.format}". Expected one of: ${Object.keys(r).join(", ")}
257
- `),2;let f;try{f=await t(a.path)}catch(k){return process.stderr.write(`Failed to load ${a.path}: ${k instanceof Error?k.message:String(k)}
258
- `),2}let h=await r[a.format].render(f,{measurementId:a.measurementId});if(!h.text&&(!h.files||h.files.length===0))return process.stderr.write(a.measurementId?`No CPU evidence found for measurement "${a.measurementId}".
259
- `:`No CPU evidence found in this document (no cpu-phase measurements). Capture some with "ostia time --cpu ...".
260
- `),2;return await q(h,a.outDir),0}function Ce(u){let a=!1,f,d=!1,h,k=!1,g=!1;for(let y=0;y<u.length;y++)switch(u[y]){case"--full":a=!0;break;case"--baseline":f=u[++y];break;case"--save-baseline":d=!0;break;case"--export-json":h=u[++y];break;case"--quiet":k=!0;break;case"--help":case"-h":g=!0;break}return{full:a,baseline:f,saveBaseline:d,exportJson:h,quiet:k,help:g}}async function Pe(u){let a=Ce(u);if(a.help)return process.stdout.write(fe),0;let f=await O();if(!f)return process.stderr.write(`No ostia.config.json found. "ostia ci" needs configured workloads.
261
- `),2;if(f.workloads.length===0)return process.stderr.write(`ostia.config.json has no "workloads" configured.
262
- `),2;let d;try{d=await te({config:f,full:a.full,baselineName:a.baseline})}catch(h){if(h instanceof L)return process.stderr.write(`${h.message}
263
- `),2;return process.stderr.write(`CI run failed: ${h instanceof Error?h.message:String(h)}
264
- `),2}if(a.exportJson)await s(d.document,a.exportJson);if(a.saveBaseline&&d.summary.regressed===0)await s(d.document,U(f,a.baseline));if(!a.quiet)process.stdout.write(se(d.summary));return d.summary.regressed>0?1:0}async function je(u){if(u.includes("--help")||u.includes("-h"))return process.stdout.write(_),0;let a=u[0],f=await O();if(!f)return process.stderr.write(`No ostia.config.json found. "ostia baseline save" needs configured workloads.
265
- `),2;if(f.workloads.length===0)return process.stderr.write(`ostia.config.json has no "workloads" configured.
266
- `),2;let d=await ne(f,a);return process.stdout.write(`Wrote ${d}
267
- `),0}async function ve(u){if(u.includes("--help")||u.includes("-h"))return process.stdout.write(_),0;let a=await O();if(!a)return process.stderr.write(`No ostia.config.json found.
268
- `),2;let f=await re(a);if(f.length===0)return process.stdout.write(`No baselines found in ${a.baselineDir}.
269
- `),0;for(let d of f){let h=d.git?` ${d.git.sha} (${d.git.branch}${d.git.dirty?", dirty":""})`:"";process.stdout.write(`${d.name} ${d.workloads} workloads created ${d.createdAt} toolVersion ${d.toolVersion}${h}
270
- `)}return 0}async function $e(u){let[a,...f]=u;if(!a||a==="--help"||a==="-h")return process.stdout.write(_),a?0:2;let d=await O();if(!d)return process.stderr.write(`No ostia.config.json found.
271
- `),2;return le([U(d,a),...f])}async function Se(u){let[a,...f]=u;switch(a){case"save":return je(f);case"list":return ve(f);case"show":return $e(f);case void 0:case"--help":case"-h":return process.stdout.write(_),a===void 0?2:0;default:return process.stderr.write(`Unknown "ostia baseline ${a}". Run "ostia baseline --help".
272
- `),2}}async function De(){let[u,...a]=process.argv.slice(2);switch(u){case"time":return be(a);case"bench":return we(a);case"compare":return ye(a);case"report":return le(a);case"ci":return Pe(a);case"baseline":return Se(a);case void 0:case"--help":case"-h":return process.stdout.write(`ostia - Bun-native profile IR engine
313
+ `;function _e(d){let i={commands:[],prepare:[],interleave:!0,cpu:!1,heap:!1,ignoreExitCodes:[],failOnNonzero:!1,noiseCheck:!0,format:"table",quiet:!1,help:!1};for(let h=0;h<d.length;h++){let v=d[h];if(v==="--"){i.argvCommand=d.slice(h+1);break}if(v==="--ignore-failure"||v.startsWith("--ignore-failure=")){let y=v.startsWith("--ignore-failure=")?v.slice(17):void 0;i.ignoreExitCodes.push(...y===void 0?Ue:y.split(",").map(Number));continue}switch(v){case"--samples":i.samples=z("--samples",d[++h],{min:1});break;case"--budget":i.budgetMs=z("--budget",d[++h],{min:1});break;case"--min-samples":i.minSamples=z("--min-samples",d[++h],{min:1});break;case"--warmup":i.warmup=z("--warmup",d[++h],{min:0});break;case"--no-interleave":i.interleave=!1;break;case"--prepare":i.prepare.push(d[++h]??"");break;case"--time-source":i.timeSource=d[++h];break;case"--time-unit":i.timeUnit=d[++h];break;case"--cpu":i.cpu=!0;break;case"--heap":i.heap=!0;break;case"--cpu-interval":i.cpuIntervalUs=z("--cpu-interval",d[++h],{min:1});break;case"--timeout":i.timeoutMs=Number(d[++h]);break;case"--fail-on-nonzero":i.failOnNonzero=!0;break;case"--out-dir":i.outDir=d[++h];break;case"--no-noise-check":i.noiseCheck=!1;break;case"--export-json":i.exportJson=d[++h];break;case"--format":i.format=d[++h];break;case"--quiet":i.quiet=!0;break;case"--help":case"-h":i.help=!0;break;default:if(v.startsWith("-"))throw new F(`Unknown flag "${v}" for "ostia time".`);i.commands.push(v)}}return i}async function Oe(d){let i=new AbortController,h=()=>i.abort();process.on("SIGINT",h);try{return{result:await d(i.signal),aborted:i.signal.aborted}}finally{process.off("SIGINT",h)}}var Ne=["ns","us","ms","s"];async function qe(d){let i;try{i=_e(d)}catch(S){return Q(S,"time")}let h=(i.argvCommand?.length??0)>0;if(i.help||i.commands.length===0&&!h)return process.stdout.write(Be),i.help?0:2;if(!te(i.format,ee))return 2;let v=i.commands.length+(h?1:0);if(i.prepare.length>1&&i.prepare.length!==v)return O("invalid-flag",`--prepare given ${i.prepare.length} times for ${v} command(s): give it once (applies to all) or once per command.`),2;if(i.timeUnit!==void 0&&!Ne.includes(i.timeUnit))return O("invalid-flag",`Unknown --time-unit "${i.timeUnit}". Expected one of: ${Ne.join(", ")}`),2;if(i.timeSource!==void 0)try{new RegExp(i.timeSource)}catch(S){return O("invalid-flag",`Invalid --time-source regex: ${Z(S)}`),2}let y=i.timeSource!==void 0?{pattern:i.timeSource,unit:i.timeUnit}:void 0,x=(S)=>i.prepare.length===1?i.prepare[0]:i.prepare[S],A=i.commands.map((S,I)=>({command:S,prepare:x(I)}));if(h)A.push({command:i.argvCommand,prepare:x(i.commands.length)});let N,E;try{({result:N,aborted:E}=await Oe((S)=>_({commands:A,timeSource:y,samples:i.samples,budgetMs:i.budgetMs,minSamples:i.minSamples,warmup:i.warmup,interleave:i.interleave,cpu:i.cpu,heap:i.heap,cpuIntervalUs:i.cpuIntervalUs,timeoutMs:i.timeoutMs,ignoreExitCodes:i.ignoreExitCodes,failOnNonzero:i.failOnNonzero,outDir:i.outDir,noiseCheck:i.noiseCheck,signal:S})))}catch(S){return O("spawn-failed",`Run failed: ${Z(S)}`),2}let q=await ue(N,i);if(q!==0)return q;if(E)return 130;let V=new Set(i.ignoreExitCodes),R=N.workloads.some((S)=>!N.measurements.some((I)=>I.workloadId===S.id&&I.timing)),D=N.measurements.some((S)=>S.trials.some((I)=>I.exitCode!==void 0&&I.exitCode!==0&&!V.has(I.exitCode)));if(D||R){let S=N.measurements.some((K)=>K.warnings.some((X)=>X.code==="timeout")),I=N.measurements.some((K)=>K.warnings.some((X)=>X.code==="time-source-no-match"));return O(D?"command-failed":S?"timeout":I?"time-source-no-match":"command-failed","One or more commands failed to produce a clean measurement; see the report above for details."),2}return 0}function He(d){let i={suites:[],preload:[],bunFlags:[],noiseCheck:!0,format:"table",quiet:!1,help:!1};for(let h=0;h<d.length;h++){let v=d[h];if(v==="--bun-flags"||v.startsWith("--bun-flags=")){let y=v.startsWith("--bun-flags=")?v.slice(12):d[++h]??"";i.bunFlags.push(...b(y));continue}switch(v){case"--budget":i.budgetMs=z("--budget",d[++h],{min:1});break;case"--samples":i.samples=z("--samples",d[++h],{min:1});break;case"--min-samples":i.minSamples=z("--min-samples",d[++h],{min:1});break;case"--jobs":i.jobs=z("--jobs",d[++h],{min:1,allowAuto:!0});break;case"--gc":i.gc=!0;break;case"--no-gc":i.gc=!1;break;case"--cpu":i.cpu=!0;break;case"--no-cpu":i.cpu=!1;break;case"--alloc":i.alloc=!0;break;case"--no-alloc":i.alloc=!1;break;case"--filter":i.filter=d[++h];break;case"--isolate":i.isolate=!0;break;case"--no-isolate":i.isolate=!1;break;case"--preload":i.preload.push(d[++h]);break;case"--timeout":i.timeoutMs=Number(d[++h]);break;case"--out-dir":i.outDir=d[++h];break;case"--no-noise-check":i.noiseCheck=!1;break;case"--export-json":i.exportJson=d[++h];break;case"--format":i.format=d[++h];break;case"--quiet":i.quiet=!0;break;case"--help":case"-h":i.help=!0;break;default:if(v.startsWith("-"))throw new F(`Unknown flag "${v}" for "ostia bench".`);i.suites.push(v)}}return i}async function Je(d){let i;try{i=He(d)}catch(N){return Q(N,"bench")}if(i.help)return process.stdout.write(je),0;if(!te(i.format,ee))return 2;let h=await T(),v=await G(i,h?.bench);if(v.suites.length===0)return process.stdout.write(je),2;if(v.jobs!==void 0&&!(v.jobs>=1))return O("invalid-flag",'--jobs expects a positive integer or "auto".'),2;let y,x;try{({result:y,aborted:x}=await Oe((N)=>f({...v,signal:N})))}catch(N){return O("spawn-failed",`Bench failed: ${Z(N)}`),2}let A=await ue(y,i);if(A!==0)return A;return x?130:0}function ze(d){let i={paths:[],format:"table",quiet:!1,help:!1,noConfig:!1};for(let h=0;h<d.length;h++){let v=d[h];switch(v){case"--baseline":i.baseline=d[++h];break;case"--export-json":i.exportJson=d[++h];break;case"--format":i.format=d[++h];break;case"--timing-pct":i.timingPct=$e("--timing-pct",d[++h]);break;case"--alpha":i.alpha=$e("--alpha",d[++h]);break;case"--no-config":i.noConfig=!0;break;case"--quiet":i.quiet=!0;break;case"--help":case"-h":i.help=!0;break;default:if(v.startsWith("-"))throw new F(`Unknown flag "${v}" for "ostia compare".`);i.paths.push(v)}}return i}async function Ve(d){let i=u,h="defaults";if(!d.noConfig){let v=await T();if(v)i=v.thresholds,h=await W()??"ostia.config.json"}if(d.timingPct!==void 0||d.alpha!==void 0)i={...i,...d.timingPct!==void 0&&{timingPct:d.timingPct},...d.alpha!==void 0&&{alpha:d.alpha}};return{thresholds:i,source:h}}async function Ge(d){let i;try{i=ze(d)}catch(S){return Q(S,"compare")}if(i.help)return process.stdout.write(Me),0;if(!te(i.format,ee))return 2;let h,v;if(i.baseline)h=i.baseline,v=i.paths[0];else h=i.paths[0],v=i.paths[1];if(!h||!v)return process.stdout.write(Me),2;let y,x;try{[y,x]=await Promise.all([r(h),r(v)])}catch(S){return O("document-load-failed",`Failed to load documents: ${Z(S)}`),2}let{thresholds:A,source:N}=await Ve(i),E=M(y,x,A),q={...x,comparisons:E.comparisons,comparisonSummary:E.summary,unmatched:{baseOnly:E.unmatched.baseOnly.map((S)=>S.id),candOnly:E.unmatched.candOnly.map((S)=>S.id)}},V=i.format==="table"||i.format==="markdown";if(!i.quiet&&V){if(process.stdout.write(`thresholds: ${N}
314
+ `),y.git&&x.git)process.stdout.write(`base ${g(y.git)} \u2192 cand ${g(x.git)}
315
+ `);if(i.format==="table"&&E.summary.effectiveTimingPct>A.timingPct)process.stdout.write(`threshold ${A.timingPct}% (widened to ${E.summary.effectiveTimingPct.toFixed(1)}% by noise floor)
316
+ `)}let R=E.summary.matched===0?2:E.summary.verdict==="fail"?1:0,D=await ue(q,i,{protocol:{command:"compare",exitCode:R,unmatched:E.unmatched,baseGit:y.git,candGit:x.git,...i.exportJson&&{exportedTo:i.exportJson}}});if(D!==0)return D;if(!i.quiet&&(i.format==="table"||i.format==="markdown")&&(E.unmatched.baseOnly.length>0||E.unmatched.candOnly.length>0))process.stdout.write(Ke(E.unmatched,i.format));if(E.summary.matched===0)O("no-matches","No workload matched between base and candidate; nothing was compared.");return R}function Ke(d,i){let h=(y)=>y.map((x)=>n(x)).join(", ");if(i==="markdown"){let y=["### Unmatched",""];if(d.baseOnly.length>0)y.push(`- baseline only: ${h(d.baseOnly)}`);if(d.candOnly.length>0)y.push(`- candidate only: ${h(d.candOnly)}`);return y.push(""),`${y.join(`
317
+ `)}
318
+ `}let v=["","Unmatched:"];if(d.baseOnly.length>0)v.push(` baseline only: ${h(d.baseOnly)}`);if(d.candOnly.length>0)v.push(` candidate only: ${h(d.candOnly)}`);return`${v.join(`
319
+ `)}
320
+ `}function Xe(d){let i={format:"table",help:!1};for(let h=0;h<d.length;h++){let v=d[h];switch(v){case"--format":i.format=d[++h]??"";break;case"--measurement":i.measurementId=d[++h];break;case"--out-dir":i.outDir=d[++h];break;case"--help":case"-h":i.help=!0;break;default:if(v.startsWith("-"))throw new F(`Unknown flag "${v}" for "ostia report".`);if(i.path!==void 0)throw new F(`"ostia report" takes exactly one document path, got "${i.path}" and "${v}".`);i.path=v}}return i}async function Te(d){let i;try{i=Xe(d)}catch(x){return Q(x,"report")}if(i.help||!i.path)return process.stdout.write(We),i.help?0:2;if(!te(i.format,Fe))return 2;let h;try{h=await r(i.path)}catch(x){return O("document-load-failed",`Failed to load ${i.path}: ${Z(x)}`),2}if(me.includes(i.format)&&!i.measurementId&&!Ae(h))return O("no-cpu-evidence",ce),2;let y=await o[i.format].render(h,{measurementId:i.measurementId});if(!y.text&&(!y.files||y.files.length===0))return O("no-cpu-evidence",i.measurementId?`No CPU evidence found for measurement "${i.measurementId}".`:ce),2;return await Y(y,i.outDir),0}function Ze(d){let i={full:!1,saveBaseline:!1,format:"table",quiet:!1,help:!1,noNoiseCheck:!1};for(let h=0;h<d.length;h++){let v=d[h];switch(v){case"--full":i.full=!0;break;case"--baseline":i.baseline=d[++h];break;case"--save-baseline":i.saveBaseline=!0;break;case"--export-json":i.exportJson=d[++h];break;case"--format":i.format=d[++h];break;case"--on-missing-baseline":{let y=d[++h];if(y!=="warn"&&y!=="fail")throw new F(`Invalid --on-missing-baseline "${y}": expected "warn" or "fail".`);i.onMissingBaseline=y;break}case"--no-noise-check":i.noNoiseCheck=!0;break;case"--quiet":i.quiet=!0;break;case"--help":case"-h":i.help=!0;break;default:throw new F(`Unknown flag "${v}" for "ostia ci".`)}}return i}async function Ye(d){let i;try{i=Ze(d)}catch(A){return Q(A,"ci")}if(i.help)return process.stdout.write(Le),0;if(!te(i.format,ee))return 2;let h=await ae("ostia ci");if(!h)return 2;let v={...h,...i.onMissingBaseline!==void 0&&{onMissingBaseline:i.onMissingBaseline},...i.noNoiseCheck&&{noiseCheck:!1}},y;try{y=await ve({config:v,full:i.full,baselineName:i.baseline})}catch(A){if(A instanceof ne||A instanceof se)return O("baseline-missing",A.message),2;return O("spawn-failed",`CI run failed: ${Z(A)}`),2}if(i.exportJson)await c(y.document,i.exportJson);if(i.saveBaseline&&y.summary.regressed===0&&y.summary.failed===0)await c(y.document,s(v,i.baseline));let x=y.summary.failed>0?2:y.summary.regressed>0?1:0;if(y.summary.failed>0){let A=y.summary.results.filter((N)=>N.harnessFailed).map((N)=>n(N.workload));O("command-failed",`${y.summary.failed} workload(s) failed (harness error, every trial exited non-zero): ${A.join(", ")}`)}if(!i.quiet){let A=i.baseline??v.baseline;if(i.format==="table"){if(process.stdout.write(Ce(y.summary)),y.document.comparisons&&y.document.comparisons.length>0)await Y(await o.table.render(y.document,{}))}else if(i.format==="markdown")process.stdout.write(`## ostia ci
321
+
322
+ Baseline: \`${A}\` (\`${s(v,i.baseline)}\`) \xB7 ${y.summary.cached} cached, ${y.summary.executed} executed
323
+
324
+ `),await Y(await o.markdown.render(y.document,{}));else await Y(await o[i.format].render(y.document,{protocol:{command:"ci",exitCode:x,unmatched:y.summary.unmatched,baseGit:y.baseline.git,candGit:y.document.git,baseline:{name:A,path:s(v,i.baseline)},cached:y.summary.cached,executed:y.summary.executed,failed:y.summary.failed,missingBaseline:y.summary.missingBaseline,...i.exportJson&&{exportedTo:i.exportJson}}}))}return x}var Se=/^[A-Za-z0-9._-]+$/;function Ee(d){if(d.startsWith("-"))return`Invalid baseline name "${d}": names can't start with "-".`;if(!Se.test(d))return`Invalid baseline name "${d}": expected to match ${Se}.`;return}async function Qe(d){if(d.includes("--help")||d.includes("-h"))return process.stdout.write(oe),0;if(d.length>1)return O("invalid-flag",`"ostia baseline save" takes at most one name argument, got ${d.length}.
325
+ Run 'ostia baseline --help'.`),2;let i=d[0];if(i!==void 0){let y=Ee(i);if(y)return O("invalid-flag",`${y}
326
+ Run 'ostia baseline --help'.`),2}let h=await ae("ostia baseline save");if(!h)return 2;let v=await xe(h,i);return process.stdout.write(`Wrote ${v}
327
+ `),0}async function et(d){if(d.includes("--help")||d.includes("-h"))return process.stdout.write(oe),0;let i=await ae();if(!i)return 2;let h=await Pe(i);if(h.length===0)return process.stdout.write(`No baselines found in ${i.baselineDir}.
328
+ `),0;for(let v of h){let y=v.git?` ${g(v.git)}`:"";process.stdout.write(`${v.name} ${v.workloads} workloads created ${v.createdAt} toolVersion ${v.toolVersion}${y}
329
+ `)}return 0}async function tt(d){let[i,...h]=d;if(!i||i==="--help"||i==="-h")return process.stdout.write(oe),i?0:2;let v=Ee(i);if(v)return O("invalid-flag",`${v}
330
+ Run 'ostia baseline --help'.`),2;let y=await ae();if(!y)return 2;return Te([s(y,i),...h])}async function nt(d){let[i,...h]=d;switch(i){case"save":return Qe(h);case"list":return et(h);case"show":return tt(h);case void 0:case"--help":case"-h":return process.stdout.write(oe),i===void 0?2:0;default:return O("invalid-flag",`Unknown "ostia baseline ${i}". Run "ostia baseline --help".`),2}}async function st(){let[d,...i]=process.argv.slice(2);switch(d){case"time":return qe(i);case"bench":return Je(i);case"compare":return Ge(i);case"report":return Te(i);case"ci":return Ye(i);case"baseline":return nt(i);case void 0:case"--help":case"-h":return process.stdout.write(`ostia - Bun-native profile IR engine
273
331
 
274
332
  Commands:
275
333
  time Time commands N times and report timing/CPU/heap
@@ -280,5 +338,4 @@ Commands:
280
338
  baseline Manage baseline ProfileDocuments (save/list/show)
281
339
 
282
340
  Run "ostia <command> --help" for details.
283
- `),u===void 0?2:0;default:return process.stderr.write(`Unknown subcommand "${u}". Run "ostia --help".
284
- `),2}}if(import.meta.main)De().then((u)=>process.exit(u));
341
+ `),d===void 0?2:0;default:return O("invalid-flag",`Unknown subcommand "${d}". Run "ostia --help".`),2}}if(import.meta.main)st().then((d)=>process.exit(d));export{F as CliUsageError,z as parseIntFlag};