Thread dumps can help to identify IDE performance problems when it locks and user interface doesn't respond.
A dump should be taken exactly at the moment when IDE doesn't respond and will record the thread stack. Recording several thread dumps with 1-2 seconds interval can be also very useful for the problem analysis.
Automatic thread dumps
IDE runs a special thread that detects when UI is locked for a certain time and takes automatic thread dumps into the logs directory. You will find several folders with the name like threadDumps-freeze-20221117-095348-IU-222.4345.14-5sec. Zip these folders together with the logs and attach to you problem report.
If automatic thread dumps were not generated (for example when the whole IDE process is completely blocked), it is needed to capture thread dumps manually:
jstack
The jstack command line utility can be used to capture a thread dump when the IDE hangs. This tool is provided with the JDK installation and can be found in JAVA_HOME\bin directory or the <ide_installed_path>/jbr/bin (available on the IDE 2021.1 and later version). If you are using Toolbox App, please see this article about <ide_installed_path> location.
To use jstack you need the IDE process identifier (PID). PID can be obtained using jps utility that is located in the same directory as jstack.
jps -lExample: If you want to use jstack from some_path_to_jdk_bin_folder, open a terminal and run some_path_to_jdk_bin_folder/jps -l (on macOS and Linux) or some_path_to_jdk_bin_folder\jps.exe -l (on Windows).
This command lists the Java processes running on your system along with their main class names.
For example, the output would look like this:
1616 jdk.jcmd/sun.tools.jps.Jps -ml
3616 com.intellij.idea.Main
7628 org.jetbrains.idea.maven.server.RemoteMavenServer36Find the process ID that ends with com.intellij.idea.Main. If you have multiple JetBrains-based IDEs running, either close the other instances to identify the correct process ID using jps command line or open your system’s Task/Activity Manager and locate the IDE's process ID (you may need to enable the PID, or Process ID, column to view it). In this example, the process ID is 3616.
jstack -l <PID>Example: If you want to use jstack from some_path_to_jdk_bin_folder and the process ID is 3616, open a terminal and run some_path_to_jdk_bin_folder/jstack -l 3616 (on macOS and Linux) or some_path_to_jdk_bin_folder\jstack.exe -l 3616 (on Windows).
Running jstack with the IDE PID will print the thread dump into console, however it's not very convenient. Use this command to redirect the output to a file:
jstack -l <PID> > dump.txtTo take several dumps repeat this command with different file names, like dump1.txt, dump2.txt, etc.
Thread dump from the console
If jstack doesn't work, it's possible to start IDE from the console/terminal and take a dump using platform specific ways.
Windows
Use the .bat file named for the product and located in IDE_HOME\bin directory (idea.bat, phpstorm.bat, webstorm.bat, pycharm.bat, rubymine,bat).
Press Ctrl+Break (NOT Ctrl+C) in the console to take a thread dump. Dumps can be long, running with output redirection to a file is recommended, like:
idea.bat > output.txt 2>&1You can record several dumps in the same file by pressing Ctrl+Break multiple times.
macOS
Browse to the /Applications/<PRODUCT>.app/Contents/MacOS/<product> executable in Finder, in the context menu choose Open With, Terminal. To get a thread dump press Ctrl+\ in the Terminal window.
Linux, Solaris, Generic Unix
Start the IDE from the terminal using the .sh script in the product bin directory. Start another terminal, find the IDE java process ID using jps, ps or your other favorite process manager. Send the QUIT signal to the IDE process:
kill -QUIT <PID>Thread dump should be printed into the first terminal window from where IDE was started. Use process output to a file redirection to capture long dumps.
Comments
0 comments
Please sign in to leave a comment.