-
Notifications
You must be signed in to change notification settings - Fork 12.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trace key operations #40063
Trace key operations #40063
Conversation
There are some noteworthy rough edges:
Updates:
|
CI failures are because I didn't update the harness System impl(s). That can wait until next week. |
There are deliberately few trace events in the checker to avoid (excessively) skewing the runtime. If people would like to see more, e.g. for debugging, my inclination would be to add a separate mode (i.e. profiling trace vs activity trace). Note that the persistence format is JSON, so it's very easy to create enormous trace files (e.g. adding |
Have you looked at the sources for |
Rough instructions for using it in its present state:
|
Produce output in Chrome's event tracing format so that it can be viewed in Chrome/Edge.
Having applied this to several repos now, I feel pretty confident that this is useful in its current state. Enriching it with additional tracepoints (e.g. for inference) or output (e.g. stack traces) can follow in future PRs. |
export function startTracing(configFilePath: string | undefined, traceDir: string, isBuildMode: boolean) { | ||
Debug.assert(!traceFd, "Tracing already started"); | ||
|
||
if (fs === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the future we might be able to move some of this logic to a conditionally loaded module, similar to the extended debug information for flow nodes in ~/src/debug/dbg.ts loaded by ~/src/compiler/debug.ts:
TypeScript/src/compiler/debug.ts
Lines 655 to 668 in d896353
// attempt to load extended debugging information | |
try { | |
if (sys && sys.require) { | |
const basePath = getDirectoryPath(resolvePath(sys.getExecutingFilePath())); | |
const result = sys.require(basePath, "./compiler-debug") as RequireResult<ExtendedDebugModule>; | |
if (!result.error) { | |
result.module.init(ts); | |
extendedDebugModule = result.module; | |
} | |
} | |
} | |
catch { | |
// do nothing | |
} |
I've been thinking about moving more of ts.Debug
into the external file to reduce the file size of tsc.js, typescript.js, and tsserver.js as well.
This obviously isn't something we need to do now, but we might want to consider putting it on the backlog.
@amcasey I'm having the problem that I am running this patch against 4.1.0-beta to also get the diff --git a/lib/tsc.js b/lib/tsc.js
index c78b8d698ea730be5a363592a25eb5eb9815753b..4333d58e45d2b2a55724ce7f7894c482223fc36c 100644
--- a/lib/tsc.js
+++ b/lib/tsc.js
@@ -59317,7 +59317,13 @@ var ts;
}
}
function checkExpression(node, checkMode, forceTuple) {
- ts.tracing.begin("check", "checkExpression", { kind: node.kind, pos: node.pos, end: node.end });
+ var parent = node.parent;
+ while (parent && parent.kind !== 300 /*SyntaxKind.SourceFile*/) {
+ parent = parent.parent
+ }
+ var sourceFile = parent;
+
+ ts.tracing.begin("check", "checkExpression", { kind: node.kind, pos: node.pos, end: node.end, sourceFile: sourceFile && sourceFile.fileName || "unknown" });
var saveCurrentNode = currentNode;
currentNode = node;
instantiationCount = 0;
|
@phryneas Thanks for the patch! I had an early version that included similar code (there's actually a helper for walking up to the source file) but concluded that the extra tree walking was distorting the timing and the paths were bloating the log file excessively. Since readability wasn't a goal for v1, I left it out. When I've encountered the problem in practice, I've used code inspection on the frames that are in the right file plus types from later in the call stack to work out what was going on. p.s. Sorry about the confusion this caused you - it's frustrating to waste time on things like that. |
Produce output in Chrome's event tracing format so that it can be viewed in Chrome/Edge.
Hat tip to @samccone for suggesting the format.