Profiling an application in stand-alone mode

  You can profile an application in stand-alone mode (that is, from the command line), without having the the Test and Performance Tools Platform installed. However, you do need to have the Agent Controller installed on the machine where the application to be profiled resides.

You can profile an application in stand-alone mode by invoking the Java Profiling Agent, which is a library that attaches to a Java virtual machine (JVM) to capture and record the behavior of your Java application. The output from the agent is in the form of XML fragments.

Using the profiler with Java 1.4 (or lower) virtual machines
Using the profiler with Java 5.0 (or higher) virtual machines
Format of the Class Filter file
Controlling the Java Profiling Agent
Notes

 

Using the profiler with Java 1.4 (or lower) virtual machines

Use the -Xrun Java option to invoke the Java Profiling Agent:

    -XrunpiAgent:agent_parm[,agent_parm]*

For example, to profile PerformanceExample.java, using filters that are defined in the file myFilters.txt, and directing the data from the profiling session to a file called PEProfilingData, you would type the following on a command line:
    java -XrunpiAgent:server=standalone,filters=myFilters.txt,file=PEProfilingData.trcxml PerformanceExample

Note: If you want to start WebSphere Application Server Version 6 (WAS) in profiling mode from the command line, you have to perform the following steps:

  1. Go to <profile root>/config/cells/<nodename>Cell/nodes/<nodename>/servers/server1

  2. Edit the jvmEntries element in the server.xml file. In that element, there is an attribute called genericJvmArguments. Append -XrunpiAgent:server=enabled to the attribute value.

  3. Restart WAS.
     

By augmenting the -XrunpiAgent parameter you can specify several different modes to run the profiling agent in. The parameter agent_parm can take one of the following values:

 

Using the profiler with Java 5.0 (or higher) virtual machines

Use the -agentlib Java option to invoke the Java Profiling Agent:

-agentlib:JPIBootLoader=JPIAgent[:[help]|[<option>=<value>,...]];<profiler>[:<option>=<value>,...]

The command line is structured as follows:

JPIBootLoader

is the library that loads the profiling agent.

JPIAgent

is the Java 5.0+ profiling agent. By augmenting the JPIAgent part of the command line with additional options, you can control the behavior of the profiling agent. The following options are supported:

<Profiler>

is the name of the Profiler Library to load. Some of the available profilers support additional profiler-specific options, as described below:

  • CGProf
    Execution time analysis. Supports the following options:

    execdetails=[true | false] : whether to collect execution flow/call-graph information (true) or not (false). Default is false.

  • HeapProf
    Object allocation/heap analysis. Supports the following options:

    allocsites=[true | false] : whether to collect object allocation site information (true) or not (false). Default is false.

  • ThreadProf
    Thread analysis.

To run the Java Profiling Agent in standalone mode on Windows, perform the following steps:

  1. Set TPTP_AC_HOME=<<Agent Controller Home>>

  2. Set JAVA_PROFILER_HOME=%TPTP_AC_HOME%\plugins\org.eclipse.tptp.javaprofiler

  3. Set PATH=%JAVA_PROFILER_HOME%;%PATH%;%TPTP_AC_HOME%\bin

  4. Set PATH=%PATH%;%JAVA_HOME%\bin

  5. Execute the Java application with the -agentlib parameter as described above

 

To run the Java Profiling Agent in standalone mode on Linux, perform the following steps:

  1. Set TPTP_AC_HOME=<<Agent Controller Home>>

  2. Set JAVA_PROFILER_HOME=%TPTP_AC_HOME%/plugins/org.eclipse.tptp.javaprofiler

  3. Add the following directories to LD_LIBRARY_PATH:

%JAVA_PROFILER_HOME%:%TPTP_AC_HOME%/lib
 

  1. Execute the Java application with the -agentlib parameter as described above.

Note

On Linux, make sure to surround the entire -agentlib argument with single quotes. Otherwise, the Linux shell may interpret the semicolon (;) preceding the profiler name as a command terminator and the Java application will not be executed.

Examples

Profiling the "HelloWorld" Java application with the CPU Profiler in standalone mode, writing results into log.trcxml:

java -agentlib:JPIBootLoader=JPIAgent:server=standalone,file=log.trcxml;CGProf HelloWorld

Profiling the "HelloWorld" Java application with the Heap Profiler in standalone mode, using filters defined in myFilter.txt, and collecting information about the source locations were objects are allocated:

java -agentlib:JPIBootLoader=JPIAgent:server=standalone,filters=myFilter.txt;HeapProf:allocsites=true HelloWorld

 

Format of the Class Filter file

The filter file should specify three fields, package/class, method, and mode in the following format:
   package/class method mode

where:

package/class

This field is used to specify a pattern for a package or a class name. The pattern should be specified as a string with no embedded blanks. The string may contain a single asterisk (*) either at the beginning of the string or trailing the string, e.g. *.mypackage or org.mycompany.*. The * matches zero or more characters, thus making the pattern a generic prefix or suffix pattern. A sole * can also be specified to represent all strings.

method

This field is used to specify a pattern for the method name. The pattern should be specified as a string with no embedded blanks and with the same specification rules as the class field.

mode

This field specifies whether the package or class that matches the pattern is to be included or excluded from profiling. The value for mode is either INCLUDE or EXCLUDE.

Filter patterns are processed in the order that they are specified until the first pattern match succeeds. If the class name does not match any of the specified filter patterns, the default is to INCLUDE the class.

 

Controlling the Java Profiling Agent

When the Java Profiling Agent is started with the server=enabled or server=controlled parameter, communication with the agent is done using the client workbench by means of the Agent Controller on the host machine.

 

Notes

 

Related concepts
Overview of the Profiling Tool
Profiling resources

Related tasks
Profiling an application in standalone mode on AS/400
Launching or attaching a Java process
Using the Profiling monitor view