How to generate a YourKit session

  • Updated

Objective

Generate a YourKit session for debugging purposes.

Process

Here are the steps to manually generate a YourKit session:

  1. Download the Linux .zip archive from: https://www.yourkit.com/download/. (This contains the necessary binaries for all environments.)
  2. Unzip the contents to any location (this is your Profiler Directory referenced below).
  3. Add the -agentpath flag as shown on this page: https://www.yourkit.com/docs/java/help/agent.jsp. Remember to put this new flag before the -javaagent flag. We also want to add the following options for the profiling session:
    • “sampling” -- this will turn on CPU profiling as soon as the app starts.
    • “onexit=snapshot” -- this will tell the agent to dump a snapshot to disk ($USER/Snapshots) after the JVM exits cleanly
    • "alloceach=10" -- turn on object allocation recording at the start, recording each 10th allocation.
    • "usedmem=90" -- capture a snapshot when the memory usage reaches 90%
    So, our final path will look something like:
 -agentpath:<Profiler Directory>/bin/<architecture>/libyjpagent.so=sampling,alloceach=10,usedmem=90,onexit=snapshot
  1. For agent versions 3.6.1 and newer, an internal feature for advanced instrumentation of strings will have to be disabled to allow running YourKit from the command line.  Add the following System Property to the command line when launching with YourKit.
-Dcontrast.java.agent.enable_java_string_support=false
  1. Make sure the Contrast log level is ERROR or WARN.
  2. Delete the contrast.log file
  3. Start the server
  4. Browse the application enough to experience the unwanted behavior (slowness, crashing, etc)
  5. Shutdown the server
  6. Check the $USER/Snapshots directory, please zip up and send to support. Also include standard out logs that will confirm that YourKit was running properly.

For problems not related to memory, you can use the same steps except change #2:

  1. Add the -agentpath flag as shown on this page: https://www.yourkit.com/docs/java/help/agent.jsp. Remember to put this new flag before the -javaagent flag. We also want to add the following options for the profiling session:
    • “sampling” -- this will turn on CPU profiling as soon as the app starts.
    • “onexit=snapshot” -- this will tell the agent to dump a snapshot to disk ($USER/Snapshots) after the JVM exits cleanly

It is worth noting that problems with memory can masquerade as problems with CPU or slow requests, as memory thrashing will cause all operations to slow down.

 

Example setup on Centos/RHEL


 

1. Change dir to where you're going to download YourKit

 cd /tmp

 2. Grab the download from YourKit's site

wget https://www.yourkit.com/download/YourKit-JavaProfiler-2019.8-b127.zip

3. Unzip the file

unzip YourKit-JavaProfiler-2019.8-b127.zip

4. Add the agentpath flag. This will set the option for 64bit Java & set the Snapshot directory to /tmp & enable sampling & take the snapshot when the app is shutdown.  Remember to put this new flag before the -javaagent flag

-agentpath:tmp/bin/linux-x86-64/libyjpagent.so=dir=/tmp,sampling,alloceach=10,usedmem=90,onexit=snapshot

5.  Add the following system property for YourKit to run

-Dcontrast.java.agent.enable_java_string_support=false

6. Sets log level to info to impact performance the least

-Dcontrast.agent.logger.level=INFO

7. Print timestamps to stdout related to the loading of Contrast (OPTIONAL)

-Dcontrast.profile.startup=true

8. Remove the current contrast.log file

rm /home/$user/.contrast/contrast.log

 

Was this article helpful?

1 out of 1 found this helpful

Have more questions? Submit a request