Skip to content

Commit 073ac92

Browse files
authored
Add server tracepoints (microsoft#48282)
* Trace project creation, loading, and updateGraph * Drop generic event tracing * Make argument names more consistent * Trace diagnostics to make steps easier to interpret * Fill an unexplained gap in updateGraph * Move updateGraph tracing into base type * Fill the gaps in updateGraph
1 parent c1cf901 commit 073ac92

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

Diff for: src/compiler/commandLineParser.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -2591,7 +2591,10 @@ namespace ts {
25912591
* file to. e.g. outDir
25922592
*/
25932593
export function parseJsonSourceFileConfigFileContent(sourceFile: TsConfigSourceFile, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: readonly FileExtensionInfo[], extendedConfigCache?: Map<ExtendedConfigCacheEntry>, existingWatchOptions?: WatchOptions): ParsedCommandLine {
2594-
return parseJsonConfigFileContentWorker(/*json*/ undefined, sourceFile, host, basePath, existingOptions, existingWatchOptions, configFileName, resolutionStack, extraFileExtensions, extendedConfigCache);
2594+
tracing?.push(tracing.Phase.Parse, "parseJsonSourceFileConfigFileContent", { path: sourceFile.fileName });
2595+
const result = parseJsonConfigFileContentWorker(/*json*/ undefined, sourceFile, host, basePath, existingOptions, existingWatchOptions, configFileName, resolutionStack, extraFileExtensions, extendedConfigCache);
2596+
tracing?.pop();
2597+
return result;
25952598
}
25962599

25972600
/*@internal*/

Diff for: src/server/editorServices.ts

+3
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,7 @@ namespace ts.server {
20622062

20632063
/* @internal */
20642064
createConfiguredProject(configFileName: NormalizedPath) {
2065+
tracing?.instant(tracing.Phase.Session, "createConfiguredProject", { configFilePath: configFileName });
20652066
this.logger.info(`Creating configuration project ${configFileName}`);
20662067
const canonicalConfigFilePath = asNormalizedPath(this.toCanonicalFileName(configFileName));
20672068
let configFileExistenceInfo = this.configFileExistenceInfoCache.get(canonicalConfigFilePath);
@@ -2119,6 +2120,7 @@ namespace ts.server {
21192120
*/
21202121
/* @internal */
21212122
private loadConfiguredProject(project: ConfiguredProject, reason: string) {
2123+
tracing?.push(tracing.Phase.Session, "loadConfiguredProject", { configFilePath: project.canonicalConfigFilePath });
21222124
this.sendProjectLoadingStartEvent(project, reason);
21232125

21242126
// Read updated contents from disk
@@ -2160,6 +2162,7 @@ namespace ts.server {
21602162
project.enablePluginsWithOptions(compilerOptions, this.currentPluginConfigOverrides);
21612163
const filesToAdd = parsedCommandLine.fileNames.concat(project.getExternalFiles());
21622164
this.updateRootAndOptionsOfNonInferredProject(project, filesToAdd, fileNamePropertyReader, compilerOptions, parsedCommandLine.typeAcquisition!, parsedCommandLine.compileOnSave, parsedCommandLine.watchOptions);
2165+
tracing?.pop();
21632166
}
21642167

21652168
/*@internal*/

Diff for: src/server/project.ts

+12-1
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,7 @@ namespace ts.server {
10451045
* @returns: true if set of files in the project stays the same and false - otherwise.
10461046
*/
10471047
updateGraph(): boolean {
1048+
tracing?.push(tracing.Phase.Session, "updateGraph", { name: this.projectName, kind: ProjectKind[this.projectKind] });
10481049
perfLogger.logStartUpdateGraph();
10491050
this.resolutionCache.startRecordingFilesWithChangedResolutions();
10501051

@@ -1092,6 +1093,7 @@ namespace ts.server {
10921093
this.getPackageJsonAutoImportProvider();
10931094
}
10941095
perfLogger.logStopUpdateGraph();
1096+
tracing?.pop();
10951097
return !hasNewProgram;
10961098
}
10971099

@@ -1128,7 +1130,9 @@ namespace ts.server {
11281130
this.resolutionCache.startCachingPerDirectoryResolution();
11291131
this.program = this.languageService.getProgram(); // TODO: GH#18217
11301132
this.dirty = false;
1133+
tracing?.push(tracing.Phase.Session, "finishCachingPerDirectoryResolution");
11311134
this.resolutionCache.finishCachingPerDirectoryResolution();
1135+
tracing?.pop();
11321136

11331137
Debug.assert(oldProgram === undefined || this.program !== undefined);
11341138

@@ -1747,13 +1751,16 @@ namespace ts.server {
17471751

17481752
const dependencySelection = this.includePackageJsonAutoImports();
17491753
if (dependencySelection) {
1754+
tracing?.push(tracing.Phase.Session, "getPackageJsonAutoImportProvider");
17501755
const start = timestamp();
17511756
this.autoImportProviderHost = AutoImportProviderProject.create(dependencySelection, this, this.getModuleResolutionHostForAutoImportProvider(), this.documentRegistry);
17521757
if (this.autoImportProviderHost) {
17531758
updateProjectIfDirty(this.autoImportProviderHost);
17541759
this.sendPerformanceEvent("CreatePackageJsonAutoImportProvider", timestamp() - start);
1760+
tracing?.pop();
17551761
return this.autoImportProviderHost.getCurrentProgram();
17561762
}
1763+
tracing?.pop();
17571764
}
17581765
}
17591766

@@ -1776,9 +1783,13 @@ namespace ts.server {
17761783
}
17771784

17781785
function getUnresolvedImports(program: Program, cachedUnresolvedImportsPerFile: ESMap<Path, readonly string[]>): SortedReadonlyArray<string> {
1786+
const sourceFiles = program.getSourceFiles();
1787+
tracing?.push(tracing.Phase.Session, "getUnresolvedImports", { count: sourceFiles.length });
17791788
const ambientModules = program.getTypeChecker().getAmbientModules().map(mod => stripQuotes(mod.getName()));
1780-
return sortAndDeduplicate(flatMap(program.getSourceFiles(), sourceFile =>
1789+
const result = sortAndDeduplicate(flatMap(sourceFiles, sourceFile =>
17811790
extractUnresolvedImportsFromSourceFile(sourceFile, ambientModules, cachedUnresolvedImportsPerFile)));
1791+
tracing?.pop();
1792+
return result;
17821793
}
17831794
function extractUnresolvedImportsFromSourceFile(file: SourceFile, ambientModules: readonly string[], cachedUnresolvedImportsPerFile: ESMap<Path, readonly string[]>): readonly string[] {
17841795
return getOrUpdate(cachedUnresolvedImportsPerFile, file.path, () => {

Diff for: src/server/session.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,6 @@ namespace ts.server {
903903
}
904904

905905
public event<T extends object>(body: T, eventName: string): void {
906-
tracing?.instant(tracing.Phase.Session, "event", { eventName });
907906
this.send(toEvent(eventName, body));
908907
}
909908

@@ -955,18 +954,24 @@ namespace ts.server {
955954
}
956955

957956
private semanticCheck(file: NormalizedPath, project: Project) {
957+
tracing?.push(tracing.Phase.Session, "semanticCheck", { file, configFilePath: (project as ConfiguredProject).canonicalConfigFilePath }); // undefined is fine if the cast fails
958958
const diags = isDeclarationFileInJSOnlyNonConfiguredProject(project, file)
959959
? emptyArray
960960
: project.getLanguageService().getSemanticDiagnostics(file).filter(d => !!d.file);
961961
this.sendDiagnosticsEvent(file, project, diags, "semanticDiag");
962+
tracing?.pop();
962963
}
963964

964965
private syntacticCheck(file: NormalizedPath, project: Project) {
966+
tracing?.push(tracing.Phase.Session, "syntacticCheck", { file, configFilePath: (project as ConfiguredProject).canonicalConfigFilePath }); // undefined is fine if the cast fails
965967
this.sendDiagnosticsEvent(file, project, project.getLanguageService().getSyntacticDiagnostics(file), "syntaxDiag");
968+
tracing?.pop();
966969
}
967970

968971
private suggestionCheck(file: NormalizedPath, project: Project) {
972+
tracing?.push(tracing.Phase.Session, "suggestionCheck", { file, configFilePath: (project as ConfiguredProject).canonicalConfigFilePath }); // undefined is fine if the cast fails
969973
this.sendDiagnosticsEvent(file, project, project.getLanguageService().getSuggestionDiagnostics(file), "suggestionDiag");
974+
tracing?.pop();
970975
}
971976

972977
private sendDiagnosticsEvent(file: NormalizedPath, project: Project, diagnostics: readonly Diagnostic[], kind: protocol.DiagnosticEventKind): void {

Diff for: src/services/services.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1004,9 +1004,11 @@ namespace ts {
10041004

10051005
// Initialize the list with the root file names
10061006
const rootFileNames = host.getScriptFileNames();
1007+
tracing?.push(tracing.Phase.Session, "initializeHostCache", { count: rootFileNames.length });
10071008
for (const fileName of rootFileNames) {
10081009
this.createEntry(fileName, toPath(fileName, this.currentDirectory, getCanonicalFileName));
10091010
}
1011+
tracing?.pop();
10101012
}
10111013

10121014
private createEntry(fileName: string, path: Path) {

0 commit comments

Comments
 (0)