Files
codegraph/scripts/validation/semantic-update-poll.cjs
T

9 lines
2.1 KiB
JavaScript

const diagnosticEvents=[];require('node:diagnostics_channel').channel('codegraph.semantic.update').subscribe(e=>diagnosticEvents.push({...e,atMs:performance.now()}));
const fs=require('node:fs'),path=require('node:path'),crypto=require('node:crypto'),assert=require('node:assert/strict');const {CodeGraph}=require('../../dist');const {DatabaseSync}=require('node:sqlite');
Object.assign(process.env,{CODEGRAPH_TELEMETRY:'0',CODEGRAPH_PARSE_WORKERS:'2',CODEGRAPH_RESOLVE_WORKERS:'0',CODEGRAPH_SYNTH_TIMINGS:'all'});
const [root,file,out]=process.argv.slice(2),original=fs.readFileSync(path.join(root,file)),rows=[];fs.mkdirSync(path.dirname(out),{recursive:true});
const save=()=>fs.writeFileSync(out,JSON.stringify({root,file,distSHA:crypto.createHash('sha256').update(fs.readFileSync('dist/index.js')).digest('hex'),rows},null,2));
function refs(){const d=new DatabaseSync(path.join(root,'.codegraph/codegraph.db'),{readOnly:true});try{return d.prepare('select status,count(*) n from unresolved_refs group by status').all()}finally{d.close()}}
(async()=>{const g=await CodeGraph.open(root);async function run(name,fn){const eventStart=diagnosticEvents.length;let progress=0;const started=performance.now(),cpu=process.cpuUsage();const result=await fn(p=>{if(p.phase==='parsing')progress=Math.max(progress,p.current)});rows.push({name,wallMs:performance.now()-started,cpu:process.cpuUsage(cpu),maxRSS:process.resourceUsage().maxRSS,parseProgress:progress,diagnostics:diagnosticEvents.slice(eventStart),result,refs:refs()});save();console.log(name,rows.at(-1).wallMs)}
try{for(let i=0;i<3;i++)await run('no-change-'+i,p=>g.sync({onProgress:p}));fs.appendFileSync(path.join(root,file),'\n// semantic update timing fixture\n');await run('ordinary',p=>g.sync({paths:[file],onProgress:p}));await run('indexFiles-unchanged',()=>g.indexFiles([file]));fs.writeFileSync(path.join(root,file),original);await run('restore',p=>g.sync({paths:[file],onProgress:p}));for(let i=0;i<3;i++)await run('final-no-change-'+i,p=>g.sync({onProgress:p}));}finally{fs.writeFileSync(path.join(root,file),original);g.close();save()}})().catch(e=>{console.error(e);process.exitCode=1});