Skip to content

Collecting data for an investigation.

Heejae Chang edited this page May 28, 2024 · 9 revisions

Collecting Trace Logs

  1. Enable trace logging by adding "python.analysis.logLevel": "Trace" to your settings.json configuration file.
  2. Select "View: Toggle Output" from the command palette (Ctrl+Shift+P on Windows/Linux, Command+Shift+P on macOS), then select "Python Language Server" in the dropdown on the right.
  3. Copy the entire log starting with "Pylance language server XXX (pyright xxx) starting"

The output will be substantial, but having the full log will help people investigating what is happening

  • You can confirm you have the correct log by checking for entries such as the one below.
Search paths for file:///c%3A/repo/test
  c:\repo\test
  c:\repo\test\src
  c:\repo\test\.venv
  c:\repo\test\.venv\Lib\site-packages
  
Adding fs watcher for library directories:
  file:///c%3A/repo/test/.venv
  file:///c%3A/repo/test/.venv/Lib/site-packages
  
Adding fs watcher for directories:
  file:///c%3A/repo/test

Collecting Trace Logs Using Commands

You can also save the log by using the Pylance: Start Logging and Pylance: Stop Logging commands. Simply start logging, perform your repro, stop logging, and then share the saved log file with us.

Collecting type evaluation related data in the log

  1. set python.analysis.logLeve to Trace
  2. set python.analysis.logTypeEvaluationTime to true
  3. set python.analysis.typeEvaluationTimeThreshold to 500

this will include type evaluation related data to the log. this data is quite large so it should be only included when needed.

Collecting *.cpuprofiles

[available in 2024.3.100 and after]

  1. Load the Pylance extension by either creating/opening a Python file or folder.
  2. Select "View: Toggle Output" from the command palette (Ctrl+Shift+P on Windows/Linux, Command+Shift+P on macOS), and wait for the "Python Language Server" output pane to be created, logging the state "Pylance language server XXX (pyright xxx) starting".

image

  1. Wait for VS Code to go idle (no CPU time on VS Code).
  2. Select "Pylance: Start profiling" from the command palette.
  3. Reproduce the performance issue.
  • when reproducing, please ensure it's as short as possible, containing only the performance issue observed, to avoid unnecessary noise and make identifying issues easier, if not impossible.
  1. Wait for VS Code to go idle (no CPU time on VS Code).
  2. Select "Pylance: Stop profiling" from the command palette.
  3. Go to the folder the message box showed.

image

  1. Select all *.cpuprofile files in the folder.
  2. Provide those files to Pylance, such as attaching them to an issue.
  • If you believe it is an indexing issue, one should:
  1. Start pylance extension with "python.analysis.indexing": false and
  2. Then perform steps 1~4, change "python.analysis.indexing": true in settings.json and save.
  3. Then perform steps 6~10.
  • "Pylance: Stop profiling" will generate cpuprofile files for each worker thread. Having all of them will help those investigating the performance issue.

  • If you encounter an Out of Memory (OOM) error because the reproduction step is too large, use "python.analysis.nodeExecutable" to allocate more memory to the Pylance extension.