Yourkit Introduce

Profiling your application (Yourkit)

 

Install Yourkit

Linux

./yjp.sh

Windows

yjp-12.0.5.exe

 

Profile your application by Yourkit

Plugin IDE

 

Manual config

-agentpath:<profiler directory>\bin\win64(win32)\yjpagent.dll

-agentpath:<profiler directory>/bin/linux-x86-64(linux-x86-32)/libyjpagent.so

default port:10001

-agentpath:<profiler directory>\bin\win64(win32)\yjpagent.dll=port=1090

more options: http://www.yourkit.com/docs/java/help/startup_options.jsp

 

Attach in runtime

a. Attach for local connect purpose

b. Attach for remote connet purpose

(1) The attach mode is only supported for Sun Java (HotSpot) and JRockit

(2) Attach may fail due to insufficient access rights

(3) Requires kernel 2.6

...

not suggestion using attach mode

 

Before profiling

JVM memory structure

 

Shallow size/Retained size

Shallow heap is the memory consumed by one object. An object needs 32 or 64 bits (depending on the OS architecture) per reference, 4 bytes per Integer, 8 bytes per Long, etc. Depending on the heap dump format the size may be adjusted (e.g. aligned to 8, etc...) to model better the real consumption of the VM.

 

Retained set of X is the set of objects which would be removed by GC when X is garbage collected.

 

Retained heap of X is the sum of shallow sizes of all objects in the retained set of X, i.e. memory kept alive by X.

 

Generally speaking, shallow heap of an object is its size in the heap and retained size of the same object is the amount of heap memory that will be freed when the object is garbage collected.

 

GC root

A garbage collection root is an object that is accessible from outside the heap. The following reasons make an object a GC root:

 

System Class

Class loaded by bootstrap/system class loader. For example, everything from the rt.jar like java.util.* .

 

JNI Local

Local variable in native code, such as user defined JNI code or JVM internal code.

 

JNI Global

Global variable in native code, such as user defined JNI code or JVM internal code.

 

Thread Block

Object referred to from a currently active thread block.

 

Thread

A started, but not stopped, thread.

 

Busy Monitor

Everything that has called wait() or notify() or that is synchronized. For example, by calling synchronized(Object) or by entering a synchronized method. Static method means class, non-static method means object.

 

Java Local

Local variable. For example, input parameters or locally created objects of methods that are still in the stack of a thread.

 

Native Stack

In or out parameters in native code, such as user defined JNI code or JVM internal code. This is often the case as many methods have native parts and the objects handled as method parameters become GC roots. For example, parameters used for file/network I/O methods or reflection.

 

Finalizer

An object which is in a queue awaiting its finalizer to be run.

 

Unfinalized

An object which has a finalize method, but has not been finalized and is not yet on the finalizer queue.

 

Unreachable

An object which is unreachable from any other root, but has been marked as a root by MAT to retain objects which otherwise would not be included in the analysis.

 

Unknown

An object of unknown root type. Some dumps, such as IBM Portable Heap Dump files, do not have root information. For these dumps the MAT parser marks objects which are have no inbound references or are unreachable from any other root as roots of this type. This ensures that MAT retains all the objects in the dump.

 

CPU time/Work time

 

CPU time is the time on scheduler

Work time is the total time from request in to response out

 

Thread status

NEW: The thread is created but has not been processed yet.

RUNNABLE: The thread is occupying the CPU and processing a task. (It may be in WAITING status due to the OS's resource distribution.)

BLOCKED: The thread is waiting for a different thread to release its lock in order to get the monitor lock.

WAITING: The thread is waiting by using a wait, join or park method.

TIMED_WAITING: The thread is waiting by using a sleep, wait, join or park method. (The difference from WAITING is that the maximum waiting time is specified by the method parameter, and WAITING can be relieved by time as well as external changes.)

 

5 CPU profile

# Telemetry

# Sampling

# Tracking

To begin obtaining profiling results, start CPU measuring when your application requires it.

You can choose either of two available measurement modes: sampling or tracing.

 
Sampling
Tracing
Measured time accuracy
High for long running methods, low for short running methods
Low to high, depending on profiled application and  settings
Invocation counts
Not available
Available
Overhead
Negligible unless  J2EE high-level profiling is enabled in the  settings
Low to high, depending on profiled application and  settings

# Filter methods

 

6 Thread monitor

# Telemetry

# Monitor profile

 

 

7 Memory profile

# Telemetry

The "Memory" tab shows live memory usage statistics:

 

The bottom table on "Memory" tab provides a class instance count statistics - a quick overview of current heap state:

# Record by thread/method/classloader/GC root (allocation)

# Compare two snapshot

# Object generations

# Support of HPROF format snapshots

 

8 Exception profile

# Show where the exception throws

 

Conclusion

# Out of memory occurd

# Memory leak

# Timeout

# Deadlock

# Also anytime when you want to refine your application

猜你喜欢

转载自bkhh.iteye.com/blog/1883476