"use strict";if(process.env.PW_INSTRUMENT_MODULES){let t=require("module"),e=t._load,l={name:"<root>",selfMs:0,totalMs:0,childrenMs:0,children:[]},s=l,o=[];t._load=function(t,l,r){let n,a={name:t,selfMs:0,totalMs:0,childrenMs:0,children:[]};s.children.push(a),o.push(s),s=a;let i=performance.now();try{n=e.apply(this,arguments)}catch(t){throw(s=o.pop()).children.pop(),t}let c=performance.now()-i;return a.totalMs=c,a.selfMs=Math.max(0,c-a.childrenMs),s=o.pop(),s.childrenMs+=c,n},process.on("exit",()=>{let t=0;l.children.forEach(function e(l){t++,l.children.forEach(e)});let e=[],s=l.children.slice().sort((t,e)=>e.totalMs-t.totalMs);for(let t=0;t<s.length;t++)!function t(e,l,s,o,r){if(e.totalMs<1&&r>0)return;let n=`${e.totalMs.toFixed(1).padStart(8)}ms`,a=e.children.length?` (self: ${e.selfMs.toFixed(1)}ms)`:"";o.push(`${n}  ${l}${0===r?"":s?"└── ":"├── "}${e.name}${a}`);let i=l+(0===r?"":s?"    ":"│   "),c=e.children.slice().sort((t,e)=>e.totalMs-t.totalMs);for(let e=0;e<c.length;e++)t(c[e],i,e===c.length-1,o,r+1)}(s[t],"",t===s.length-1,e,0);let o=l.children.reduce((t,e)=>t+e.totalMs,0);process.stderr.write(`
--- Module load tree: ${t} modules, ${o.toFixed(0)}ms total ---
`+e.join("\n")+"\n");let r=new Map;l.children.forEach(function t(e){let l=r.get(e.name);l?(l.selfMs+=e.selfMs,l.totalMs+=e.totalMs,l.count++):r.set(e.name,{selfMs:e.selfMs,totalMs:e.totalMs,count:1}),e.children.forEach(t)});let n=[...r.entries()].sort((t,e)=>e[1].selfMs-t[1].selfMs).slice(0,50).map(([t,{selfMs:e,totalMs:l,count:s}])=>`${e.toFixed(1).padStart(8)}ms self ${l.toFixed(1).padStart(8)}ms total  (x${String(s).padStart(3)})  ${t}`);process.stderr.write(`
--- Top 50 modules by self time ---
`+n.join("\n")+"\n")})}