Skip to content

Commit 0cf9e30

Browse files
committed
Options solutionDiagnostics instead so that its not too verbose when printing diagnostics
1 parent fe69264 commit 0cf9e30

File tree

8 files changed

+62
-25
lines changed

8 files changed

+62
-25
lines changed

src/compiler/commandLineParser.ts

+8-1
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,14 @@ namespace ts {
14201420
description: Diagnostics.Delete_the_outputs_of_all_projects,
14211421
type: "boolean",
14221422
defaultValueDescription: false,
1423-
}
1423+
},
1424+
{
1425+
name: "solutionDiagnostics",
1426+
type: "boolean",
1427+
category: Diagnostics.Compiler_Diagnostics,
1428+
description: Diagnostics.Output_more_detailed_solution_performance_information_after_building,
1429+
defaultValueDescription: false,
1430+
},
14241431
];
14251432

14261433
/* @internal */

src/compiler/diagnosticMessages.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -5261,7 +5261,7 @@
52615261
"code": 6385,
52625262
"reportsDeprecated": true
52635263
},
5264-
"Performance timings for '--diagnostics' or '--extendedDiagnostics' are not available in this session. A native implementation of the Web Performance API could not be found.": {
5264+
"Performance timings for '--diagnostics' or '--extendedDiagnostics' or '--solutionDiagnostics' are not available in this session. A native implementation of the Web Performance API could not be found.": {
52655265
"category": "Message",
52665266
"code": 6386
52675267
},
@@ -5807,6 +5807,10 @@
58075807
"category": "Message",
58085808
"code": 6718
58095809
},
5810+
"Output more detailed solution performance information after building.": {
5811+
"category": "Message",
5812+
"code": 6719
5813+
},
58105814
"Default catch clause variables as 'unknown' instead of 'any'.": {
58115815
"category": "Message",
58125816
"code": 6803

src/compiler/emitter.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ namespace ts {
396396
sourceMap: compilerOptions.sourceMap,
397397
inlineSourceMap: compilerOptions.inlineSourceMap,
398398
inlineSources: compilerOptions.inlineSources,
399-
extendedDiagnostics: compilerOptions.extendedDiagnostics,
399+
extendedDiagnostics: compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics,
400400
writeBundleFileInfo: !!bundleBuildInfo,
401401
relativeToBuildInfo
402402
};
@@ -454,7 +454,7 @@ namespace ts {
454454
target: compilerOptions.target,
455455
sourceMap: compilerOptions.sourceMap,
456456
inlineSourceMap: compilerOptions.inlineSourceMap,
457-
extendedDiagnostics: compilerOptions.extendedDiagnostics,
457+
extendedDiagnostics: compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics,
458458
onlyPrintJsDocStyle: true,
459459
writeBundleFileInfo: !!bundleBuildInfo,
460460
recordInternalSection: !!bundleBuildInfo,
@@ -483,7 +483,7 @@ namespace ts {
483483
sourceMap: !forceDtsEmit && compilerOptions.declarationMap,
484484
sourceRoot: compilerOptions.sourceRoot,
485485
mapRoot: compilerOptions.mapRoot,
486-
extendedDiagnostics: compilerOptions.extendedDiagnostics,
486+
extendedDiagnostics: compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics,
487487
// Explicitly do not passthru either `inline` option
488488
}
489489
);

src/compiler/performance.ts

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ namespace ts {
2020
const marks = new Map<string, number>();
2121
const counts = new Map<string, number>();
2222
const durations = new Map<string, number>();
23+
const durationMarks = new Set<string>();
2324

2425
return {
2526
createTimerIf,
@@ -29,6 +30,7 @@ namespace ts {
2930
getCount,
3031
getDuration,
3132
forEachMeasure,
33+
forEachCount,
3234
isEnabled,
3335
enable,
3436
disable,
@@ -87,6 +89,7 @@ namespace ts {
8789
*/
8890
function measure(measureName: string, startMarkName: string, endMarkName: string) {
8991
if (enabled) {
92+
durationMarks.add(startMarkName).add(endMarkName);
9093
const end = marks.get(endMarkName) ?? timestamp();
9194
const start = marks.get(startMarkName) ?? timeorigin;
9295
const previousDuration = durations.get(measureName) || 0;
@@ -122,6 +125,15 @@ namespace ts {
122125
durations.forEach((duration, measureName) => cb(measureName, duration));
123126
}
124127

128+
/**
129+
* Iterate over each count which is not duration mark, performing some action
130+
*
131+
* @param cb The action to perform for each measure
132+
*/
133+
function forEachCount(cb: (countName: string, count: number) => void) {
134+
counts.forEach((count, countName) => !durationMarks.has(countName) && cb(countName, count));
135+
}
136+
125137
/**
126138
* Indicates whether the performance API is enabled.
127139
*/

src/compiler/tsbuildPublic.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ namespace ts {
2222
traceResolution?: boolean;
2323
/* @internal */ diagnostics?: boolean;
2424
/* @internal */ extendedDiagnostics?: boolean;
25+
/* @internal */ solutionDiagnostics?: boolean;
2526
/* @internal */ locale?: string;
2627
/* @internal */ generateCpuProfile?: string;
2728
/* @internal */ generateTrace?: string;
@@ -189,6 +190,7 @@ namespace ts {
189190
commonOptionsWithBuild.forEach(option => {
190191
if (hasProperty(buildOptions, option.name)) result[option.name] = buildOptions[option.name];
191192
});
193+
if (buildOptions.solutionDiagnostics) result.solutionDiagnostics = true;
192194
return result;
193195
}
194196

@@ -2004,7 +2006,15 @@ namespace ts {
20042006
: ExitStatus.DiagnosticsPresent_OutputsSkipped;
20052007
}
20062008

2007-
function clean(state: SolutionBuilderState, project?: string, onlyReferences?: boolean) {
2009+
function clean(state: SolutionBuilderState, project?: string, onlyReferences?: boolean): ExitStatus {
2010+
solutionPerformance.mark("beforeClean");
2011+
const result = cleanWorker(state, project, onlyReferences);
2012+
solutionPerformance.mark("afterClean");
2013+
solutionPerformance.measure("Clean", "beforeClean", "afterClean");
2014+
return result;
2015+
}
2016+
2017+
function cleanWorker(state: SolutionBuilderState, project?: string, onlyReferences?: boolean) {
20082018
const buildOrder = getBuildOrderFor(state, project, onlyReferences);
20092019
if (!buildOrder) return ExitStatus.InvalidProject_OutputsSkipped;
20102020

src/compiler/types.ts

+1
Original file line numberDiff line numberDiff line change
@@ -6149,6 +6149,7 @@ namespace ts {
61496149
declarationDir?: string;
61506150
/* @internal */ diagnostics?: boolean;
61516151
/* @internal */ extendedDiagnostics?: boolean;
6152+
/* @internal */ solutionDiagnostics?: boolean;
61526153
disableSizeLimit?: boolean;
61536154
disableSourceOfProjectReferenceRedirect?: boolean;
61546155
disableSolutionSearching?: boolean;

src/compiler/watch.ts

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ namespace ts {
3434
if (system.clearScreen &&
3535
!options.preserveWatchOutput &&
3636
!options.extendedDiagnostics &&
37+
!options.solutionDiagnostics &&
3738
!options.diagnostics &&
3839
contains(screenStartingMessageCodes, diagnostic.code)) {
3940
system.clearScreen();

src/executeCommandLine/executeCommandLine.ts

+21-19
Original file line numberDiff line numberDiff line change
@@ -769,14 +769,14 @@ namespace ts {
769769
if (!reportWatchStatistics) return;
770770
if (d.code === Diagnostics.Found_0_errors_Watching_for_file_changes.code ||
771771
d.code === Diagnostics.Found_1_error_Watching_for_file_changes.code) {
772-
reportSolutionBuilderTimes(sys, builder, buildHost);
772+
reportSolutionBuilderTimes(sys, buildOptions, builder, buildHost);
773773
}
774774
};
775775
updateSolutionBuilderHost(sys, cb, buildHost);
776776
enableSolutionPerformance(sys, buildOptions);
777777
const builder = createSolutionBuilderWithWatch(buildHost, projects, buildOptions, watchOptions);
778778
builder.build();
779-
reportSolutionBuilderTimes(sys, builder, buildHost);
779+
reportSolutionBuilderTimes(sys, buildOptions, builder, buildHost);
780780
reportWatchStatistics = true;
781781
return builder;
782782
}
@@ -792,31 +792,33 @@ namespace ts {
792792
enableSolutionPerformance(sys, buildOptions);
793793
const builder = createSolutionBuilder(buildHost, projects, buildOptions);
794794
const exitStatus = buildOptions.clean ? builder.clean() : builder.build();
795-
reportSolutionBuilderTimes(sys, builder, buildHost);
795+
reportSolutionBuilderTimes(sys, buildOptions, builder, buildHost);
796796
dumpTracingLegend(); // Will no-op if there hasn't been any tracing
797797
return sys.exit(exitStatus);
798798
}
799799

800800
function enableSolutionPerformance(system: System, options: BuildOptions) {
801-
if (system === sys && (options.diagnostics || options.extendedDiagnostics)) solutionPerformance.enable();
801+
if (system === sys && options.solutionDiagnostics) solutionPerformance.enable();
802802
}
803803

804-
function reportSolutionBuilderTimes(system: System, builder: SolutionBuilder<BuilderProgram>, buildHost: SolutionBuilderHost<BuilderProgram>) {
805-
if (system !== sys) return;
804+
function reportSolutionBuilderTimes(system: System, buildOptions: BuildOptions, builder: SolutionBuilder<BuilderProgram>, buildHost: SolutionBuilderHost<BuilderProgram>) {
805+
if (system !== sys || !buildOptions.solutionDiagnostics) return;
806+
806807

807808
if (solutionPerformance.isEnabled()) {
808809
const solutionStatistics: Statistic[] = [];
809-
solutionPerformance.forEachMeasure((name, duration) => solutionStatistics.push({ name: `${name} time`, value: duration, type: StatisticType.time }));
810810
solutionStatistics.push(
811-
{ name: "projectsBuilt", value: solutionPerformance.getCount("projectsBuilt"), type: StatisticType.count },
812-
{ name: "timestampUpdated", value: solutionPerformance.getCount("timestampUpdated"), type: StatisticType.count },
813-
{ name: "bundlesUpdated", value: solutionPerformance.getCount("bundlesUpdated"), type: StatisticType.count },
814-
{ name: "projects", value: getBuildOrderFromAnyBuildOrder(builder.getBuildOrder()).length, type: StatisticType.count },
811+
{ name: "Projects", value: getBuildOrderFromAnyBuildOrder(builder.getBuildOrder()).length, type: StatisticType.count },
815812
);
813+
solutionPerformance.forEachCount((name, count) => solutionStatistics.push({ name, value: count, type: StatisticType.count }));
814+
solutionPerformance.forEachMeasure((name, duration) => solutionStatistics.push({ name: `${name} time`, value: duration, type: StatisticType.time }));
816815
buildHost.statistics = append(buildHost.statistics, solutionStatistics);
817816
solutionPerformance.disable();
818817
solutionPerformance.enable();
819818
}
819+
else {
820+
sys.write(Diagnostics.Performance_timings_for_diagnostics_or_extendedDiagnostics_or_solutionDiagnostics_are_not_available_in_this_session_A_native_implementation_of_the_Web_Performance_API_could_not_be_found.message + "\n");
821+
}
820822

821823
if (!buildHost.statistics) return;
822824
const statistics: Statistic[] = [];
@@ -990,16 +992,16 @@ namespace ts {
990992
return createWatchProgram(watchCompilerHost);
991993
}
992994

993-
function canReportDiagnostics(system: System, compilerOptions: CompilerOptions) {
994-
return system === sys && (compilerOptions.diagnostics || compilerOptions.extendedDiagnostics);
995+
function canGenerateStatistics(system: System, compilerOptions: CompilerOptions) {
996+
return system === sys && (compilerOptions.diagnostics || compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics);
995997
}
996998

997999
function canTrace(system: System, compilerOptions: CompilerOptions) {
9981000
return system === sys && compilerOptions.generateTrace;
9991001
}
10001002

10011003
function enableStatisticsAndTracing(system: System, compilerOptions: CompilerOptions, isBuildMode: boolean) {
1002-
if (canReportDiagnostics(system, compilerOptions)) {
1004+
if (canGenerateStatistics(system, compilerOptions)) {
10031005
performance.enable(system);
10041006
}
10051007

@@ -1022,15 +1024,15 @@ namespace ts {
10221024
}
10231025

10241026
let statistics: Statistic[];
1025-
if (canReportDiagnostics(sys, compilerOptions)) {
1027+
if (canGenerateStatistics(sys, compilerOptions)) {
10261028
statistics = [];
10271029
const memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1;
10281030
if (program) {
10291031
reportCountStatistic("Files", program.getSourceFiles().length);
10301032

10311033
const lineCounts = countLines(program);
10321034
const nodeCounts = countNodes(program);
1033-
if (compilerOptions.extendedDiagnostics) {
1035+
if (compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics) {
10341036
for (const key of arrayFrom(lineCounts.keys())) {
10351037
reportCountStatistic("Lines of " + key, lineCounts.get(key)!);
10361038
}
@@ -1058,7 +1060,7 @@ namespace ts {
10581060
const bindTime = isPerformanceEnabled ? performance.getDuration("Bind") : 0;
10591061
const checkTime = isPerformanceEnabled ? performance.getDuration("Check") : 0;
10601062
const emitTime = isPerformanceEnabled ? performance.getDuration("Emit") : 0;
1061-
if (compilerOptions.extendedDiagnostics) {
1063+
if (compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics) {
10621064
if (program) {
10631065
const caches = program.getRelationCacheSizes();
10641066
reportCountStatistic("Assignability cache size", caches.assignable);
@@ -1085,9 +1087,9 @@ namespace ts {
10851087
if (isPerformanceEnabled) {
10861088
reportTimeStatistic("Total time", programTime + bindTime + checkTime + emitTime);
10871089
}
1088-
reportAllStatistics(sys, statistics);
1090+
if (compilerOptions.diagnostics || compilerOptions.extendedDiagnostics) reportAllStatistics(sys, statistics);
10891091
if (!isPerformanceEnabled) {
1090-
sys.write(Diagnostics.Performance_timings_for_diagnostics_or_extendedDiagnostics_are_not_available_in_this_session_A_native_implementation_of_the_Web_Performance_API_could_not_be_found.message + "\n");
1092+
sys.write(Diagnostics.Performance_timings_for_diagnostics_or_extendedDiagnostics_or_solutionDiagnostics_are_not_available_in_this_session_A_native_implementation_of_the_Web_Performance_API_could_not_be_found.message + "\n");
10911093
}
10921094
else {
10931095
performance.disable();

0 commit comments

Comments
 (0)