feat(language-service): add perf tracing to LanguageService (#41319)
Adds perf tracing for the public methods in LanguageService. If the log level is verbose or higher, trace performance results to the tsServer logger. This logger is implemented on the extension side in angular/vscode-ng-language-service. PR Close #41319
This commit is contained in:
committed by
Alex Rickabaugh
parent
a371646a37
commit
90f85da2de
@@ -110,6 +110,40 @@ export enum PerfPhase {
|
||||
*/
|
||||
LsReferencesAndRenames,
|
||||
|
||||
/**
|
||||
* Time spent by the Angular Language Service calculating a "quick info" operation.
|
||||
*/
|
||||
LsQuickInfo,
|
||||
|
||||
/**
|
||||
* Time spent by the Angular Language Service calculating a "get type definition" or "get
|
||||
* definition" operation.
|
||||
*/
|
||||
LsDefinition,
|
||||
|
||||
/**
|
||||
* Time spent by the Angular Language Service calculating a "get completions" (AKA autocomplete)
|
||||
* operation.
|
||||
*/
|
||||
LsCompletions,
|
||||
|
||||
/**
|
||||
* Time spent by the Angular Language Service calculating a "view template typecheck block"
|
||||
* operation.
|
||||
*/
|
||||
LsTcb,
|
||||
|
||||
/**
|
||||
* Time spent by the Angular Language Service calculating diagnostics.
|
||||
*/
|
||||
LsDiagnostics,
|
||||
|
||||
/**
|
||||
* Time spent by the Angular Language Service calculating a "get component locations for template"
|
||||
* operation.
|
||||
*/
|
||||
LsComponentLocations,
|
||||
|
||||
/**
|
||||
* Tracks the number of `PerfPhase`s, and must appear at the end of the list.
|
||||
*/
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -275,6 +275,28 @@ describe('getSemanticDiagnostics', () => {
|
||||
expect(diag.category).toBe(ts.DiagnosticCategory.Suggestion);
|
||||
expect(getTextOfDiagnostic(diag)).toBe('user');
|
||||
});
|
||||
|
||||
it('logs perf tracing', () => {
|
||||
const files = {
|
||||
'app.ts': `
|
||||
import {Component} from '@angular/core';
|
||||
@Component({ template: '' })
|
||||
export class MyComponent {}
|
||||
`
|
||||
};
|
||||
|
||||
const project = createModuleAndProjectWithDeclarations(env, 'test', files);
|
||||
|
||||
const logger = project.getLogger();
|
||||
spyOn(logger, 'hasLevel').and.returnValue(true);
|
||||
spyOn(logger, 'perftrc').and.callFake(() => {});
|
||||
|
||||
const diags = project.getDiagnosticsForFile('app.ts');
|
||||
expect(diags.length).toEqual(0);
|
||||
expect(logger.perftrc)
|
||||
.toHaveBeenCalledWith(jasmine.stringMatching(
|
||||
/LanguageService\#LsDiagnostics\:.*\"LsDiagnostics\":\s*\d+.*/g));
|
||||
});
|
||||
});
|
||||
|
||||
function getTextOfDiagnostic(diag: ts.Diagnostic): string {
|
||||
|
||||
@@ -179,6 +179,10 @@ export class Project {
|
||||
getTemplateTypeChecker(): TemplateTypeChecker {
|
||||
return this.ngLS.compilerFactory.getOrCreate().getTemplateTypeChecker();
|
||||
}
|
||||
|
||||
getLogger(): ts.server.Logger {
|
||||
return this.tsProject.projectService.logger;
|
||||
}
|
||||
}
|
||||
|
||||
function getClassOrError(sf: ts.SourceFile, name: string): ts.ClassDeclaration {
|
||||
|
||||
Reference in New Issue
Block a user