Skip to content

Commit

Permalink
Options solutionDiagnostics instead so that its not too verbose when …
Browse files Browse the repository at this point in the history
…printing diagnostics
  • Loading branch information
sheetalkamat committed Jun 1, 2022
1 parent fe69264 commit 0cf9e30
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 25 deletions.
9 changes: 8 additions & 1 deletion src/compiler/commandLineParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1420,7 +1420,14 @@ namespace ts {
description: Diagnostics.Delete_the_outputs_of_all_projects,
type: "boolean",
defaultValueDescription: false,
}
},
{
name: "solutionDiagnostics",
type: "boolean",
category: Diagnostics.Compiler_Diagnostics,
description: Diagnostics.Output_more_detailed_solution_performance_information_after_building,
defaultValueDescription: false,
},
];

/* @internal */
Expand Down
6 changes: 5 additions & 1 deletion src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -5261,7 +5261,7 @@
"code": 6385,
"reportsDeprecated": true
},
"Performance timings for '--diagnostics' or '--extendedDiagnostics' are not available in this session. A native implementation of the Web Performance API could not be found.": {
"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.": {
"category": "Message",
"code": 6386
},
Expand Down Expand Up @@ -5807,6 +5807,10 @@
"category": "Message",
"code": 6718
},
"Output more detailed solution performance information after building.": {
"category": "Message",
"code": 6719
},
"Default catch clause variables as 'unknown' instead of 'any'.": {
"category": "Message",
"code": 6803
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ namespace ts {
sourceMap: compilerOptions.sourceMap,
inlineSourceMap: compilerOptions.inlineSourceMap,
inlineSources: compilerOptions.inlineSources,
extendedDiagnostics: compilerOptions.extendedDiagnostics,
extendedDiagnostics: compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics,
writeBundleFileInfo: !!bundleBuildInfo,
relativeToBuildInfo
};
Expand Down Expand Up @@ -454,7 +454,7 @@ namespace ts {
target: compilerOptions.target,
sourceMap: compilerOptions.sourceMap,
inlineSourceMap: compilerOptions.inlineSourceMap,
extendedDiagnostics: compilerOptions.extendedDiagnostics,
extendedDiagnostics: compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics,
onlyPrintJsDocStyle: true,
writeBundleFileInfo: !!bundleBuildInfo,
recordInternalSection: !!bundleBuildInfo,
Expand Down Expand Up @@ -483,7 +483,7 @@ namespace ts {
sourceMap: !forceDtsEmit && compilerOptions.declarationMap,
sourceRoot: compilerOptions.sourceRoot,
mapRoot: compilerOptions.mapRoot,
extendedDiagnostics: compilerOptions.extendedDiagnostics,
extendedDiagnostics: compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics,
// Explicitly do not passthru either `inline` option
}
);
Expand Down
12 changes: 12 additions & 0 deletions src/compiler/performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ namespace ts {
const marks = new Map<string, number>();
const counts = new Map<string, number>();
const durations = new Map<string, number>();
const durationMarks = new Set<string>();

return {
createTimerIf,
Expand All @@ -29,6 +30,7 @@ namespace ts {
getCount,
getDuration,
forEachMeasure,
forEachCount,
isEnabled,
enable,
disable,
Expand Down Expand Up @@ -87,6 +89,7 @@ namespace ts {
*/
function measure(measureName: string, startMarkName: string, endMarkName: string) {
if (enabled) {
durationMarks.add(startMarkName).add(endMarkName);
const end = marks.get(endMarkName) ?? timestamp();
const start = marks.get(startMarkName) ?? timeorigin;
const previousDuration = durations.get(measureName) || 0;
Expand Down Expand Up @@ -122,6 +125,15 @@ namespace ts {
durations.forEach((duration, measureName) => cb(measureName, duration));
}

/**
* Iterate over each count which is not duration mark, performing some action
*
* @param cb The action to perform for each measure
*/
function forEachCount(cb: (countName: string, count: number) => void) {
counts.forEach((count, countName) => !durationMarks.has(countName) && cb(countName, count));
}

/**
* Indicates whether the performance API is enabled.
*/
Expand Down
12 changes: 11 additions & 1 deletion src/compiler/tsbuildPublic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ namespace ts {
traceResolution?: boolean;
/* @internal */ diagnostics?: boolean;
/* @internal */ extendedDiagnostics?: boolean;
/* @internal */ solutionDiagnostics?: boolean;
/* @internal */ locale?: string;
/* @internal */ generateCpuProfile?: string;
/* @internal */ generateTrace?: string;
Expand Down Expand Up @@ -189,6 +190,7 @@ namespace ts {
commonOptionsWithBuild.forEach(option => {
if (hasProperty(buildOptions, option.name)) result[option.name] = buildOptions[option.name];
});
if (buildOptions.solutionDiagnostics) result.solutionDiagnostics = true;
return result;
}

Expand Down Expand Up @@ -2004,7 +2006,15 @@ namespace ts {
: ExitStatus.DiagnosticsPresent_OutputsSkipped;
}

function clean(state: SolutionBuilderState, project?: string, onlyReferences?: boolean) {
function clean(state: SolutionBuilderState, project?: string, onlyReferences?: boolean): ExitStatus {
solutionPerformance.mark("beforeClean");
const result = cleanWorker(state, project, onlyReferences);
solutionPerformance.mark("afterClean");
solutionPerformance.measure("Clean", "beforeClean", "afterClean");
return result;
}

function cleanWorker(state: SolutionBuilderState, project?: string, onlyReferences?: boolean) {
const buildOrder = getBuildOrderFor(state, project, onlyReferences);
if (!buildOrder) return ExitStatus.InvalidProject_OutputsSkipped;

Expand Down
1 change: 1 addition & 0 deletions src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6149,6 +6149,7 @@ namespace ts {
declarationDir?: string;
/* @internal */ diagnostics?: boolean;
/* @internal */ extendedDiagnostics?: boolean;
/* @internal */ solutionDiagnostics?: boolean;
disableSizeLimit?: boolean;
disableSourceOfProjectReferenceRedirect?: boolean;
disableSolutionSearching?: boolean;
Expand Down
1 change: 1 addition & 0 deletions src/compiler/watch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace ts {
if (system.clearScreen &&
!options.preserveWatchOutput &&
!options.extendedDiagnostics &&
!options.solutionDiagnostics &&
!options.diagnostics &&
contains(screenStartingMessageCodes, diagnostic.code)) {
system.clearScreen();
Expand Down
40 changes: 21 additions & 19 deletions src/executeCommandLine/executeCommandLine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -769,14 +769,14 @@ namespace ts {
if (!reportWatchStatistics) return;
if (d.code === Diagnostics.Found_0_errors_Watching_for_file_changes.code ||
d.code === Diagnostics.Found_1_error_Watching_for_file_changes.code) {
reportSolutionBuilderTimes(sys, builder, buildHost);
reportSolutionBuilderTimes(sys, buildOptions, builder, buildHost);
}
};
updateSolutionBuilderHost(sys, cb, buildHost);
enableSolutionPerformance(sys, buildOptions);
const builder = createSolutionBuilderWithWatch(buildHost, projects, buildOptions, watchOptions);
builder.build();
reportSolutionBuilderTimes(sys, builder, buildHost);
reportSolutionBuilderTimes(sys, buildOptions, builder, buildHost);
reportWatchStatistics = true;
return builder;
}
Expand All @@ -792,31 +792,33 @@ namespace ts {
enableSolutionPerformance(sys, buildOptions);
const builder = createSolutionBuilder(buildHost, projects, buildOptions);
const exitStatus = buildOptions.clean ? builder.clean() : builder.build();
reportSolutionBuilderTimes(sys, builder, buildHost);
reportSolutionBuilderTimes(sys, buildOptions, builder, buildHost);
dumpTracingLegend(); // Will no-op if there hasn't been any tracing
return sys.exit(exitStatus);
}

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

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


if (solutionPerformance.isEnabled()) {
const solutionStatistics: Statistic[] = [];
solutionPerformance.forEachMeasure((name, duration) => solutionStatistics.push({ name: `${name} time`, value: duration, type: StatisticType.time }));
solutionStatistics.push(
{ name: "projectsBuilt", value: solutionPerformance.getCount("projectsBuilt"), type: StatisticType.count },
{ name: "timestampUpdated", value: solutionPerformance.getCount("timestampUpdated"), type: StatisticType.count },
{ name: "bundlesUpdated", value: solutionPerformance.getCount("bundlesUpdated"), type: StatisticType.count },
{ name: "projects", value: getBuildOrderFromAnyBuildOrder(builder.getBuildOrder()).length, type: StatisticType.count },
{ name: "Projects", value: getBuildOrderFromAnyBuildOrder(builder.getBuildOrder()).length, type: StatisticType.count },
);
solutionPerformance.forEachCount((name, count) => solutionStatistics.push({ name, value: count, type: StatisticType.count }));
solutionPerformance.forEachMeasure((name, duration) => solutionStatistics.push({ name: `${name} time`, value: duration, type: StatisticType.time }));
buildHost.statistics = append(buildHost.statistics, solutionStatistics);
solutionPerformance.disable();
solutionPerformance.enable();
}
else {
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");
}

if (!buildHost.statistics) return;
const statistics: Statistic[] = [];
Expand Down Expand Up @@ -990,16 +992,16 @@ namespace ts {
return createWatchProgram(watchCompilerHost);
}

function canReportDiagnostics(system: System, compilerOptions: CompilerOptions) {
return system === sys && (compilerOptions.diagnostics || compilerOptions.extendedDiagnostics);
function canGenerateStatistics(system: System, compilerOptions: CompilerOptions) {
return system === sys && (compilerOptions.diagnostics || compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics);
}

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

function enableStatisticsAndTracing(system: System, compilerOptions: CompilerOptions, isBuildMode: boolean) {
if (canReportDiagnostics(system, compilerOptions)) {
if (canGenerateStatistics(system, compilerOptions)) {
performance.enable(system);
}

Expand All @@ -1022,15 +1024,15 @@ namespace ts {
}

let statistics: Statistic[];
if (canReportDiagnostics(sys, compilerOptions)) {
if (canGenerateStatistics(sys, compilerOptions)) {
statistics = [];
const memoryUsed = sys.getMemoryUsage ? sys.getMemoryUsage() : -1;
if (program) {
reportCountStatistic("Files", program.getSourceFiles().length);

const lineCounts = countLines(program);
const nodeCounts = countNodes(program);
if (compilerOptions.extendedDiagnostics) {
if (compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics) {
for (const key of arrayFrom(lineCounts.keys())) {
reportCountStatistic("Lines of " + key, lineCounts.get(key)!);
}
Expand Down Expand Up @@ -1058,7 +1060,7 @@ namespace ts {
const bindTime = isPerformanceEnabled ? performance.getDuration("Bind") : 0;
const checkTime = isPerformanceEnabled ? performance.getDuration("Check") : 0;
const emitTime = isPerformanceEnabled ? performance.getDuration("Emit") : 0;
if (compilerOptions.extendedDiagnostics) {
if (compilerOptions.extendedDiagnostics || compilerOptions.solutionDiagnostics) {
if (program) {
const caches = program.getRelationCacheSizes();
reportCountStatistic("Assignability cache size", caches.assignable);
Expand All @@ -1085,9 +1087,9 @@ namespace ts {
if (isPerformanceEnabled) {
reportTimeStatistic("Total time", programTime + bindTime + checkTime + emitTime);
}
reportAllStatistics(sys, statistics);
if (compilerOptions.diagnostics || compilerOptions.extendedDiagnostics) reportAllStatistics(sys, statistics);
if (!isPerformanceEnabled) {
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");
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");
}
else {
performance.disable();
Expand Down

0 comments on commit 0cf9e30

Please sign in to comment.