JDK tools for performance diagnostics   Dror Bereznitsky Director of Technologies, AlphaCSP
Introduction <ul><li>Application to slow ? </li></ul>Image courtesy of   WTL photos   -   flickr
Introduction Leaking Memory ? Image courtesy of   neoliminal - flickr
Intoduction Suffering from deadlocks ? Image courtesy of   hfb  -   flickr
Introduction <ul><li>The JDK has tools that can help you … </li></ul>Image courtesy of   docman  - flickr
JDK tools for performance diag. <ul><li>JDK tools for performance diagnostics: </li></ul>Image courtesy of   dodgechalleng...
VisualVM
VisualVM <ul><li>Java troubleshooting tool </li></ul><ul><li>Visual tool integrating several command line JDK tools and mu...
VisualVM Features <ul><li>Display local/remote Java applications  </li></ul><ul><li>Monitor memory and threads </li></ul><...
<ul><li>MBean browser </li></ul><ul><li>Visual GC </li></ul><ul><li>Memory sampler </li></ul><ul><li>Profiler – CPU, Memor...
VisualVM Feature Matrix           JDK 6 Local      JDK 6 Remote      JDK 5 JConsole plugins MBean Brow...
Supported VMs Requires the VisualVM Extensions plugin  SAP JDK  HP-UX JDK  Using JMX only IBM J9 Oracle JRockit Apple JDK ...
Getting Started <ul><li>Version 1.0 ships with JDK6 since  update 7 </li></ul><ul><ul><li>Look for  jvisualvm  in your JDK...
The Demo Application
VisualVM Demo <ul><li>VisualVM  Demo </li></ul>
Working With Remote Applications <ul><li>Start a  jstatd  daemon on the remote host </li></ul><ul><ul><li>Allow remote mon...
Extending VisualVM <ul><li>What is VisualVM, really? </li></ul><ul><li>Generic desktop application infrastructure for anal...
Extending VisualVM <ul><li>Why you would want to extend VisualVM: </li></ul><ul><ul><li>Tool-Centric   You have a monitori...
Extending VisualVM <ul><li>What Can You Create? </li></ul><ul><ul><li>Tabs: Main tabs, Sub tabs </li></ul></ul><ul><ul><li...
Getting Started With Extending VisualVM <ul><li>Install JDK 6 </li></ul><ul><li>Read VisualVM API Javadoc & Tutorials </li...
VisualVM Usage Scenarios <ul><li>General health monitoring </li></ul><ul><li>Diagnose specific problems  </li></ul><ul><ul...
BTrace
BTrace <ul><li>Dynamic tracing tool for the Java platform </li></ul><ul><li>Safe – read, no write </li></ul><ul><li>Low-ov...
Dynamic Tracing <ul><li>Works by dynamically instrumenting classes of a running Java program – using ASM 3.0 </li></ul><ul...
BTrace HelloWorld Example <ul><li>import  com.sun.btrace.annotations.*;  </li></ul><ul><li>import  static com.sun.btrace.B...
BTrace Terminology <ul><li>Probe Point </li></ul><ul><ul><li>&quot;location&quot; or &quot;event&quot; at which a set of t...
BTrace HelloWorld Example <ul><li>import  com.sun.btrace.annotations.*;  </li></ul><ul><li>import  static com.sun.btrace.B...
Some BTrace Annotations <ul><li>@OnMethod </li></ul><ul><ul><li>Specify target class(es), target method(s) and &quot;locat...
<ul><li>can  not  create new objects.  </li></ul><ul><li>can  not  create new arrays.  </li></ul><ul><li>can  not  throw e...
com . sun . btrace . BTraceUtils  <ul><li>Contains 270  public static  methods which may be called from a BTrace script  <...
Getting Started <ul><li>BTrace is available as a VisualVM plugin </li></ul><ul><li>Requires VisualVM 1.0.1+ </li></ul><ul>...
BTrace Demo <ul><li>Demo </li></ul>
BTrace Demo Source <ul><li>@BTrace </li></ul><ul><li>public   class  SizeOfStatusCache {  </li></ul><ul><ul><li>@OnMethod(...
BTrace Usage Scenarios <ul><li>Fine grained performance analysis </li></ul><ul><li>Runtime profiling and monitoring </li><...
jhat <ul><li>jhat </li></ul>
jhat <ul><li>Java   Heap Analysis Tool </li></ul><ul><li>Parses a java heap dump and launches a web server  </li></ul><ul>...
jhat Features <ul><li>View all class instances </li></ul><ul><li>View class classloader </li></ul><ul><li>View all referen...
OQL <ul><li>SQL-like query language to query Java heap </li></ul><ul><li>Based on JavaScript expression language  </li></u...
Getting Started <ul><li>C:jdk1.6.0_13in>jhat -J-mx512m c:heapdump-1245057502890.hprof </li></ul><ul><li>Reading from c:he...
jhat demo <ul><li>jhat Demo </li></ul>
jhat Usage Scenarios <ul><li>When analyzing large heap dumps – can use a remote powerful server </li></ul><ul><li>When you...
Summary <ul><li>Summary </li></ul>
Summary <ul><li>The JDK contains useful performance diagnostics tools </li></ul><ul><li>These tools can be used for detect...
References <ul><li>Monitoring and Troubleshooting Java applications using JDK tools  (PDF)   </li></ul><ul><li>VisualVM </...
<ul><li>Thank You   </li></ul>
Upcoming SlideShare
Loading in...5
×

Jdk Tools For Performance Diagnostics

3,700

Published on

Coverage of JDK tools for JVM performance monitoring including visualvm, jhat and btrace

Published in: Technology
0 Comments
8 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
3,700
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
235
Comments
0
Likes
8
Embeds 0
No embeds

No notes for slide

Jdk Tools For Performance Diagnostics

  1. 1. JDK tools for performance diagnostics Dror Bereznitsky Director of Technologies, AlphaCSP
  2. 2. Introduction <ul><li>Application to slow ? </li></ul>Image courtesy of WTL photos - flickr
  3. 3. Introduction Leaking Memory ? Image courtesy of neoliminal - flickr
  4. 4. Intoduction Suffering from deadlocks ? Image courtesy of hfb - flickr
  5. 5. Introduction <ul><li>The JDK has tools that can help you … </li></ul>Image courtesy of docman - flickr
  6. 6. JDK tools for performance diag. <ul><li>JDK tools for performance diagnostics: </li></ul>Image courtesy of dodgechallenger1 - flickr <ul><ul><li>VisualVM </li></ul></ul><ul><ul><li>BTrace </li></ul></ul><ul><ul><li>jhat </li></ul></ul><ul><ul><li>jmap </li></ul></ul><ul><ul><li>jconsole </li></ul></ul><ul><ul><li>jstat </li></ul></ul><ul><ul><li>jinfo </li></ul></ul><ul><ul><li>jps </li></ul></ul><ul><ul><li>jstack </li></ul></ul>
  7. 7. VisualVM
  8. 8. VisualVM <ul><li>Java troubleshooting tool </li></ul><ul><li>Visual tool integrating several command line JDK tools and much more </li></ul><ul><li>For development and production time </li></ul>
  9. 9. VisualVM Features <ul><li>Display local/remote Java applications </li></ul><ul><li>Monitor memory and threads </li></ul><ul><li>Take and browse heap + thread dumps </li></ul><ul><li>Extensible with plugins </li></ul><ul><li>Attach API or JMX </li></ul>
  10. 10. <ul><li>MBean browser </li></ul><ul><li>Visual GC </li></ul><ul><li>Memory sampler </li></ul><ul><li>Profiler – CPU, Memory </li></ul><ul><li>BTrace plugin </li></ul><ul><li>Direct buffers monitor (JDK 7) </li></ul><ul><li>Many more … </li></ul>VisualVM Plugins
  11. 11. VisualVM Feature Matrix           JDK 6 Local      JDK 6 Remote      JDK 5 JConsole plugins MBean Browser Heam Dump OOME Heap Dump Thread Dump Profiler Threads  Monitor System properties  Overview JDK 1.4.2
  12. 12. Supported VMs Requires the VisualVM Extensions plugin SAP JDK HP-UX JDK Using JMX only IBM J9 Oracle JRockit Apple JDK Open JDK Sun JDK Remarks Java VM
  13. 13. Getting Started <ul><li>Version 1.0 ships with JDK6 since update 7 </li></ul><ul><ul><li>Look for jvisualvm in your JDK bin directory </li></ul></ul><ul><li>Version 1.1.1 now ships with JDK6 update 14 </li></ul><ul><li>Latest version can be downloaded from https:// visualvm.dev.java.net </li></ul>
  14. 14. The Demo Application
  15. 15. VisualVM Demo <ul><li>VisualVM Demo </li></ul>
  16. 16. Working With Remote Applications <ul><li>Start a jstatd daemon on the remote host </li></ul><ul><ul><li>Allow remote monitoring tools to attach to running JVMs </li></ul></ul><ul><ul><li>May have security implications </li></ul></ul><ul><li>Add the remote host to the ‘Remote’ node in the Applications window </li></ul>
  17. 17. Extending VisualVM <ul><li>What is VisualVM, really? </li></ul><ul><li>Generic desktop application infrastructure for analyzing sources of data. </li></ul><ul><li>Default data sources </li></ul><ul><ul><li>Applications </li></ul></ul><ul><ul><li>Hosts </li></ul></ul><ul><ul><li>Dumps </li></ul></ul><ul><ul><li>Snapshots </li></ul></ul>
  18. 18. Extending VisualVM <ul><li>Why you would want to extend VisualVM: </li></ul><ul><ul><li>Tool-Centric You have a monitoring or management tool that you want to make available to VisualVM </li></ul></ul><ul><ul><ul><li>BTrace plugin </li></ul></ul></ul><ul><ul><li>Application-Centric You have an application with specific monitoring/management needs </li></ul></ul><ul><ul><ul><li>Glassfish plugin </li></ul></ul></ul>
  19. 19. Extending VisualVM <ul><li>What Can You Create? </li></ul><ul><ul><li>Tabs: Main tabs, Sub tabs </li></ul></ul><ul><ul><li>Actions: Menu items, Toolbar buttons </li></ul></ul><ul><ul><li>Application Types </li></ul></ul><ul><ul><li>Data Sources </li></ul></ul>
  20. 20. Getting Started With Extending VisualVM <ul><li>Install JDK 6 </li></ul><ul><li>Read VisualVM API Javadoc & Tutorials </li></ul><ul><li>Create VisualVM modules </li></ul><ul><ul><li>Netbeans IDE </li></ul></ul><ul><li>VisualVM samples collection </li></ul>
  21. 21. VisualVM Usage Scenarios <ul><li>General health monitoring </li></ul><ul><li>Diagnose specific problems </li></ul><ul><ul><li>Memory leaks </li></ul></ul><ul><ul><li>Deadlocks </li></ul></ul><ul><ul><li>Excessive use of finalizers </li></ul></ul><ul><ul><li>Hot lock contention </li></ul></ul><ul><ul><li>Hung process </li></ul></ul>
  22. 22. BTrace
  23. 23. BTrace <ul><li>Dynamic tracing tool for the Java platform </li></ul><ul><li>Safe – read, no write </li></ul><ul><li>Low-overhead </li></ul><ul><li>Tracing code is written in Java </li></ul><ul><li>Available as a VisualVM plugin or as a command line tool </li></ul>
  24. 24. Dynamic Tracing <ul><li>Works by dynamically instrumenting classes of a running Java program – using ASM 3.0 </li></ul><ul><ul><li>ASM is an all purpose Java bytecode manipulation and analysis framework </li></ul></ul><ul><li>Inserts tracing actions by hot-swapping the traced program classes </li></ul>
  25. 25. BTrace HelloWorld Example <ul><li>import com.sun.btrace.annotations.*; </li></ul><ul><li>import static com.sun.btrace.BTraceUtils.*; </li></ul><ul><li>@BTrace </li></ul><ul><li>public class HelloWorld { </li></ul><ul><li>@OnMethod ( </li></ul><ul><li>clazz= &quot;java.lang.Thread&quot; , </li></ul><ul><li>method= &quot;start&quot; </li></ul><ul><li>) </li></ul><ul><li>public static void func() { </li></ul><ul><li>println( &quot;about to start a thread!&quot; ); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  26. 26. BTrace Terminology <ul><li>Probe Point </li></ul><ul><ul><li>&quot;location&quot; or &quot;event&quot; at which a set of tracing statements are executed. </li></ul></ul><ul><li>Trace Actions/Actions </li></ul><ul><ul><li>Trace statements that are executed whenever a probe &quot;fires&quot;. </li></ul></ul><ul><li>Action Methods </li></ul><ul><ul><li>Trace statements that are executed when a probe fires </li></ul></ul><ul><ul><li>defined inside a static method </li></ul></ul><ul><ul><li>Such methods are called &quot;action&quot; methods. </li></ul></ul>
  27. 27. BTrace HelloWorld Example <ul><li>import com.sun.btrace.annotations.*; </li></ul><ul><li>import static com.sun.btrace.BTraceUtils.*; </li></ul><ul><li>@BTrace </li></ul><ul><li>public class HelloWorld { </li></ul><ul><li>@OnMethod ( </li></ul><ul><li>clazz= &quot;java.lang.Thread&quot; , </li></ul><ul><li>method= &quot;start&quot; </li></ul><ul><li>) </li></ul><ul><li>public static void func() { </li></ul><ul><li>println( &quot;about to start a thread!&quot; ); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>Probe Point Action Method
  28. 28. Some BTrace Annotations <ul><li>@OnMethod </li></ul><ul><ul><li>Specify target class(es), target method(s) and &quot;location(s)&quot; within the method(s) </li></ul></ul><ul><li>@OnLowMemory </li></ul><ul><ul><li>Trace memory threshold exceed event </li></ul></ul><ul><li>@OnTimer </li></ul><ul><ul><li>Specify tracing actions that have to run periodically once every N milliseconds </li></ul></ul>
  29. 29. <ul><li>can not create new objects. </li></ul><ul><li>can not create new arrays. </li></ul><ul><li>can not throw exceptions. </li></ul><ul><li>can not catch exceptions. </li></ul><ul><li>can not have loops (for, while, do..while) </li></ul><ul><li>Almost everything is restricted … </li></ul>BTrace Restrictions ?
  30. 30. com . sun . btrace . BTraceUtils <ul><li>Contains 270 public static methods which may be called from a BTrace script </li></ul><ul><li>Many useful methods: </li></ul><ul><ul><li>deadlocks - prints the Java level deadlocks detected (if any) </li></ul></ul><ul><ul><li>dumpHeap - dump the snapshot of the Java heap </li></ul></ul><ul><ul><li>jstack - Prints the java stack trace of the current thread </li></ul></ul>
  31. 31. Getting Started <ul><li>BTrace is available as a VisualVM plugin </li></ul><ul><li>Requires VisualVM 1.0.1+ </li></ul><ul><li>Available at the BTrace plugin center - https:// btrace.dev.java.net/uc/updates.xml </li></ul>
  32. 32. BTrace Demo <ul><li>Demo </li></ul>
  33. 33. BTrace Demo Source <ul><li>@BTrace </li></ul><ul><li>public class SizeOfStatusCache { </li></ul><ul><ul><li>@OnMethod( </li></ul></ul><ul><ul><ul><li>clazz = &quot;com.alphacsp.performance.seminar.twitter.Main&quot; , </li></ul></ul></ul><ul><ul><ul><li>method = &quot;pollForNewStatuses&quot; , </li></ul></ul></ul><ul><ul><ul><li>location = @Location( Kind. RETURN) ) </li></ul></ul></ul><ul><ul><li>public static void onNewStatuses(Object obj) { </li></ul></ul><ul><ul><li>List statusCache = </li></ul></ul><ul><ul><li>(List) get(field(classOf( obj), &quot;statusCache&quot; , true ), obj); </li></ul></ul><ul><ul><li>println(concat( &quot;Number of cached statuses: &quot; , </li></ul></ul><ul><ul><li>str(size( statusCache)))); </li></ul></ul><ul><ul><li>} </li></ul></ul><ul><li>} </li></ul>
  34. 34. BTrace Usage Scenarios <ul><li>Fine grained performance analysis </li></ul><ul><li>Runtime profiling and monitoring </li></ul><ul><li>Collecting statistics </li></ul><ul><li>When no graphic user interface available </li></ul>
  35. 35. jhat <ul><li>jhat </li></ul>
  36. 36. jhat <ul><li>Java Heap Analysis Tool </li></ul><ul><li>Parses a java heap dump and launches a web server </li></ul><ul><li>Basic web interface for browsing the heap dump </li></ul><ul><li>Useful for analyzing memory leaks </li></ul>
  37. 37. jhat Features <ul><li>View all class instances </li></ul><ul><li>View class classloader </li></ul><ul><li>View all references to an object </li></ul><ul><li>View reference chains from Rootset </li></ul><ul><li>Use OQL ( O bject Q uery L anguage) to query heap dumps </li></ul>
  38. 38. OQL <ul><li>SQL-like query language to query Java heap </li></ul><ul><li>Based on JavaScript expression language </li></ul><ul><li>Built-in objects and functions </li></ul><ul><li>OQL help is available from the jhat OQL screen </li></ul>
  39. 39. Getting Started <ul><li>C:jdk1.6.0_13in>jhat -J-mx512m c:heapdump-1245057502890.hprof </li></ul><ul><li>Reading from c:heapdump-1245057502890.hprof... </li></ul><ul><li>Dump file created Mon Jun 15 12:18:22 IDT 2009 </li></ul><ul><li>Snapshot read, resolving... </li></ul><ul><li>Resolving 120908 objects... </li></ul><ul><li>Chasing references, expect 24 dots ........................ </li></ul><ul><li>Eliminating duplicate references........................ </li></ul><ul><li>Snapshot resolved. </li></ul><ul><li>Started HTTP server on port 7000 </li></ul><ul><li>Server is ready. </li></ul>
  40. 40. jhat demo <ul><li>jhat Demo </li></ul>
  41. 41. jhat Usage Scenarios <ul><li>When analyzing large heap dumps – can use a remote powerful server </li></ul><ul><li>When you do not have a graphic user interface </li></ul><ul><li>If you want to perform smart queries on heap content </li></ul>
  42. 42. Summary <ul><li>Summary </li></ul>
  43. 43. Summary <ul><li>The JDK contains useful performance diagnostics tools </li></ul><ul><li>These tools can be used for detecting, analyzing and solving performance related issues </li></ul>
  44. 44. References <ul><li>Monitoring and Troubleshooting Java applications using JDK tools (PDF) </li></ul><ul><li>VisualVM </li></ul><ul><li>VisualVM Sample Collection </li></ul><ul><li>TS-4247 Getting More Out of the Java VisualVM Tool (PDF) </li></ul><ul><li>btrace </li></ul><ul><li>ASM </li></ul><ul><li>jhat </li></ul>
  45. 45. <ul><li>Thank You  </li></ul>
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×