analyze-tsc-trace-longest-checkSourceFile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as fsp from 'fs/promises'; | |
import { dirname } from 'path'; | |
import { fileURLToPath } from 'url'; | |
// eslint-disable-next-line no-underscore-dangle | |
const __dirname = dirname(fileURLToPath(import.meta.url)); | |
const dirNameLen = __dirname.length; | |
const file = await fsp.readFile('../trace.json'); | |
const trace = JSON.parse(file); | |
const infoByFile = {}; | |
for (const entry of trace) { | |
if (entry.name !== 'checkSourceFile') { | |
continue; | |
} | |
if (entry.ph === 'B') { | |
infoByFile[entry.args.path] = {}; | |
infoByFile[entry.args.path].startTs = entry.ts; | |
} | |
if (entry.ph === 'E') { | |
infoByFile[entry.args.path].endTs = entry.ts; | |
} | |
} | |
const filesAndDurations = []; | |
Object.keys(infoByFile).forEach(filePath => { | |
const info = infoByFile[filePath]; | |
const durationSeconds = Math.floor(info.endTs - info.startTs) / 1_000_000; | |
filesAndDurations.push({ | |
filePath, | |
durationSeconds | |
}); | |
}); | |
filesAndDurations.sort((a, b) => b.durationSeconds - a.durationSeconds); | |
const topFiles = filesAndDurations.slice(0, 10); | |
for (const entry of topFiles) { | |
console.log( | |
`${entry.durationSeconds.toFixed(2)}s: ${entry.filePath.slice( | |
dirNameLen | |
)}` | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment