30

I do have a jenkins instance that is stuck in some kind of endless loop without any visible activity.

I can get the pid of the running process so how do I generate a trace that I can use for a bug report?

I'm running on linux.

sorin
  • 161,544
  • 178
  • 535
  • 806

5 Answers5

38

Try with jstack. It'll give you a full list of what your threads are doing. All it needs is the process pid.

mprivat
  • 21,582
  • 4
  • 54
  • 64
  • I am not sure if this helps in my case, but it does respond the question http://pastebin.com/r1e0dtzp – sorin May 25 '12 at 14:34
  • It narrows it down to some extent. If you have 100% CPU usage, you want to be looking for threads that are not in the BLOCKING state. For example Thread 30609 is sun.nio.ch.EPollArrayWrapper.epollWait which could potentially match [this defect](https://issues.apache.org/jira/browse/DIRMINA-678) depending on your config. – mprivat May 25 '12 at 14:45
  • Recently jstack stopped working and I am not sure why. Here is the related question http://stackoverflow.com/questions/31179544/did-the-jstack-stopped-working-on-newer-jdk8-versions – sorin Jul 02 '15 at 15:59
  • >NOTE - This utility is unsupported and may or may not be available in future versions of the J2SE SDK. **jstack is not currently available on Windows platforms** or on the Linux Itanium platform. – Matt Jun 24 '19 at 14:01
12

Take a thread dump. Connect through Visual VM and request a dump. Or if on unix then kill -3 pid or on windows Ctrl+Break on the process console would do it for you. The dump goes straight to the console. You can also use jstack to throw a dump.

Drona
  • 6,886
  • 1
  • 29
  • 35
5

Ctrl+\ on linux (which sends SIGQUIT)

Ctrl+Break on windows (which sends SIGBREAK under MSVCRT)

SamB
  • 9,039
  • 5
  • 49
  • 56
4

In *nix, with top by pressing H you can see the threads.

Then with jps you can see the pid bear in mind that if the process was started with privileges then you must execute it with sudo for instance.

If you take the thread id and converted it to hexadecimal then you can cross that data with the jstack pid output.

Both tools are in $JAVA_HOME/bin.

ssedano
  • 8,322
  • 9
  • 60
  • 98
2

Take a look at VisualVM. There is a lot of nice profiling tools with it, and you can perform a thread dump.

Nican
  • 7,825
  • 3
  • 27
  • 26