mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-30 11:24:49 -05:00
Make perfLogger potentially undefined rather than using a noop logger (#53229)
This commit is contained in:
@@ -1259,7 +1259,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
|
||||
*/
|
||||
updateGraph(): boolean {
|
||||
tracing?.push(tracing.Phase.Session, "updateGraph", { name: this.projectName, kind: ProjectKind[this.projectKind] });
|
||||
perfLogger.logStartUpdateGraph();
|
||||
perfLogger?.logStartUpdateGraph();
|
||||
this.resolutionCache.startRecordingFilesWithChangedResolutions();
|
||||
|
||||
const hasNewProgram = this.updateGraphWorker();
|
||||
@@ -1305,7 +1305,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
|
||||
// Preload auto import provider so it's not created during completions request
|
||||
this.getPackageJsonAutoImportProvider();
|
||||
}
|
||||
perfLogger.logStopUpdateGraph();
|
||||
perfLogger?.logStopUpdateGraph();
|
||||
tracing?.pop();
|
||||
return !hasNewProgram;
|
||||
}
|
||||
|
||||
@@ -1177,7 +1177,7 @@ export class Session<TMessage = string> implements EventSender {
|
||||
|
||||
protected writeMessage(msg: protocol.Message) {
|
||||
const msgText = formatMessage(msg, this.logger, this.byteLength, this.host.newLine);
|
||||
perfLogger.logEvent(`Response message size: ${msgText.length}`);
|
||||
perfLogger?.logEvent(`Response message size: ${msgText.length}`);
|
||||
this.host.write(msgText);
|
||||
}
|
||||
|
||||
@@ -3540,7 +3540,7 @@ export class Session<TMessage = string> implements EventSender {
|
||||
relevantFile = request.arguments && (request as protocol.FileRequest).arguments.file ? (request as protocol.FileRequest).arguments : undefined;
|
||||
|
||||
tracing?.instant(tracing.Phase.Session, "request", { seq: request.seq, command: request.command });
|
||||
perfLogger.logStartCommand("" + request.command, this.toStringMessage(message).substring(0, 100));
|
||||
perfLogger?.logStartCommand("" + request.command, this.toStringMessage(message).substring(0, 100));
|
||||
|
||||
tracing?.push(tracing.Phase.Session, "executeCommand", { seq: request.seq, command: request.command }, /*separateBeginAndEnd*/ true);
|
||||
const { response, responseRequired } = this.executeCommand(request);
|
||||
@@ -3557,7 +3557,7 @@ export class Session<TMessage = string> implements EventSender {
|
||||
}
|
||||
|
||||
// Note: Log before writing the response, else the editor can complete its activity before the server does
|
||||
perfLogger.logStopCommand("" + request.command, "Success");
|
||||
perfLogger?.logStopCommand("" + request.command, "Success");
|
||||
tracing?.instant(tracing.Phase.Session, "response", { seq: request.seq, command: request.command, success: !!response });
|
||||
if (response) {
|
||||
this.doOutput(response, request.command, request.seq, /*success*/ true);
|
||||
@@ -3572,14 +3572,14 @@ export class Session<TMessage = string> implements EventSender {
|
||||
|
||||
if (err instanceof OperationCanceledException) {
|
||||
// Handle cancellation exceptions
|
||||
perfLogger.logStopCommand("" + (request && request.command), "Canceled: " + err);
|
||||
perfLogger?.logStopCommand("" + (request && request.command), "Canceled: " + err);
|
||||
tracing?.instant(tracing.Phase.Session, "commandCanceled", { seq: request?.seq, command: request?.command });
|
||||
this.doOutput({ canceled: true }, request!.command, request!.seq, /*success*/ true);
|
||||
return;
|
||||
}
|
||||
|
||||
this.logErrorWorker(err, this.toStringMessage(message), relevantFile);
|
||||
perfLogger.logStopCommand("" + (request && request.command), "Error: " + err);
|
||||
perfLogger?.logStopCommand("" + (request && request.command), "Error: " + err);
|
||||
tracing?.instant(tracing.Phase.Session, "commandError", { seq: request?.seq, command: request?.command, message: (err as Error).message });
|
||||
|
||||
this.doOutput(
|
||||
|
||||
@@ -48,13 +48,13 @@ export class ThrottledOperations {
|
||||
}
|
||||
|
||||
private static run(self: ThrottledOperations, operationId: string, cb: () => void) {
|
||||
perfLogger.logStartScheduledOperation(operationId);
|
||||
perfLogger?.logStartScheduledOperation(operationId);
|
||||
self.pendingTimeouts.delete(operationId);
|
||||
if (self.logger) {
|
||||
self.logger.info(`Running: ${operationId}`);
|
||||
}
|
||||
cb();
|
||||
perfLogger.logStopScheduledOperation();
|
||||
perfLogger?.logStopScheduledOperation();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export class GcTimer {
|
||||
private static run(self: GcTimer) {
|
||||
self.timerId = undefined;
|
||||
|
||||
perfLogger.logStartScheduledOperation("GC collect");
|
||||
perfLogger?.logStartScheduledOperation("GC collect");
|
||||
const log = self.logger.hasLevel(LogLevel.requestTime);
|
||||
const before = log && self.host.getMemoryUsage!(); // TODO: GH#18217
|
||||
|
||||
@@ -84,7 +84,7 @@ export class GcTimer {
|
||||
const after = self.host.getMemoryUsage!(); // TODO: GH#18217
|
||||
self.logger.perftrc(`GC::before ${before}, after ${after}`);
|
||||
}
|
||||
perfLogger.logStopScheduledOperation();
|
||||
perfLogger?.logStopScheduledOperation();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user