Control method trace by using the command-line option -Xtrace:<option>.
To produce method trace you need to set trace options for the Java
classes and methods you want to trace. You also need to route the
method trace to the destination you require.
You must set the following two options:
- Use -Xtrace:methods to select which Java
classes and methods you want to trace.
- Use either
- -Xtrace:print to route the trace to stderr.
- -Xtrace:maximal and -Xtrace:output to
route the trace to a binary compressed file using memory buffers.
Use the methods parameter to control what is traced. For
example, to trace all methods on the String class, set -Xtrace:methods=java/lang/String.*,print=mt.
The
methods parameter is formally defined as follows:
-Xtrace:methods=[[!]<method_spec>[,...]]
Where
<method_spec> is
formally defined as:
{*|[*]<classname>[*]}.{*|[*]<methodname>[*]}[()]
Note:
- The symbol "!" in the methods parameter is a NOT operator. Use
this symbol to exclude methods from the trace. Use "this" with other methods parameters
to set up a trace of the form: "trace methods of this type but not
methods of that type".
- The parentheses, (), that are in the <method_spec> define
whether to trace method parameters.
- If a method specification includes any commas, the
whole specification must be enclosed in braces:
-Xtrace:methods={java/lang/*,java/util/*},print=mt
- On Linux®, AIX®, z/OS®, and i5/OS®, you might have to enclose your command
line in quotation marks. This action prevents the shell intercepting
and fragmenting comma-separated command lines:
“-Xtrace:methods={java/lang/*,java/util/*},print=mt”
Use the
print,
maximal and
output options
to route the trace to the required destination, where:
- print formats the tracepoint data while the Java application
is running and writes the tracepoints to stderr.
- maximal saves the tracepoints into memory buffers.
- output writes the memory buffers to a file, in a binary
compressed format.
To produce method trace that is routed to stderr, use the print option,
specifying mt (method trace). For example: -Xtrace:methods=java/lang/String.*,print=mt.
To produce method trace that is written to a binary file from the
memory buffers, use the maximal and output options.
For example: -Xtrace:methods=java/lang/String.*,maximal=mt,output=mytrace.trc.
If you want your trace output to contain only the tracepoints you
specify, use the option -Xtrace:none to switch
off the default tracepoints. For example: java -Xtrace:none
-Xtrace:methods=java/lang/String.*,maximal=mt,output=mytrace.trc <class>.