SlideShare a Scribd company logo
Java profiling 
Do It Yourself 
Alexey Ragozin 
alexey.ragozin@gmail.com
JVM diagnostic interfaces 
• JMX 
• JVMTI – native API only 
• Attach API 
 Ad hoc instrumentation 
 and more 
• Perf counters 
• Heap dump
MBeans: threading 
 CPU usage per thread (user / sys) 
 Memory allocation per thread 
 Block / wait times 
 Should be enabled 
 Stack traces 
Invaluable
SJK: ttop 
2014-10-01T19:27:22.825+0400 Process summary 
process cpu=101.80% 
application cpu=100.50% (user=86.21% sys=14.29%) 
other: cpu=1.30% 
GC cpu=0.00% (young=0.00%, old=0.00%) 
heap allocation rate 123mb/s 
Available via PerfCounters 
[000037] user=83.66% sys=14.02% alloc= 121mb/s - Proxy:ExtendTcpProxyService1:TcpAcceptor:TcpProcessor 
[000075] user= 0.97% sys= 0.08% alloc= 411kb/s - RMI TCP Connection(35)-10.139.200.51 
[000029] user= 0.61% sys=-0.00% alloc= 697kb/s - Invocation:Management 
[000073] user= 0.49% sys=-0.01% alloc= 343kb/s - RMI TCP Connection(33)-10.128.46.114 
[000023] user= 0.24% sys=-0.01% alloc= 10kb/s - PacketPublisher 
[000022] user= 0.00% sys= 0.10% alloc= 11kb/s - PacketReceiver 
[000072] user= 0.00% sys= 0.07% alloc= 22kb/s - RMI TCP Connection(31)-10.139.207.76 
[000056] user= 0.00% sys= 0.05% alloc= 20kb/s - RMI TCP Connection(25)-10.139.207.76 
[000026] user= 0.12% sys=-0.07% alloc= 2217b/s - Cluster|Member(Id=18, Timestamp=2014-10-01 15:58:3... 
[000076] user= 0.00% sys= 0.04% alloc= 6657b/s - JMX server connection timeout 76 
[000021] user= 0.00% sys= 0.03% alloc= 526b/s - PacketListener1P 
[000034] user= 0.00% sys= 0.02% alloc= 1537b/s - Proxy:ExtendTcpProxyService1 
[000049] user= 0.00% sys= 0.02% alloc= 6011b/s - JMX server connection timeout 49 
[000032] user= 0.00% sys= 0.01% alloc= 0b/s - DistributedCache 
https://github.com/aragozin/jvm-tools/blob/master/sjk-core/COMMANDS.md#ttop-command
MBeans: memory 
• Memory geometry information 
• Collection count 
• Last collection details 
 for each collector
SJK: GC 
[GC: Copy#1806 time: 7ms interval: 332ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-325397.59kb/s] Tenured 
Gen: 162185k+14k->162199k[max:477888k,rate:42.22kb/s] Survivor Space: 235k-13k->222k[max:23872k,rate:-41.93kb/s]] 
[GC: Copy#1807 time: 8ms interval: 338ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-319621.30kb/s] Tenured 
Gen: 162199k+219k->162418k[max:477888k,rate:648.30kb/s] Survivor Space: 222k-217k->4k[max:23872k,rate:-644.90kb/s]] 
[GC: Copy#1808 time: 7ms interval: 321ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-336548.29kb/s] Tenured 
Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 4k-2k->1k[max:23872k,rate:-7.64kb/s]] 
[GC: Copy#1809 time: 7ms interval: 321ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-336548.29kb/s] Tenured 
Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 1k+0k->1k[max:23872k,rate:0.24kb/s]] 
[GC: Copy#1810 time: 4ms interval: 700ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-154331.43kb/s] Tenured 
Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 1k+288k->290k[max:23872k,rate:412.00kb/s]] 
[GC: Copy#1811 time: 5ms interval: 311ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-347369.77kb/s] Tenured 
Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 290k-155k->135k[max:23872k,rate:-498.52kb/s]] 
[GC: Copy#1812 time: 3ms interval: 340ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-317741.18kb/s] Tenured 
Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 135k-2k->132k[max:23872k,rate:-6.14kb/s]] 
[GC: Copy#1813 time: 6ms interval: 325ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-332406.15kb/s] Tenured 
Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 132k+0k->133k[max:23872k,rate:0.65kb/s]] 
Total 
Copy[ collections: 28 | avg: 0.0065 secs | total: 0.2 secs ] 
MarkSweepCompact[ collections: 0 | avg: NaN secs | total: 0.0 secs ] 
https://github.com/aragozin/jvm-tools/blob/master/sjk-core/COMMANDS.md#gc-command
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
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
SJK: hh --dead 
1: 19117456 2038375696 [C 
2: 9543865 441272568 [Ljava.lang.Object; 
3: 13519356 432619392 java.util.HashMap$Entry 
4: 12558262 301398288 java.lang.String 
5: 7193066 287722640 org.hibernate.engine.spi.CollectionKey 
6: 619253 160678888 [I 
7: 4710497 113051928 org.jboss.seam.international.Messages$1$1 
8: 571327 100876880 [Ljava.util.HashMap$Entry; 
9: 1436183 57447320 org.hibernate.event.spi.FlushEntityEvent 
10: 1661932 53181824 java.util.Stack 
11: 209899 52047904 [B 
12: 1624200 51974400 org.hibernate.engine.internal.Cascade 
13: 929354 44608992 java.util.HashMap 
14: 1812762 43506288 org.hibernate.i.u.c.IdentityMap$IdentityMapEntry 
15: 850157 34006280 java.util.TreeMap$Entry 
16: 1044636 25071264 java.util.ArrayList 
17: 1340986 23423328 [Ljava.lang.Class; 
18: 710973 22751136 java.io.ObjectStreamClass$WeakClassKey 
19: 885164 21243936 org.hibernate.event.internal.WrapVisitor 
20: 885126 21243024 org.hibernate.event.internal.FlushVisitor 
... 
Total 95197823 4793878008 
https://github.com/aragozin/jvm-tools/blob/master/sjk-core/COMMANDS.md#hh-command
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
SJK: jps 
My favorite command 
> sjk jps -pd PID MAIN duser.dir XMaxHeapSize 
90543 sjk-0.3.1-SNAPSHOT.jar /var/vas_sdk_test_server -XX:MaxHeapSize=32126271488 
5315 WrapperSimpleApp /var/vas_sdk_test_server/vas-sdk-test-13030 -XX:MaxHeapSize=4294967296 
11094 WrapperSimpleApp /var/vas_sdk_test_server/vas-sdk-test-13020 -XX:MaxHeapSize=4294967296 
993 Main /var/gedoms-uat/private/rtdb_1 -XX:MaxHeapSize=12884901888 
56603 AxiomApplication /var/gedoms-uat/private/gedoms_1 -XX:MaxHeapSize=2147483648 
24046 WrapperSimpleApp /var/sonar/sonar-3.6.2/bin/linux-x86-64 -XX:MaxHeapSize=536870912 
https://github.com/aragozin/jvm-tools/blob/master/sjk-core/COMMANDS.md#jps-command
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
Stack Trace Sampling 
Capture 
• Dump stack traces via local connection 
• Store in highly compressed dump 
Analysis 
• Frame frequency 
• Conditional frame frequency 
• Traces classification histogram
Stack Trace Sampling 
100.00% 
90.00% 
80.00% 
70.00% 
60.00% 
50.00% 
40.00% 
30.00% 
20.00% 
10.00% 
0.00% 
Base 
Other 
DefaultServlet.doGet 
LifeCycleImpl (render) 
LifeCycleImpl (execute) 
Business logic 
Seam interceptor (lock contention) 
Seam interceptor (inject/outject) 
Resource bundle (getObject) 
Resource bundle (missing) 
Facelet compile 
Hibernate (rest) 
Hibernate (autoFlush) 
JDBC
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
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
BTrace 
Visit https://kenai.com/projects/btrace 
Instrumentation profiling 
 Inject code snippets written in Java 
 CLI or Java API to use 
 Extendible
BTrace 
@OnMethod(clazz = "org.jboss.seam.Component", 
method = "/(inject)/") 
void entryByMethod2(@ProbeClassName String className, @ProbeMethodName String methodName, 
@Self Object component) { 
if (component != null) { 
Field nameField = field(classOf(component), "name", true); 
if (nameField != null) { 
String name = (String)get(nameField, component); 
Profiling.recordEntry(bench, 
concat("org.jboss.seam.Component.", concat(methodName, concat(":", name)))); 
} 
} 
} 
@OnMethod(clazz = "org.jboss.seam.Component", 
method = "/(inject)/", 
location = @Location(value = Kind.RETURN)) 
void exitByMthd2(@ProbeClassName String className, @ProbeMethodName String methodName, 
@Self Object component, @Duration long duration) { 
if (component != null) { 
Field nameField = field(classOf(component), "name", true); 
if (nameField != null) { 
String name = (String)get(nameField, component); 
Profiling.recordExit(bench, 
concat("org.jboss.seam.Component.", concat(methodName, concat(":", name))), duration); 
} 
} 
}
Thank you 
Alexey Ragozin 
http://blog.ragozin.info 
- my articles 
http://aragozin.timepad.ru 
- IT community events in Moscow 
alexey.ragozin@gmail.com

More Related Content

PDF
What every Java developer should know about network?
PPTX
Java profiling Do It Yourself
PDF
Java on Linux for devs and ops
PPTX
Java profiling Do It Yourself (jug.msk.ru 2016)
PDF
Java black box profiling JUG.EKB 2016
PDF
I know why your Java is slow
PPTX
Am I reading GC logs Correctly?
PPTX
Don't dump thread dumps
What every Java developer should know about network?
Java profiling Do It Yourself
Java on Linux for devs and ops
Java profiling Do It Yourself (jug.msk.ru 2016)
Java black box profiling JUG.EKB 2016
I know why your Java is slow
Am I reading GC logs Correctly?
Don't dump thread dumps

What's hot (17)

PPTX
Pick diamonds from garbage
PDF
淺談 Java GC 原理、調教和 新發展
PPT
Find bottleneck and tuning in Java Application
PPTX
Don't dump thread dumps
PDF
Adopting GraalVM - Scala eXchange London 2018
PPTX
자바 성능 강의
PDF
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latency
PDF
Embedded systems
PDF
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
POTX
Performance Tuning EC2 Instances
PDF
USENIX ATC 2017: Visualizing Performance with Flame Graphs
PPTX
Ch10.애플리케이션 서버의 병목_발견_방법
PPTX
How to Troubleshoot OpenStack Without Losing Sleep
PPTX
Rapid Application Design in Financial Services
PPTX
Troubleshooting containerized triple o deployment
PDF
Monitoring with Syslog and EventMachine
PDF
FreeBSD 2014 Flame Graphs
Pick diamonds from garbage
淺談 Java GC 原理、調教和 新發展
Find bottleneck and tuning in Java Application
Don't dump thread dumps
Adopting GraalVM - Scala eXchange London 2018
자바 성능 강의
Optimizing Kubernetes Resource Requests/Limits for Cost-Efficiency and Latency
Embedded systems
Erik Skytthe - Monitoring Mesos, Docker, Containers with Zabbix | ZabConf2016
Performance Tuning EC2 Instances
USENIX ATC 2017: Visualizing Performance with Flame Graphs
Ch10.애플리케이션 서버의 병목_발견_방법
How to Troubleshoot OpenStack Without Losing Sleep
Rapid Application Design in Financial Services
Troubleshooting containerized triple o deployment
Monitoring with Syslog and EventMachine
FreeBSD 2014 Flame Graphs
Ad

Viewers also liked (20)

PDF
Система анализа работы приложений и протоколов Riverbed Cascade
PDF
JPoint 2016 - Etudes of DIY Java profiler
PDF
Михаил Корепанов — Profiler: Профилирование кода
PDF
Autosprite presentation at London Web Summit 2013
PDF
Metaprogramming
PDF
AddConf. Дмитрий Сошников - Будущее ECMAScript
PDF
Божена Пеннер (Mail.ru Group) Как за год набрать 8 тысяч плюсов
PDF
OpenJDK-Zulu talk at JEEConf'14
PDF
iterators-must-go
PDF
Востребованность мер государственной поддержки инновационных предприятий в ро...
PDF
GC @ jmaghreb2014
PPTX
Любовь Соболева, Виктория Гонгина (Tech Media). Хабр и Geektimes.ru: полное п...
ODP
Правильная работа с часовыми поясами в Rails приложении — DevConf 2015
PDF
Fake Flash Drives from TopKeen
PPTX
Светлана Лузгина (ABBYY). Как прокачать корпоративную редакцию
PDF
RubyConf 2010 Keynote by Matz
PDF
Данил Декханов (Fu2RE). Мотивация писать на Хабр: снаружи и изнутри
PDF
В погоне за производительностью
PPT
Продвижение iOS приложений
PPTX
Gepetto’s Army: Creating International Incidents with Twitter Bots
Система анализа работы приложений и протоколов Riverbed Cascade
JPoint 2016 - Etudes of DIY Java profiler
Михаил Корепанов — Profiler: Профилирование кода
Autosprite presentation at London Web Summit 2013
Metaprogramming
AddConf. Дмитрий Сошников - Будущее ECMAScript
Божена Пеннер (Mail.ru Group) Как за год набрать 8 тысяч плюсов
OpenJDK-Zulu talk at JEEConf'14
iterators-must-go
Востребованность мер государственной поддержки инновационных предприятий в ро...
GC @ jmaghreb2014
Любовь Соболева, Виктория Гонгина (Tech Media). Хабр и Geektimes.ru: полное п...
Правильная работа с часовыми поясами в Rails приложении — DevConf 2015
Fake Flash Drives from TopKeen
Светлана Лузгина (ABBYY). Как прокачать корпоративную редакцию
RubyConf 2010 Keynote by Matz
Данил Декханов (Fu2RE). Мотивация писать на Хабр: снаружи и изнутри
В погоне за производительностью
Продвижение iOS приложений
Gepetto’s Army: Creating International Incidents with Twitter Bots
Ad

Similar to DIY Java Profiler (20)

PPTX
Top-5-production-devconMunich-2023-v2.pptx
PPTX
Top 5 Java Performance Problems Presentation!
PPTX
16 ARTIFACTS TO CAPTURE WHEN YOUR CONTAINER APPLICATION IS IN TROUBLE
PDF
DUG'20: 12 - DAOS in Lenovo’s HPC Innovation Center
PDF
Profiling your Applications using the Linux Perf Tools
PPTX
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
PDF
YOW2020 Linux Systems Performance
PPTX
TroubleshootingJVMOutages-3CaseStudies.pptx
PPT
Performance tuning jvm
PPT
Taming Java Garbage Collector
PPTX
The Art of JVM Profiling
PDF
Adopting GraalVM - NE Scala 2019
PDF
Non-blocking I/O, Event loops and node.js
PDF
Disruptive IP Networking with Intel DPDK on Linux
PDF
Building an inflight entertainment system controller in twisted
PPTX
Debugging linux issues with eBPF
PDF
Node Interactive Debugging Node.js In Production
PDF
Nodejs性能分析优化和分布式设计探讨
PDF
Microservices with Micronaut
PDF
Native Java with GraalVM
Top-5-production-devconMunich-2023-v2.pptx
Top 5 Java Performance Problems Presentation!
16 ARTIFACTS TO CAPTURE WHEN YOUR CONTAINER APPLICATION IS IN TROUBLE
DUG'20: 12 - DAOS in Lenovo’s HPC Innovation Center
Profiling your Applications using the Linux Perf Tools
Chicago-Java-User-Group-Meetup-Some-Garbage-Talk-2015-01-14
YOW2020 Linux Systems Performance
TroubleshootingJVMOutages-3CaseStudies.pptx
Performance tuning jvm
Taming Java Garbage Collector
The Art of JVM Profiling
Adopting GraalVM - NE Scala 2019
Non-blocking I/O, Event loops and node.js
Disruptive IP Networking with Intel DPDK on Linux
Building an inflight entertainment system controller in twisted
Debugging linux issues with eBPF
Node Interactive Debugging Node.js In Production
Nodejs性能分析优化和分布式设计探讨
Microservices with Micronaut
Native Java with GraalVM

More from aragozin (20)

PDF
Распределённое нагрузочное тестирование на Java
PPTX
Java black box profiling
PDF
Блеск и нищета распределённых кэшей
PDF
JIT compilation in modern platforms – challenges and solutions
PDF
Casual mass parallel computing
PPTX
Nanocloud cloud scale jvm
PDF
Java GC tuning and monitoring (by Alexander Ashitkin)
PDF
Garbage collection in JVM
PDF
Virtualizing Java in Java (jug.ru)
PDF
Filtering 100M objects in Coherence cache. What can go wrong?
PDF
Cборка мусора в Java без пауз (HighLoad++ 2013)
PDF
JIT-компиляция в виртуальной машине Java (HighLoad++ 2013)
PDF
Performance Test Driven Development (CEE SERC 2013 Moscow)
PDF
Performance Test Driven Development with Oracle Coherence
PPTX
Борьба с GС паузами в JVM
PPTX
Распределённый кэш или хранилище данных. Что выбрать?
PPTX
Devirtualization of method calls
PPTX
Tech talk network - friend or foe
PDF
Database backed coherence cache
PDF
ORM and distributed caching
Распределённое нагрузочное тестирование на Java
Java black box profiling
Блеск и нищета распределённых кэшей
JIT compilation in modern platforms – challenges and solutions
Casual mass parallel computing
Nanocloud cloud scale jvm
Java GC tuning and monitoring (by Alexander Ashitkin)
Garbage collection in JVM
Virtualizing Java in Java (jug.ru)
Filtering 100M objects in Coherence cache. What can go wrong?
Cборка мусора в Java без пауз (HighLoad++ 2013)
JIT-компиляция в виртуальной машине Java (HighLoad++ 2013)
Performance Test Driven Development (CEE SERC 2013 Moscow)
Performance Test Driven Development with Oracle Coherence
Борьба с GС паузами в JVM
Распределённый кэш или хранилище данных. Что выбрать?
Devirtualization of method calls
Tech talk network - friend or foe
Database backed coherence cache
ORM and distributed caching

Recently uploaded (20)

PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Odoo Companies in India – Driving Business Transformation.pdf
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
medical staffing services at VALiNTRY
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Upgrade and Innovation Strategies for SAP ERP Customers
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
PDF
Digital Strategies for Manufacturing Companies
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PPTX
ISO 45001 Occupational Health and Safety Management System
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
System and Network Administration Chapter 2
PPTX
L1 - Introduction to python Backend.pptx
PPTX
Transform Your Business with a Software ERP System
PDF
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
PPTX
Operating system designcfffgfgggggggvggggggggg
Adobe Illustrator 28.6 Crack My Vision of Vector Design
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
2025 Textile ERP Trends: SAP, Odoo & Oracle
Odoo Companies in India – Driving Business Transformation.pdf
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
VVF-Customer-Presentation2025-Ver1.9.pptx
medical staffing services at VALiNTRY
How Creative Agencies Leverage Project Management Software.pdf
Upgrade and Innovation Strategies for SAP ERP Customers
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
SAP S4 Hana Brochure 3 (PTS SYSTEMS AND SOLUTIONS)
Digital Strategies for Manufacturing Companies
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
ISO 45001 Occupational Health and Safety Management System
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
System and Network Administration Chapter 2
L1 - Introduction to python Backend.pptx
Transform Your Business with a Software ERP System
Flood Susceptibility Mapping Using Image-Based 2D-CNN Deep Learnin. Overview ...
Operating system designcfffgfgggggggvggggggggg

DIY Java Profiler

  • 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
  • 4. SJK: ttop 2014-10-01T19:27:22.825+0400 Process summary process cpu=101.80% application cpu=100.50% (user=86.21% sys=14.29%) other: cpu=1.30% GC cpu=0.00% (young=0.00%, old=0.00%) heap allocation rate 123mb/s Available via PerfCounters [000037] user=83.66% sys=14.02% alloc= 121mb/s - Proxy:ExtendTcpProxyService1:TcpAcceptor:TcpProcessor [000075] user= 0.97% sys= 0.08% alloc= 411kb/s - RMI TCP Connection(35)-10.139.200.51 [000029] user= 0.61% sys=-0.00% alloc= 697kb/s - Invocation:Management [000073] user= 0.49% sys=-0.01% alloc= 343kb/s - RMI TCP Connection(33)-10.128.46.114 [000023] user= 0.24% sys=-0.01% alloc= 10kb/s - PacketPublisher [000022] user= 0.00% sys= 0.10% alloc= 11kb/s - PacketReceiver [000072] user= 0.00% sys= 0.07% alloc= 22kb/s - RMI TCP Connection(31)-10.139.207.76 [000056] user= 0.00% sys= 0.05% alloc= 20kb/s - RMI TCP Connection(25)-10.139.207.76 [000026] user= 0.12% sys=-0.07% alloc= 2217b/s - Cluster|Member(Id=18, Timestamp=2014-10-01 15:58:3... [000076] user= 0.00% sys= 0.04% alloc= 6657b/s - JMX server connection timeout 76 [000021] user= 0.00% sys= 0.03% alloc= 526b/s - PacketListener1P [000034] user= 0.00% sys= 0.02% alloc= 1537b/s - Proxy:ExtendTcpProxyService1 [000049] user= 0.00% sys= 0.02% alloc= 6011b/s - JMX server connection timeout 49 [000032] user= 0.00% sys= 0.01% alloc= 0b/s - DistributedCache https://github.com/aragozin/jvm-tools/blob/master/sjk-core/COMMANDS.md#ttop-command
  • 5. MBeans: memory • Memory geometry information • Collection count • Last collection details  for each collector
  • 6. SJK: GC [GC: Copy#1806 time: 7ms interval: 332ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-325397.59kb/s] Tenured Gen: 162185k+14k->162199k[max:477888k,rate:42.22kb/s] Survivor Space: 235k-13k->222k[max:23872k,rate:-41.93kb/s]] [GC: Copy#1807 time: 8ms interval: 338ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-319621.30kb/s] Tenured Gen: 162199k+219k->162418k[max:477888k,rate:648.30kb/s] Survivor Space: 222k-217k->4k[max:23872k,rate:-644.90kb/s]] [GC: Copy#1808 time: 7ms interval: 321ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-336548.29kb/s] Tenured Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 4k-2k->1k[max:23872k,rate:-7.64kb/s]] [GC: Copy#1809 time: 7ms interval: 321ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-336548.29kb/s] Tenured Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 1k+0k->1k[max:23872k,rate:0.24kb/s]] [GC: Copy#1810 time: 4ms interval: 700ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-154331.43kb/s] Tenured Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 1k+288k->290k[max:23872k,rate:412.00kb/s]] [GC: Copy#1811 time: 5ms interval: 311ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-347369.77kb/s] Tenured Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 290k-155k->135k[max:23872k,rate:-498.52kb/s]] [GC: Copy#1812 time: 3ms interval: 340ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-317741.18kb/s] Tenured Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 135k-2k->132k[max:23872k,rate:-6.14kb/s]] [GC: Copy#1813 time: 6ms interval: 325ms mem: Eden Space: 108032k-108032k->0k[max:191168k,rate:-332406.15kb/s] Tenured Gen: 162418k+0k->162418k[max:477888k,rate:0.00kb/s] Survivor Space: 132k+0k->133k[max:23872k,rate:0.65kb/s]] Total Copy[ collections: 28 | avg: 0.0065 secs | total: 0.2 secs ] MarkSweepCompact[ collections: 0 | avg: NaN secs | total: 0.0 secs ] https://github.com/aragozin/jvm-tools/blob/master/sjk-core/COMMANDS.md#gc-command
  • 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
  • 9. SJK: hh --dead 1: 19117456 2038375696 [C 2: 9543865 441272568 [Ljava.lang.Object; 3: 13519356 432619392 java.util.HashMap$Entry 4: 12558262 301398288 java.lang.String 5: 7193066 287722640 org.hibernate.engine.spi.CollectionKey 6: 619253 160678888 [I 7: 4710497 113051928 org.jboss.seam.international.Messages$1$1 8: 571327 100876880 [Ljava.util.HashMap$Entry; 9: 1436183 57447320 org.hibernate.event.spi.FlushEntityEvent 10: 1661932 53181824 java.util.Stack 11: 209899 52047904 [B 12: 1624200 51974400 org.hibernate.engine.internal.Cascade 13: 929354 44608992 java.util.HashMap 14: 1812762 43506288 org.hibernate.i.u.c.IdentityMap$IdentityMapEntry 15: 850157 34006280 java.util.TreeMap$Entry 16: 1044636 25071264 java.util.ArrayList 17: 1340986 23423328 [Ljava.lang.Class; 18: 710973 22751136 java.io.ObjectStreamClass$WeakClassKey 19: 885164 21243936 org.hibernate.event.internal.WrapVisitor 20: 885126 21243024 org.hibernate.event.internal.FlushVisitor ... Total 95197823 4793878008 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
  • 11. SJK: jps My favorite command > sjk jps -pd PID MAIN duser.dir XMaxHeapSize 90543 sjk-0.3.1-SNAPSHOT.jar /var/vas_sdk_test_server -XX:MaxHeapSize=32126271488 5315 WrapperSimpleApp /var/vas_sdk_test_server/vas-sdk-test-13030 -XX:MaxHeapSize=4294967296 11094 WrapperSimpleApp /var/vas_sdk_test_server/vas-sdk-test-13020 -XX:MaxHeapSize=4294967296 993 Main /var/gedoms-uat/private/rtdb_1 -XX:MaxHeapSize=12884901888 56603 AxiomApplication /var/gedoms-uat/private/gedoms_1 -XX:MaxHeapSize=2147483648 24046 WrapperSimpleApp /var/sonar/sonar-3.6.2/bin/linux-x86-64 -XX:MaxHeapSize=536870912 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
  • 14. Stack Trace Sampling 100.00% 90.00% 80.00% 70.00% 60.00% 50.00% 40.00% 30.00% 20.00% 10.00% 0.00% Base Other DefaultServlet.doGet LifeCycleImpl (render) LifeCycleImpl (execute) Business logic Seam interceptor (lock contention) Seam interceptor (inject/outject) Resource bundle (getObject) Resource bundle (missing) Facelet compile Hibernate (rest) Hibernate (autoFlush) JDBC
  • 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
  • 17. BTrace Visit https://kenai.com/projects/btrace Instrumentation profiling  Inject code snippets written in Java  CLI or Java API to use  Extendible
  • 18. BTrace @OnMethod(clazz = "org.jboss.seam.Component", method = "/(inject)/") void entryByMethod2(@ProbeClassName String className, @ProbeMethodName String methodName, @Self Object component) { if (component != null) { Field nameField = field(classOf(component), "name", true); if (nameField != null) { String name = (String)get(nameField, component); Profiling.recordEntry(bench, concat("org.jboss.seam.Component.", concat(methodName, concat(":", name)))); } } } @OnMethod(clazz = "org.jboss.seam.Component", method = "/(inject)/", location = @Location(value = Kind.RETURN)) void exitByMthd2(@ProbeClassName String className, @ProbeMethodName String methodName, @Self Object component, @Duration long duration) { if (component != null) { Field nameField = field(classOf(component), "name", true); if (nameField != null) { String name = (String)get(nameField, component); Profiling.recordExit(bench, concat("org.jboss.seam.Component.", concat(methodName, concat(":", name))), duration); } } }
  • 19. Thank you Alexey Ragozin http://blog.ragozin.info - my articles http://aragozin.timepad.ru - IT community events in Moscow alexey.ragozin@gmail.com