X Tutup
The Wayback Machine - https://web.archive.org/web/20201101091430/https://github.com/microsoft/TypeScript/pull/40063
Skip to content
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

Merged
merged 6 commits into from Sep 10, 2020
Merged

Trace key operations #40063

merged 6 commits into from Sep 10, 2020

Conversation

@amcasey
Copy link
Member

@amcasey amcasey commented Aug 15, 2020

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.

@amcasey
Copy link
Member Author

@amcasey amcasey commented Aug 15, 2020

There are some noteworthy rough edges:

  1. I haven't thought through how to separate/combine the traces for different projects in build mode, so presently I just insert a counter into each path to prevent clobbering.
  2. The new System APIs are ugly, but I think it's important to write as you go, so that you get something if you have to kill a very long build (e.g. customers reporting tens of minutes)
  3. Some types are still only readable by means of typeToTypeNode and I'd really like to eliminate that because of how slow it is (not urgent since it happens after profiling is complete)

Updates:

  1. Only use counters in build mode and print a separate legend file mapping them back to tsconfig paths.
  2. Reverted - @RyanCavanaugh suggested using fs directly.
  3. Will likely wait for a future PR.
@amcasey
Copy link
Member Author

@amcasey amcasey commented Aug 15, 2020

CI failures are because I didn't update the harness System impl(s). That can wait until next week.

@amcasey
Copy link
Member Author

@amcasey amcasey commented Aug 17, 2020

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 inferFromTypes tripled the file size for one sample project).

@rbuckton
Copy link
Member

@rbuckton rbuckton commented Aug 21, 2020

Have you looked at the sources for ts-perf? I made some headway doing the same thing with the existing performance.mark function and have code for generating Chrome timelines.

@amcasey
Copy link
Member Author

@amcasey amcasey commented Aug 21, 2020

Rough instructions for using it in its present state:

  1. Append --generateTrace {folderName} to your regular tsc command line
  2. Look in the resulting folder. If you used build mode, there will be a legend.json telling you what went where. Otherwise, there will be a trace.json file and a types.json files.
  3. Navigate to edge://tracing or chrome://tracing and Load trace.json
  4. Expand Process 1 with the little triangle in the left sidebar
  5. Click on different blocks to see their payloads in the bottom pane
  6. Open types.json in an editor
  7. When you see a type ID in the tracing output, go-to-line {id} to find data about that type
amcasey added 3 commits Aug 6, 2020
Produce output in Chrome's event tracing format so that it can be viewed
in Chrome/Edge.
@amcasey amcasey force-pushed the amcasey:ChromeTracing branch from b3861c8 to 00804d8 Aug 22, 2020
@amcasey
Copy link
Member Author

@amcasey amcasey commented Sep 4, 2020

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.

@amcasey amcasey marked this pull request as ready for review Sep 4, 2020
@sandersn sandersn added this to Not started in PR Backlog Sep 8, 2020
@sandersn sandersn moved this from Not started to Needs review in PR Backlog Sep 8, 2020
@amcasey amcasey mentioned this pull request Sep 9, 2020
0 of 7 tasks complete
@amcasey amcasey merged commit 45dedd6 into microsoft:master Sep 10, 2020
8 checks passed
8 checks passed
build (10.x)
Details
build (12.x)
Details
build (14.x)
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
license/cla All CLA requirements met.
Details
node10 Build #84251 succeeded
Details
node12 Build #84249 succeeded
Details
node14 Build #84250 succeeded
Details
PR Backlog automation moved this from Needs review to Done Sep 10, 2020
@amcasey amcasey deleted the amcasey:ChromeTracing branch Sep 10, 2020
export function startTracing(configFilePath: string | undefined, traceDir: string, isBuildMode: boolean) {
Debug.assert(!traceFd, "Tracing already started");

if (fs === undefined) {

This comment has been minimized.

@rbuckton

rbuckton Sep 10, 2020
Member

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:

// 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PR Backlog
  
Done
Linked issues

Successfully merging this pull request may close these issues.

None yet

3 participants
You can’t perform that action at this time.
X Tutup