Wednesday, October 3, 2012

Offline Profiling with JProfiler


We use offline profiling when we want to run the profiling in the headless mode (without UI). Another option is to profile by connecting remotely using JProfiler GUI, which is great.  However, sometime even that option is not available if the network is slow or only allow SSH connection.

Following are quick instructions for offline profiling. For more details, refer to the "JProfiler Manual".
  1. Create a JProfile session and configure the triggers. Make sure you add a "save snapshot trigger with a timer", else you will not get anything. Do this like every 5-10 minutes. You can also give the target snapshot file location when you configure. 
  2. Copy local .jprofiler7/config.xml and JProfiler binaries or agent code to the remote machine 
  3. Add following before the java command.
    -agentpath:JPROF_LOCATION/bin/macos/libjprofilerti.jnilib=offline,id=SESSION_ID,config=/Users/srinath/.jprofiler7/config.xml 
    Here replace the configuration file and JProfiler location with your machine's values. SESSION_ID is the session ID of the session you created with JProfiler UI.  Here ~./jprofiler7/config.xml file has settings for all sessions creates by jprofiler, and it will pick up the right value.  If you are profiling in a remote machine copy your local configs to the remote host. 
  4. Start and run the program, and it will print  the following
  5. JProfiler> Using JVMTI
    JProfiler> JVMTI version 1.1 detected.
    JProfiler> 64-bit library
    JProfiler> Offline profiling mode.
    JProfiler> Using config file /Users/srinath/.jprofiler7/config.xml (id: 194)
    JProfiler> Listening on port: 8849.
    JProfiler> Instrumenting native methods.
    JProfiler> Can retransform classes.
    JProfiler> Can retransform any class.
    JProfiler> Native library initialized
    JProfiler> VM initialized
    JProfiler> Using dynamic instrumentation
    JProfiler> Time measurement: elapsed time
    JProfiler> CPU profiling enabled
    JProfiler> Hotspot compiler enabled

  6.  Open the snapshot file and analyze using JProfiler UI. 



No comments: