Java Resource Usage Tools - ISISComputingGroup/ibex_developers_manual GitHub Wiki

Wiki > Project tools > Java resource tools

Java Memory and CPU Profiling and Leak Detection

JVisualVM

This is started from any java jdk in bin double click on jvisualvm.exe. You can then immediately look at the heap of your java application.

You can then take a heap dump (button top right) and this can show where all the memory or instance have gone. (This can be extremely slow)

You can also look at what functions are using what resources by using the sampler or the profiler and using CPU/memory sampling or profiling.

Setup JVisualVM to monitor a remote client

  • Look in the log file for the client (will be on the NDX at C:\Instrument\Apps\Client_E4\workspace\logs) that you want to remotely monitor

  • When the client first starts it will print JMX url: followed by a url that looks a bit like service:jmx:rmi://machine/stub/rO0ABXNyAC5qYXZheC5tYW5hZ2V...

  • Add a JMX connection in the java visual VM and copy in the whole url

  • WARNING: using this interface you can do harm to the client and thus running experiments! Therefore you should only look at the monitoring graphs and use the sampler. For anything else you must inform the user that it may cause issues

Memory Analyzer

Installed in eclipse through the market place (search for this)

Then edit your run configuration and include -agentlib:hprof=heap=dump,format=b in your VM arguments. When the program exists it produces a heap profile which the memory analyser can load and then find possible memory leaks in.

See also

https://github.com/ISISComputingGroup/ibex_developers_manual/wiki/Debugging-memory-leaks-in-the-IBEX-GUI

JStack

JStack is a utility that comes bundled with a JDK. It can be used to perform post-mortem analysis of a crash dump generated by a java executable. It will give tracebacks of every thread at the time when the JVM crashed, which can help diagnose the root cause of a crash.

Example of usage:

"C:\Program Files\Java\jdk1.8.0_192\bin\jstack.exe" -J-d64 ibex-client.exe hs_err_pidxxxxx.mdmp

To view "native" frames (frames inside DLLs), add the "-m" switch.

Notes:

  • The first argument should be the executable that generated the crash dump (i.e. it should be the released version of the client, not a dev version). The second argument is a minidump which the JVM will generate if there is a "hard" crash (e.g. a segmentation fault as opposed to a normal java exception).

Full documentation available here.