Show TOC

TracingLocate this document in the navigation structure

Use

The VM does a lot of tracing, which can aid runtime analysis of Java programs. Examples are garbage collection statistics, method tracing or exception tracing.

Procedure

The verbose tracing for a certain VM component is controlled using the command line option -Xtrace in the form ‑Xtrace<traceflag>.

Using just the option -Xtrace gives an overview of all existing trace flags.

  • ‑XtraceMethods switches on the method traces.

  • ‑Xtrace* switches on all trace flags starting with a certain name.

    Example: ‑XtraceClass* switches on the following trace flags: ClassLoading, ClassUnloading, ClassStatistic

    Example: ‑Xtrace* switches on all trace flags.

  • ‑XtraceInfoHeader=<info header format>

    Each trace line is preceded by a header. This header, which is similar to a prompt line on a UNIX shell, can be freely formatted and can contain a lot of useful information.

    Example: ‑XtraceInfoHeader=HELLO> causes the traces to look like this: HELLO> trace output .

  • ‑XtraceWarningHeader=<info header format>

    ‑XtraceErrorHeader=<info header format>

    Same as ‑XtraceInfoHeader for warning and error messages.

Placeholders can be used to embed information in the trace line. The following placeholders are available:

Placeholder Description

@PID

Process id

@TID

Thread id

@SRC

Source file and line of the C or Java code that caused the trace output

@TIM

@TIME

Current time

@DAT

@DATE

Current date

@CMP

A short marker for the component, which caused the trace, for example, “MTH” for method traces

@VMID

Unique VM ID

  • The command ‑XtraceInfoHeader=Date: @DAT(@TIM) Process:@PID Thread:@TID>> causes the traces to look like this:

    Date: 2009-01-16(15:12:48) Number:0 Process:5832 Thread:5508 >> trace output...

    Date: 2009-01-16(15:12:48) Number:1 Process:5832 Thread:5508 >> trace output...

    Date: 2009-01-16(15:12:52) Number:2 Process:5832 Thread:5508 >> trace output...

  • ‑XtraceWarningHeader=<info header format>

    ‑XtraceErrorHeader=<info header format>

    Same as ‑XtraceInfoHeader for warning- and error messages.

Setting trace options in a running system

In addition to the command line options, tracing settings can be changed on the fly at any time using the jvmmon tool. This allows enabling or disabling any available VM trace, therefore offering a facility to inspect problems when they occur.