|
| 1 | +# Profiling the analysis server hosted by VS Code |
| 2 | + |
| 3 | +The steps below show how to use the DevTools CPU profiler against the instance |
| 4 | +of the analysis server being hosted by VS Code. This allows profiling a short |
| 5 | +window of operations (such as typing in the editor or invoking code completion). |
| 6 | + |
| 7 | +- Open a project in VS Code that can be used to trigger the bad performance |
| 8 | +- Run the **Preferences: Open Workspace Settings (JSON)** command from the |
| 9 | + command palette (`F1`) or open the `.vscode/settings.json` file |
| 10 | +- Add `"dart.analyzerVmServicePort": 8855` (the exact port number is not important |
| 11 | + but you'll need it further down) |
| 12 | +- Save the settings file |
| 13 | +- A toast notification should appear in the bottom right warning you that the |
| 14 | + analysis server's VM Service is enabled. This is a reminder that you should |
| 15 | + remove the `dart.analyzerVmServicePort` setting when you are done. |
| 16 | +- Wait for initial analysis to complete (No "Analyzing..." or spinners in the |
| 17 | + status bar) |
| 18 | +- Open a file and find a location where you can reproduce the bad performance |
| 19 | +- Run the **Dart: Open DevTools in Browser** command from the palette (`F1`) |
| 20 | +- In DevTools, enter `http://localhost:8855/` (using the port number from above) |
| 21 | + and click **Connect** |
| 22 | +- Navigate to the **CPU Profiler** tab |
| 23 | +- Click **Enable Profiler** |
| 24 | +- In the isolate selector (bottom middle of the page), select the Isolate named |
| 25 | + **main** |
| 26 | +- Click the **Start recording** button |
| 27 | +- Switch back to VS Code and perform the actions that cause bad performance |
| 28 | +- Back in DevTools, click the **Stop recording** button in the CPU Profiler |
| 29 | + |
| 30 | +Profiling information should be displayed automatically and can be exported |
| 31 | +using the export button on the top right corner. Exported information may |
| 32 | +contain paths and class/member names from your project. |
| 33 | + |
| 34 | +When you are done, don't forget to remove the VM Service port from your |
| 35 | +workspace settings: |
| 36 | + |
| 37 | +- Run the **Preferences: Open Workspace Settings (JSON)** command from the |
| 38 | + command palette (`F1`) or open the `.vscode/settings.json` file |
| 39 | +- Remove the `"dart.analyzerVmServicePort": 8855` setting |
| 40 | +- Save the settings file |
0 commit comments