Skip to content

Commit b1456ae

Browse files
committed
Print both individual and aggregated statistics
1 parent 7fe16cd commit b1456ae

File tree

1 file changed

+36
-58
lines changed

1 file changed

+36
-58
lines changed

src/tsc/executeCommandLine.ts

Lines changed: 36 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -649,72 +649,42 @@ namespace ts {
649649

650650
const overloadMeasures = performance.getOverloadMeasures();
651651
const overloadStatistics = overloadMeasures.slice();
652-
// const overloadMeasureGroups = group(overloadMeasures, s => s.kind + "::" + s.symbolName);
653-
// const overloadStatistics = overloadMeasureGroups.map(measures => ({
654-
// nodePos: measures[0].nodePos,
655-
// symbolName: measures[0].symbolName,
656-
// kind: measures[0].kind,
657-
// candidateCount: measures[0].candidateCount,
658-
// count: measures.length,
659-
// timeMs: measures.map(m => m.timeMs).reduce((a, b) => a + b, 0),
660-
// symbolCount: measures.map(m => m.symbolCount).reduce((a, b) => a + b, 0),
661-
// nodeCount: measures.map(m => m.nodeCount).reduce((a, b) => a + b, 0),
662-
// subtypeCount: measures.map(m => m.subtypeCount).reduce((a, b) => a + b, 0),
663-
// assignableCount: measures.map(m => m.assignableCount).reduce((a, b) => a + b, 0),
664-
// comparableCount: measures.map(m => m.comparableCount).reduce((a, b) => a + b, 0),
665-
// identityCount: measures.map(m => m.identityCount).reduce((a, b) => a + b, 0),
666-
// enumCount: measures.map(m => m.enumCount).reduce((a, b) => a + b, 0),
667-
// }));
652+
const overloadMeasureGroups = group(overloadMeasures, s => s.kind + "::" + s.symbolName + (s.jsxName ? "::" + s.jsxName : ""));
653+
const groupedOverloadStatistics = overloadMeasureGroups.map(measures => ({
654+
symbolName: measures[0].symbolName,
655+
jsxName: measures[0].jsxName,
656+
kind: measures[0].kind,
657+
candidateCount: measures[0].candidateCount,
658+
count: measures.length,
659+
timeMs: measures.map(m => m.timeMs).reduce((a, b) => a + b, 0),
660+
symbolCount: measures.map(m => m.symbolCount).reduce((a, b) => a + b, 0),
661+
nodeCount: measures.map(m => m.nodeCount).reduce((a, b) => a + b, 0),
662+
subtypeCount: measures.map(m => m.subtypeCount).reduce((a, b) => a + b, 0),
663+
assignableCount: measures.map(m => m.assignableCount).reduce((a, b) => a + b, 0),
664+
comparableCount: measures.map(m => m.comparableCount).reduce((a, b) => a + b, 0),
665+
identityCount: measures.map(m => m.identityCount).reduce((a, b) => a + b, 0),
666+
enumCount: measures.map(m => m.enumCount).reduce((a, b) => a + b, 0),
667+
}));
668668

669669
const topCount = 5;
670670

671-
sys.write("Top " + topCount + " by time" + sys.newLine);
672-
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.timeMs - a.timeMs))) {
673-
sys.write(JSON.stringify(stat) + sys.newLine);
674-
}
671+
sys.write("Individual callsites" + sys.newLine);
675672
sys.write(sys.newLine);
676673

677-
sys.write("Top " + topCount + " by symbols" + sys.newLine);
678-
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.symbolCount - a.symbolCount))) {
679-
sys.write(JSON.stringify(stat) + sys.newLine);
680-
}
681-
sys.write(sys.newLine);
674+
writeTop(overloadStatistics, topCount, "time", s => s.timeMs);
675+
writeTop(overloadStatistics, topCount, "symbols", s => s.symbolCount);
676+
writeTop(overloadStatistics, topCount, "subtype checks", s => s.subtypeCount);
677+
writeTop(overloadStatistics, topCount, "assignability checks", s => s.assignableCount);
678+
writeTop(overloadStatistics, topCount, "identity checks", s => s.identityCount);
682679

683-
// sys.write("Top " + topCount + " by nodes" + sys.newLine);
684-
// for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.nodeCount - a.nodeCount))) {
685-
// sys.write(JSON.stringify(stat) + sys.newLine);
686-
// }
687-
// sys.write(sys.newLine);
688-
689-
sys.write("Top " + topCount + " by subtype checks" + sys.newLine);
690-
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.subtypeCount - a.subtypeCount))) {
691-
sys.write(JSON.stringify(stat) + sys.newLine);
692-
}
680+
sys.write("Aggregated by function" + sys.newLine);
693681
sys.write(sys.newLine);
694682

695-
sys.write("Top " + topCount + " by assignability checks" + sys.newLine);
696-
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.assignableCount - a.assignableCount))) {
697-
sys.write(JSON.stringify(stat) + sys.newLine);
698-
}
699-
sys.write(sys.newLine);
700-
701-
sys.write("Top " + topCount + " by comparability checks" + sys.newLine);
702-
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.comparableCount - a.comparableCount))) {
703-
sys.write(JSON.stringify(stat) + sys.newLine);
704-
}
705-
sys.write(sys.newLine);
706-
707-
sys.write("Top " + topCount + " by identity checks" + sys.newLine);
708-
for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.identityCount - a.identityCount))) {
709-
sys.write(JSON.stringify(stat) + sys.newLine);
710-
}
711-
sys.write(sys.newLine);
712-
713-
// sys.write("Top " + topCount + " by enum checks" + sys.newLine);
714-
// for (const stat of takeAtMost(topCount, overloadStatistics.sort((a, b) => b.enumCount - a.enumCount))) {
715-
// sys.write(JSON.stringify(stat) + sys.newLine);
716-
// }
717-
// sys.write(sys.newLine);
683+
writeTop(groupedOverloadStatistics, topCount, "time", s => s.timeMs);
684+
writeTop(groupedOverloadStatistics, topCount, "symbols", s => s.symbolCount);
685+
writeTop(groupedOverloadStatistics, topCount, "subtype checks", s => s.subtypeCount);
686+
writeTop(groupedOverloadStatistics, topCount, "assignability checks", s => s.assignableCount);
687+
writeTop(groupedOverloadStatistics, topCount, "identity checks", s => s.identityCount);
718688
}
719689
else {
720690
// Individual component times.
@@ -734,6 +704,14 @@ namespace ts {
734704
performance.disable();
735705
}
736706

707+
function writeTop<T>(collection: T[], count: number, propName: string, propFn: (t: T) => number) {
708+
sys.write("Top " + count + " by " + propName + sys.newLine);
709+
for (const stat of takeAtMost(count, collection.sort((a, b) => propFn(b) - propFn(a)))) {
710+
sys.write(JSON.stringify(stat) + sys.newLine);
711+
}
712+
sys.write(sys.newLine);
713+
}
714+
737715
function takeAtMost<T>(count: number, array: readonly T[]): readonly T[] {
738716
return array.slice(0, Math.min(array.length, count));
739717
}

0 commit comments

Comments
 (0)