3. Objetivo
Compreender os principais conceitos de profiling
de código e o funcionamento das ferramentas
mais relevantes do mundo Java EE.
3
Sunday, June 27, 2010
4. Profilers deveriam ser ferramentas de
uso das equipes de desenvolvimento.
4
Sunday, June 27, 2010
5. Profilers são ferramentas usadas pelas equipes
de infra-estrutura para se protegerem de
maus códigos.
5
Sunday, June 27, 2010
6. HPROF
Heap Profiler
The Heap Profiler (HPROF) tool is a simple profiler
agent shipped with the JDK release.(...)The HPROF
tool is capable of presenting CPU usage, heap
allocation statistics, and monitor contention profiles. In
addition, it can report complete heap dumps and
states of all the monitors and threads in the Java
virtual machine. In terms of diagnosing problems,
HPROF is useful when analyzing performance, lock
contention, memory leaks, and other issues.
http://java.sun.com/javase/6/webnotes/trouble/TSG-VM/html/tooldescr.html#gblvj 6
Sunday, June 27, 2010
7. $ java -agentlib:hprof=help
HPROF: Heap and CPU Profiling Agent (JVMTI Demonstration Code)
hprof usage: java -agentlib:hprof=[help]|[<option>=<value>, ...]
Option Name and Value Description Default
--------------------- ----------- -------
heap=dump|sites|all heap profiling all
cpu=samples|times|old CPU usage off
monitor=y|n monitor contention n
format=a|b text(txt) or binary output a
file=<file> write data to file java.hprof[{.txt}]
net=<host>:<port> send data over a socket off
depth=<size> stack trace depth 4
interval=<ms> sample interval in ms 10
cutoff=<value> output cutoff point 0.0001
lineno=y|n line number in traces? y
thread=y|n thread in traces? n
doe=y|n dump on exit? y
msa=y|n Solaris micro state accounting n
force=y|n force output to <file> y
verbose=y|n print messages about dumps y
...
7
Sunday, June 27, 2010
16. jboss-4.2.2.GA/bin $ tail -3 run.conf
# Ativacao do HPROF
JAVA_OPTS="$JAVA_OPTS -agentlib:hprof=cpu=samples,file=jboss.hprof.txt"
jboss-4.2.2.GA/bin $ ./run.sh
=========================================================================
JBoss Bootstrap Environment Parâmetro
configurado no
JBOSS_HOME: /Users/alegomes/jbtun/app/jboss-4.2.2.GA
JBoss...
JAVA: /Library/Java/Home/bin/java
JAVA_OPTS: -Dprogram.name=run.sh -Xms128m -Xmx512m -Dsun.rmi.dgc.client.gcInterval=3600000 -
Dsun.rmi.dgc.server.gcInterval=3600000 -Dcom.sun.management.jmxremote -
Djboss.platform.mbeanserver -
Djavax.management.builder.initial=org.jboss.system.server.jmx.MBeanServerBuilderImpl -
agentlib:hprof=cpu=samples,file=jboss.hprof.txt
CLASSPATH: /Users/alegomes/jbtun/app/jboss-4.2.2.GA/bin/run.jar
=========================================================================
08:36:39,356 INFO [Server] Starting JBoss (MX MicroKernel)...
08:36:39,368 INFO [Server] Release ID: JBoss [Trinity] 4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA
date=200710221139)
...
08:38:53,308 INFO [AjpProtocol] Starting Coyote AJP/1.3 on ajp-127.0.0.1-8009
08:38:53,402 INFO [Server] JBoss (MX MicroKernel) [4.2.2.GA (build: SVNTag=JBoss_4_2_2_GA
date=200710221139)] Started in 2m:13s:890ms
...mas nada demais aconteceu. 14
Sunday, June 27, 2010
17. Ctrl +
jboss.hprof.txt
15
Sunday, June 27, 2010
18. java.hprof.txt
JAVA PROFILE 1.0.1, created Wed May 27 07:33:19 2009
Header for -agentlib:hprof (or -Xrunhprof) ASCII Output (JDK 5.0 JVMTI based)
@(#)jvm.hprof.txt! 1.5 06/01/28
Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved.
WARNING! This file format is under development, and is subject to
change without notice.
This file contains the following types of records:
...
documentação no
próprio arquivo
gerado
16
Sunday, June 27, 2010
19. THREAD START
THREAD END mark the lifetime of Java threads
THREAD START (obj=5000013f, id = 200001, name="main", group="main")
THREAD START (obj=5000013f, id = 200005, name="Java2D Disposer", group="system")
THREAD START (obj=5000013f, id = 200006, name="AWT-XAWT", group="main")
THREAD START (obj=5000013f, id = 200007, name="Image Fetcher 0", group="main")
THREAD START (obj=5000013f, id = 200008, name="Image Fetcher 1", group="main")
THREAD START (obj=5000013f, id = 200009, name="Image Fetcher 2", group="main")
THREAD START (obj=5000013f, id = 200010, name="AWT-Shutdown", group="main")
THREAD START (obj=500005e7, id = 200011, name="AWT-EventQueue-0", group="main")
THREAD END (id = 200008)
THREAD END (id = 200007)
THREAD END (id = 200009)
THREAD END (id = 200010)
THREAD END (id = 200011)
17
Sunday, June 27, 2010
20. TRACE represents a Java stack trace. Each trace consists
of a series of stack frames. Other records refer to
TRACEs to identify (1) where object allocations have
taken place, (2) the frames in which GC roots were
found, and (3) frequently executed methods.
TRACE 306106:
! java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:Unknown line)
! java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:Unknown line)
! java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:Unknown line)
TRACE 306095:
! java.lang.Object.wait(Object.java:Unknown line)
! java.lang.ref.Reference$ReferenceHandler.run(Reference.java:Unknown line)
TRACE 317114:
! java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:Unknown line)
! java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:Unknown line)
! sun.java2d.Disposer.run(Disposer.java:Unknown line)
! java.lang.Thread.run(Thread.java:Unknown line)
18
Sunday, June 27, 2010
21. HEAP DUMP is a complete snapshot of all live objects in the Java
heap. Following distinctions are made:
ROOT root set as determined by GC
CLS classes
OBJ instances
ARR arrays
OBJ 50036a24 (sz=392, trace=306854, class=javax.swing.JLabel@50000868)
OBJ 50036a25 (sz=8, trace=306855, class=java.lang.Object@5000009f)
OBJ 50036a26 (sz=8, trace=306856, class=java.lang.Object@5000009f)
OBJ 50036a27 (sz=24, trace=300098, class=java.util.ArrayList@5000005b)
ARR 50036a28 (sz=56, trace=305084, nelems=0, elem type=java.lang.Object[]@500000a0)
OBJ 50036a29 (sz=16, trace=306857, class=javax.swing.event.EventListenerList@50002745)
OBJ 50036a2a (sz=24, trace=306356, class=java.lang.ref.WeakReference@50000037)
19
Sunday, June 27, 2010
22. SITES is a sorted list of allocation sites. This identifies
the most heavily allocated object types, and the TRACE
at which those allocations occurred.
SITES BEGIN (ordered by live bytes) Wed May 27 07:34:16 2009
percent live alloc'ed stack class
rank self accum bytes objs bytes objs trace name
1 9,88% 9,88% 2486200 3 2486200 3 317684 int[]
2 2,13% 12,01% 535440 6693 535760 6697 310354 javax.swing.text.html.InlineView
3 2,07% 14,08% 521592 159 623912 168 306967 char[]
4 1,78% 15,86% 447696 18654 450672 18778 305960 java.awt.Rectangle
5 1,72% 17,58% 432240 18010 599808 24992 310036 java.util.Hashtable$Entry
6 1,69% 19,27% 426240 3330 426368 3331 309154 javax.swing.text.html.ParagraphView
20
Sunday, June 27, 2010
23. NetBeans Profiler
“
The NetBeans profiler provides expert
assistance for optimizing your application's
speed and memory usage, and makes it
easier to build reliable and scalable Java SE,
JavaFX and Java EE applications.
http://www.netbeans.org/features/java/profiler.html 21
Sunday, June 27, 2010
24. WebApp
Inicializa a
aplicação web em
modo de profiling
22
Sunday, June 27, 2010
25. Qual método gastou mais
tempo de processamento
durante a bateria de
testes?
23
Sunday, June 27, 2010
26. Memória
vs
Garbage Collector
24
Sunday, June 27, 2010
32. Mesmo erro no log
do Tomcat do
NetBeans
30
Sunday, June 27, 2010
33. The Eclipse
Test & Performance
Tools Platform
(TPTP)
The Eclipse Test and Performance Tools Platform
(TPTP) Project provides an open platform
supplying powerful frameworks and services that
allow software developers to build unique test and
performance tools, both open source and
commercial, that can be easily integrated with the
platform and with other tools.
http://www.eclipse.org/tptp/ 31
Sunday, June 27, 2010
43. Usando HPROF, NetBeans ou Eclipse,
realizar o profiling da alguma aplicação web Java
durante uma sessão de testes de carga. 41
Sunday, June 27, 2010
44. JProfiler
“ JProfiler's intuitive GUI helps you find
performance bottlenecks, pin
down memory leaks and resolve
threading issues.
http://www.ej-technologies.com/products/jprofiler/overview.html 42
Sunday, June 27, 2010
62. JBoss Profiler
“ JBoss Profiler is a log based profiler using
JVMPI and JVMTI. It uses an agent written in C
that captures events from the JVM and logs to
disk. A web application running on JBoss or
another machine can be used to analyze these
logs through a web browser.
http://www.jboss.org/jbossprofiler/ 52
Sunday, June 27, 2010
64. JBoss Profiler
instalação
• Copiar para JBOSS_HOME/bin
• jboss-profiler.jar,
• jboss-profiler.properties,
• jboss-profiler-plugins.jar
• Copiar para JBOSS_HOME/server/<conf>/deploy
• jboss-profiler.sar
• Se JBoss 4.2x, copie para JBOSS_HOME/bin:
• javassist.jar
54
Sunday, June 27, 2010
65. JBoss Profiler
instalação
• Em JBOSS_HOME/bin/jboss-profiler.properties
# Pacote a ser monitorado pelo Profiler
includes=br.com.seatecnologia.jbosstuning.*
• Em JBOSS_HOME/bin/run.conf
# Ativacao do JBoss Profiler
JAVA_OPTS="$JAVA_OPTS
-javaagent:jboss-profiler.jar
-Djboss-profiler.properties=jboss-profiler.properties"
55
Sunday, June 27, 2010
66. JBoss Profiler
instalação
Reinicialize o JBoss
Ctrl+C
56
Sunday, June 27, 2010
67. JBoss Profiler
utilização
• Inicie o JBoss Profiler
java -jar jboss-profiler-client.jar startProfiler
• Execute a aplicação
Hora de executar o plano de teste do JMeter
• Pare o JBoss Profiler
java -jar jboss-profiler-client.jar stopProfiler
• Colete os dados para análise
java -jar jboss-profiler-client.jar getSnapshot 1
57
Sunday, June 27, 2010
68. java -jar jboss-profiler-client.jar getSnapshot 1
Diretório criado
Arquivos com os
resultados do profiling
Diretório de instalação
do jboss-profiler
58
Sunday, June 27, 2010
69. Duração do teste
Thread mais demorada Métodos mais
demorados
Métodos que mais
usaram a CPU
59
Sunday, June 27, 2010
73. Twiddle:
--------
Information:
./twiddle.sh get 'org.jboss.profiler:service=Profiler' Running
./twiddle.sh get 'org.jboss.profiler:service=Profiler' Enabled
./twiddle.sh get 'org.jboss.profiler:service=Profiler' Memory
./twiddle.sh get 'org.jboss.profiler:service=Profiler' File
./twiddle.sh get 'org.jboss.profiler:service=Profiler' EJB
./twiddle.sh get 'org.jboss.profiler:service=Profiler' Servlet
./twiddle.sh get 'org.jboss.profiler:service=Profiler' JSF
./twiddle.sh get 'org.jboss.profiler:service=Profiler' JMX
./twiddle.sh get 'org.jboss.profiler:service=Profiler' RMI
./twiddle.sh get 'org.jboss.profiler:service=Profiler' CORBA
Operations:
./twiddle.sh invoke 'org.jboss.profiler:service=Profiler' startProfiler
./twiddle.sh invoke 'org.jboss.profiler:service=Profiler' stopProfiler
./twiddle.sh invoke 'org.jboss.profiler:service=Profiler' enableProfiler
./twiddle.sh invoke 'org.jboss.profiler:service=Profiler' disableProfiler
./twiddle.sh invoke 'org.jboss.profiler:service=Profiler' clearSnapshots
./twiddle.sh invoke 'org.jboss.profiler:service=Profiler' addClasses org.jboss.test.* public
./twiddle.sh invoke 'org.jboss.profiler:service=Profiler' removeClasses org.jboss.test.*
./twiddle.sh invoke 'org.jboss.profiler:service=Profiler' listClasses
63
Sunday, June 27, 2010
74. YourKit
“ With YourKit solutions, both CPU and
memory profiling have come to the highest
professional level, where one can profile even
huge applications with maximum productivity and
zero overhead.
http://www.yourkit.com/ 64
Sunday, June 27, 2010