Skip to content

Commit 85ef91e

Browse files
authored
Merge pull request #41180 from amcasey/ProgramTracing
Add tracepoints within createProgram
2 parents e5ca776 + dcb18d6 commit 85ef91e

File tree

1 file changed

+34
-1
lines changed

1 file changed

+34
-1
lines changed

src/compiler/program.ts

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,11 +867,15 @@ namespace ts {
867867
forEachResolvedProjectReference
868868
});
869869

870+
tracing.push(tracing.Phase.Program, "shouldProgramCreateNewSourceFiles", { hasOldProgram: !!oldProgram });
870871
const shouldCreateNewSourceFile = shouldProgramCreateNewSourceFiles(oldProgram, options);
872+
tracing.pop();
871873
// We set `structuralIsReused` to `undefined` because `tryReuseStructureFromOldProgram` calls `tryReuseStructureFromOldProgram` which checks
872874
// `structuralIsReused`, which would be a TDZ violation if it was not set in advance to `undefined`.
873875
let structureIsReused: StructureIsReused;
876+
tracing.push(tracing.Phase.Program, "tryReuseStructureFromOldProgram", {});
874877
structureIsReused = tryReuseStructureFromOldProgram(); // eslint-disable-line prefer-const
878+
tracing.pop();
875879
if (structureIsReused !== StructureIsReused.Completely) {
876880
processingDefaultLibFiles = [];
877881
processingOtherFiles = [];
@@ -907,19 +911,23 @@ namespace ts {
907911
}
908912
}
909913

914+
tracing.push(tracing.Phase.Program, "processRootFiles", { count: rootNames.length });
910915
forEach(rootNames, name => processRootFile(name, /*isDefaultLib*/ false, /*ignoreNoDefaultLib*/ false));
916+
tracing.pop();
911917

912918
// load type declarations specified via 'types' argument or implicitly from types/ and node_modules/@types folders
913919
const typeReferences: string[] = rootNames.length ? getAutomaticTypeDirectiveNames(options, host) : emptyArray;
914920

915921
if (typeReferences.length) {
922+
tracing.push(tracing.Phase.Program, "processTypeReferences", { count: typeReferences.length });
916923
// This containingFilename needs to match with the one used in managed-side
917924
const containingDirectory = options.configFilePath ? getDirectoryPath(options.configFilePath) : host.getCurrentDirectory();
918925
const containingFilename = combinePaths(containingDirectory, inferredTypesContainingFile);
919926
const resolutions = resolveTypeReferenceDirectiveNamesWorker(typeReferences, containingFilename);
920927
for (let i = 0; i < typeReferences.length; i++) {
921928
processTypeReferenceDirective(typeReferences[i], resolutions[i]);
922929
}
930+
tracing.pop();
923931
}
924932

925933
// Do not process the default library if:
@@ -1041,21 +1049,25 @@ namespace ts {
10411049
if (!moduleNames.length) return emptyArray;
10421050
const containingFileName = getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory);
10431051
const redirectedReference = getRedirectReferenceForResolution(containingFile);
1052+
tracing.push(tracing.Phase.Program, "resolveModuleNamesWorker", { containingFileName });
10441053
performance.mark("beforeResolveModule");
10451054
const result = actualResolveModuleNamesWorker(moduleNames, containingFileName, reusedNames, redirectedReference);
10461055
performance.mark("afterResolveModule");
10471056
performance.measure("ResolveModule", "beforeResolveModule", "afterResolveModule");
1057+
tracing.pop();
10481058
return result;
10491059
}
10501060

10511061
function resolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames: string[], containingFile: string | SourceFile): readonly (ResolvedTypeReferenceDirective | undefined)[] {
10521062
if (!typeDirectiveNames.length) return [];
1053-
performance.mark("beforeResolveTypeReference");
10541063
const containingFileName = !isString(containingFile) ? getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory) : containingFile;
10551064
const redirectedReference = !isString(containingFile) ? getRedirectReferenceForResolution(containingFile) : undefined;
1065+
tracing.push(tracing.Phase.Program, "resolveTypeReferenceDirectiveNamesWorker", { containingFileName });
1066+
performance.mark("beforeResolveTypeReference");
10561067
const result = actualResolveTypeReferenceDirectiveNamesWorker(typeDirectiveNames, containingFileName, redirectedReference);
10571068
performance.mark("afterResolveTypeReference");
10581069
performance.measure("ResolveTypeReference", "beforeResolveTypeReference", "afterResolveTypeReference");
1070+
tracing.pop();
10591071
return result;
10601072
}
10611073

@@ -2426,6 +2438,17 @@ namespace ts {
24262438

24272439
// Get source file from normalized fileName
24282440
function findSourceFile(fileName: string, path: Path, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, refFile: RefFile | undefined, packageId: PackageId | undefined): SourceFile | undefined {
2441+
tracing.push(tracing.Phase.Program, "findSourceFile", {
2442+
fileName,
2443+
isDefaultLib: isDefaultLib || undefined,
2444+
refKind: refFile ? (RefFileKind as any)[refFile.kind] : undefined,
2445+
});
2446+
const result = findSourceFileWorker(fileName, path, isDefaultLib, ignoreNoDefaultLib, refFile, packageId);
2447+
tracing.pop();
2448+
return result;
2449+
}
2450+
2451+
function findSourceFileWorker(fileName: string, path: Path, isDefaultLib: boolean, ignoreNoDefaultLib: boolean, refFile: RefFile | undefined, packageId: PackageId | undefined): SourceFile | undefined {
24292452
if (useSourceOfProjectReferenceRedirect) {
24302453
let source = getSourceOfProjectReferenceRedirect(fileName);
24312454
// If preserveSymlinks is true, module resolution wont jump the symlink
@@ -2750,6 +2773,16 @@ namespace ts {
27502773
resolvedTypeReferenceDirective?: ResolvedTypeReferenceDirective,
27512774
refFile?: RefFile
27522775
): void {
2776+
tracing.push(tracing.Phase.Program, "processTypeReferenceDirective", { directive: typeReferenceDirective, hasResolved: !!resolveModuleNamesReusingOldState, refKind: refFile?.kind, refPath: refFile?.file.path });
2777+
processTypeReferenceDirectiveWorker(typeReferenceDirective, resolvedTypeReferenceDirective, refFile);
2778+
tracing.pop();
2779+
}
2780+
2781+
function processTypeReferenceDirectiveWorker(
2782+
typeReferenceDirective: string,
2783+
resolvedTypeReferenceDirective?: ResolvedTypeReferenceDirective,
2784+
refFile?: RefFile
2785+
): void {
27532786

27542787
// If we already found this library as a primary reference - nothing to do
27552788
const previousResolution = resolvedTypeReferenceDirectives.get(typeReferenceDirective);

0 commit comments

Comments
 (0)