using and extending memory analyzer into uncharted waters

18
Vladimir Pavlov Dimitar Giormov SAP Labs Bulgaria Using and Extending Memory Analyzer into Uncharted Waters Memory Analyzer

Upload: vladimir-pavlov

Post on 10-Jun-2015

5.131 views

Category:

Technology


0 download

DESCRIPTION

Presentation given at EclipseCon 2011 in Santa Clara, CA, about using and extending the Eclipse Memory Analyzer (MAT). Session abstract at http://www.eclipsecon.org/2011/sessions/?page=sessions&id=2184

TRANSCRIPT

Page 1: Using and Extending Memory Analyzer into Uncharted Waters

Vladimir PavlovDimitar GiormovSAP Labs Bulgaria

Using and Extending Memory Analyzer into Uncharted Waters

Memory Analyzer

Page 2: Using and Extending Memory Analyzer into Uncharted Waters

AGENDA

Introduction The Headaches Eclipse Memory Analyzer

Extending Eclipse Memory Analyzer API and Extension Points JRuby Case Android Apps Case

Q & A

© SAP 2010 / Page 2

Page 3: Using and Extending Memory Analyzer into Uncharted Waters

Memory leaks Hard to debug and find the root cause Eventually lead to OOM errors

Brings your system down Often not reproducible

Thread issues Deadlocks Exhausted threads Waiting for an external resource – e.g. DB connection

Application does not respond Whole system hangs

THE HEADACHES

© SAP 2010 / Page 3

Page 4: Using and Extending Memory Analyzer into Uncharted Waters

Eclipse Memory Analyzer (MAT) is… Java heap analyzer Helps find memory leaks and reduce memory consumption UI and programmatic access to data in the heap dumps Multi-Gigabyte Java Heap Dumps Are Nothing to Fear Now Soooo much faster than other tools, e.g. jhat Very little memory “overhead” for processing heap dumps (again – cf. jhat) Supports Sun, SAP, HP, IBM JDKs 1.4.2 and above Automatic problem recognition Could also process thread dumps and correlate data to provide additional details Initial contribution from SAP, joined by IBM Highly extensible

ECLIPSE MEMORY ANALYZER

© SAP 2010 / Page 4

Memory Analyzer

Page 5: Using and Extending Memory Analyzer into Uncharted Waters
Page 6: Using and Extending Memory Analyzer into Uncharted Waters

Why extend MAT? To save time doing the same thing repeatedly To help others use the same technique as you To do things not possible from the GUI To build in application or domain specific logic

How to extend MAT? MAT provides a set of Eclipse extension points User writes an extension plug-in MAT provides an API for reading data from a heap dump

EXTENDING MAT

© SAP 2010 / Page 6

Page 7: Using and Extending Memory Analyzer into Uncharted Waters

Isnapshot Represents a heap dump Methods for reading classes and objects, getting sizes, GC roots, referenced objects,

etc. Object model

IClass IObject

IInstance– IClassLoader

IArray– IPrimitiveArray– IObjectArray

PROGRAMMATIC ACCESS TO A SNAPSHOT

© SAP 2010 / Page 7

Page 8: Using and Extending Memory Analyzer into Uncharted Waters

Name Resolver Used to give meaningful descriptions of objects Similar to a toString() method Extension point: org.eclipse.mat.api.nameResolver

Query Used for exploring dumps or detailed analysis Result in the form of a table, tree, histogram, pie chart, free text... Integrated into MAT’s menus “Collaboration” of queries Extension point: org.eclipse.mat.report.query

Request Resolver Used to provide details about what a thread was doing Contributes to Leak Suspects report Extension point: org.eclipse.mat.api.requestResolver

EXTENSION POINTS

© SAP 2010 / Page 8

Page 9: Using and Extending Memory Analyzer into Uncharted Waters

Parser – for new heap dump types and VMs, such as for Jikes RVM Trigger Heap Dump – org.eclipse.mat.api.heapDumpProvider

For new VM types Reports – org.eclipse.mat.report.report

HTML results of queries – also used for batch mode Thread Resolver – additional thread data such as native stacks Ticket Resolver – can identify appropriate routing for problems

Based on classes and class loaders of problematic objects Rendering – org.eclipse.mat.api.renderer

Additional to HTML and CSV

Annotations used as filters and for configuration

EXTENSION POINTS (CONTD.)

© SAP 2010 / Page 9

Page 10: Using and Extending Memory Analyzer into Uncharted Waters

Ruby is… Dynamic scripting language Object-oriented Focus on simplicity and productivity Elegant syntax, natural to read and easy to write

JRuby is… 100% Java implementation of the Ruby programming language Interpreter running atop the JVM Generating Java bytecode (JIT compilation mode) Tight integration with Java

RUBY AND JRUBY

© SAP 2010 / Page 10

Page 11: Using and Extending Memory Analyzer into Uncharted Waters

Adding JRuby into the picture…

THE HEADACHES – AGGRAVATED

© SAP 2010 / Page 11

Page 12: Using and Extending Memory Analyzer into Uncharted Waters
Page 13: Using and Extending Memory Analyzer into Uncharted Waters

What were the goals Identify memory leaks (critical when talking about embedded systems due to

hardware restrictions) Filter memory usage by classes belonging to the users’ application Simpler workflow: developers start analyzing by classes they already know (not

Android system classes)

Why MAT was chosen The MAT perspective provides views to analyze application status, identify leaks,

and so on, given an HPROF file Reports are easy to navigate and provide information about retained heap It is Eclipse based Android supports the creation and extraction of HPROF files

MAT INTEGRATION WITH MOTODEV STUDIO

Page 14: Using and Extending Memory Analyzer into Uncharted Waters

Implemented an Extension Extension point used: org.eclipse.mat.ui Added a new page extending CompositeHeapEditorPane

Created MotodevPane based on OQLPane class

WORK DONE ON MAT

Page 15: Using and Extending Memory Analyzer into Uncharted Waters

The integration of MOTODEV Studio, Google DDMS and Eclipse MAT worked very well.

Used the org.eclipse.mat.ui extension point, which was well-documented.

It took about 2 weeks of one developer to study the project, implement and test the solution.

OVERALL EXPERIENCE

Page 16: Using and Extending Memory Analyzer into Uncharted Waters

Eclipse Memory Analyzer provides:

Powerful and efficient memory analysis features out-of-the-box

API for extracting data from a heap dump

Application or domain specific analysis can be added as extensions

SUMMARY

© SAP 2010 / Page 16

Page 17: Using and Extending Memory Analyzer into Uncharted Waters

RESOURCES

© SAP 2010 / Page 17

Page 18: Using and Extending Memory Analyzer into Uncharted Waters

Memory Analyzer

THANK YOU!

in: vpavlovt: @giormov