mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Re-do tracing initialization and tests around calls
Make `tracing` either `undefined` or the same namespace as before.
Switching all calls to `tracing?.___` means that there is no cost for
a call or the arguments when tracing is not used. Comparing two runs
without tracing (27 runs, drop 5+5, avg rest) I get:
master:
42.59s user 1.00s system 165% cpu 26.372 total
changed:
42.01s user 0.982 system 165% cpu 26.039 total
(Makes it all private, so no api changes.)
This commit is contained in:
@@ -208,25 +208,25 @@ namespace ts.server {
|
||||
try {
|
||||
if (this.operationHost.isCancellationRequested()) {
|
||||
stop = true;
|
||||
tracing.instant(tracing.Phase.Session, "stepCanceled", { seq: this.requestId, early: true });
|
||||
tracing?.instant(tracing.Phase.Session, "stepCanceled", { seq: this.requestId, early: true });
|
||||
}
|
||||
else {
|
||||
tracing.push(tracing.Phase.Session, "stepAction", { seq: this.requestId });
|
||||
tracing?.push(tracing.Phase.Session, "stepAction", { seq: this.requestId });
|
||||
action(this);
|
||||
tracing.pop();
|
||||
tracing?.pop();
|
||||
}
|
||||
}
|
||||
catch (e) {
|
||||
// Cancellation or an error may have left incomplete events on the tracing stack.
|
||||
tracing.popAll();
|
||||
tracing?.popAll();
|
||||
|
||||
stop = true;
|
||||
// ignore cancellation request
|
||||
if (e instanceof OperationCanceledException) {
|
||||
tracing.instant(tracing.Phase.Session, "stepCanceled", { seq: this.requestId });
|
||||
tracing?.instant(tracing.Phase.Session, "stepCanceled", { seq: this.requestId });
|
||||
}
|
||||
else {
|
||||
tracing.instant(tracing.Phase.Session, "stepError", { seq: this.requestId, message: (<Error>e).message });
|
||||
tracing?.instant(tracing.Phase.Session, "stepError", { seq: this.requestId, message: (<Error>e).message });
|
||||
this.operationHost.logError(e, `delayed processing of request ${this.requestId}`);
|
||||
}
|
||||
}
|
||||
@@ -947,7 +947,7 @@ namespace ts.server {
|
||||
}
|
||||
|
||||
public event<T extends object>(body: T, eventName: string): void {
|
||||
tracing.instant(tracing.Phase.Session, "event", { eventName });
|
||||
tracing?.instant(tracing.Phase.Session, "event", { eventName });
|
||||
this.send(toEvent(eventName, body));
|
||||
}
|
||||
|
||||
@@ -2962,12 +2962,12 @@ namespace ts.server {
|
||||
request = this.parseMessage(message);
|
||||
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 });
|
||||
tracing?.instant(tracing.Phase.Session, "request", { seq: request.seq, command: request.command });
|
||||
perfLogger.logStartCommand("" + request.command, this.toStringMessage(message).substring(0, 100));
|
||||
|
||||
tracing.push(tracing.Phase.Session, "executeCommand", { seq: request.seq, command: request.command }, /*separateBeginAndEnd*/ true);
|
||||
tracing?.push(tracing.Phase.Session, "executeCommand", { seq: request.seq, command: request.command }, /*separateBeginAndEnd*/ true);
|
||||
const { response, responseRequired } = this.executeCommand(request);
|
||||
tracing.pop();
|
||||
tracing?.pop();
|
||||
|
||||
if (this.logger.hasLevel(LogLevel.requestTime)) {
|
||||
const elapsedTime = hrTimeToMilliseconds(this.hrtime(start)).toFixed(4);
|
||||
@@ -2981,7 +2981,7 @@ namespace ts.server {
|
||||
|
||||
// Note: Log before writing the response, else the editor can complete its activity before the server does
|
||||
perfLogger.logStopCommand("" + request.command, "Success");
|
||||
tracing.instant(tracing.Phase.Session, "response", { seq: request.seq, command: request.command, success: !!response });
|
||||
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);
|
||||
}
|
||||
@@ -2991,19 +2991,19 @@ namespace ts.server {
|
||||
}
|
||||
catch (err) {
|
||||
// Cancellation or an error may have left incomplete events on the tracing stack.
|
||||
tracing.popAll();
|
||||
tracing?.popAll();
|
||||
|
||||
if (err instanceof OperationCanceledException) {
|
||||
// Handle cancellation exceptions
|
||||
perfLogger.logStopCommand("" + (request && request.command), "Canceled: " + err);
|
||||
tracing.instant(tracing.Phase.Session, "commandCanceled", { seq: request?.seq, command: request?.command });
|
||||
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);
|
||||
tracing.instant(tracing.Phase.Session, "commandError", { seq: request?.seq, command: request?.command, message: (<Error>err).message });
|
||||
tracing?.instant(tracing.Phase.Session, "commandError", { seq: request?.seq, command: request?.command, message: (<Error>err).message });
|
||||
|
||||
this.doOutput(
|
||||
/*info*/ undefined,
|
||||
|
||||
Reference in New Issue
Block a user