1. Java profiling
Do It Yourself
Alexey Ragozin
alexey.ragozin@gmail.com
2. JVM diagnostic interfaces
• JMX
• JVMTI – native API only
• Attach API
Ad hoc instrumentation
and more
• Perf counters
• Heap dump
3. MBeans: threading
CPU usage per thread (user / sys)
Memory allocation per thread
Block / wait times
Should be enabled
Stack traces
Invaluable
7. JVM Attach API
• List JVM processes
• Attach to JVM by PID
• Send control commands
heap dump / histogram
stack dump
• Inspect system properties and VM options
• Launch instrumentation agents
https://github.com/gridkit/jvm-attach
8. SJK: hh --dead
Dead object histogram
Similar to jmap –histo
Invoke jmap –histo two time
all heap objects
live heap object
calculates difference
Can show top N rows
https://github.com/aragozin/jvm-tools/blob/master/sjk-core/COMMANDS.md#hh-command
10. SJK: jps
JDK’s jps on steroid
Uses attach API
Lists VMs
Filtering by JVM system properties
Prints property values
Prints effective –XX options
https://github.com/aragozin/jvm-tools/blob/master/sjk-core/COMMANDS.md#jps-command
12. Perf counters
Based on shared memory
safe for target JVM
Flat data model
misc JVM counters
true GC CPU usage data
you can add own counter programmatically
13. Stack Trace Sampling
Capture
• Dump stack traces via local connection
• Store in highly compressed dump
Analysis
• Frame frequency
• Conditional frame frequency
• Traces classification histogram
15. Working with heap dumps
Java API to traverse heap dump object graph
Available at https://github.com/aragozin/jvm-tools/tree/master/hprof-heap
Based on NetBeans profiler library
No temporary files used
Fixed generic method signatures
Improved performance
Useful for
In-place processing of large heap dumps
Write domain specific heap usage reports
16. SJK Summary
Visit https://github.com/aragozin/jvm-tools
Single executable JAR
Command line interface
Exploits JMX / Attach API / PerfCounters
Simple sampling profiler included
Extensible commands
Write commands for your own application
19. Thank you
Alexey Ragozin
http://blog.ragozin.info
- my articles
http://aragozin.timepad.ru
- IT community events in Moscow
alexey.ragozin@gmail.com