Skip to content

Instantly share code, notes, and snippets.

@jakub-g
Created November 17, 2021 15:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakub-g/fa81f4891789c0ac864119f419092071 to your computer and use it in GitHub Desktop.
Save jakub-g/fa81f4891789c0ac864119f419092071 to your computer and use it in GitHub Desktop.
analyze-tsc-trace-longest-checkSourceFile
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