Your SlideShare is downloading. ×
Tuning Android Applications (Part One)
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Introducing the official SlideShare app

Stunning, full-screen experience for iPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Tuning Android Applications (Part One)

1,892
views

Published on

From th

From th

Published in: Technology

0 Comments
5 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,892
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
74
Comments
0
Likes
5
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Tuning Android Applications Copyright © 2011 CommonsWare, LLC
  • 2. What Ill Be Yammering About● Now – Traceview – MAT● After the Keynote – Battery and Bandwidth – Top Ten Tuning Tips Copyright © 2011 CommonsWare, LLC
  • 3. Traceview Copyright © 2011 CommonsWare, LLC
  • 4. Two Types of CPU Problems● Generally slow – Foreground – Background● UI “janky” (sluggish, jerky, non-responsive) – Work being done on the main application thread that perhaps should not be Copyright © 2011 CommonsWare, LLC
  • 5. Finding Your CPU Problems● StrictMode – Reports problems with main application thread● Roll-Your-Own Timing – E.g., TimingLogger● Traceview – Analyze method traces collected from VM – Shows you where all the time goes Copyright © 2011 CommonsWare, LLC
  • 6. Collecting Trace Data● Start/Stop from DDMS – Choose your process – Toggle toolbar button● Start/Stop from Java – android.os.Debug – startMethodTracing() – stopMethodTracing() Copyright © 2011 CommonsWare, LLC
  • 7. Loading Traceview● DDMS in Eclipse – Stopping collection auto-loads Traceview● Standalone DDMS – Stopping collection auto-loads standalone Traceview (Android 2.2+)● Trace-on-External-Storage – Import into Eclipse – Run traceview from command line Copyright © 2011 CommonsWare, LLC
  • 8. The Traceview Window● Top = Timeline – Rows = threads – Shows which threads were active at which times during test period● Bottom = CPU Consumers – Call tree of methods, showing which methods are consuming what amount of time, calls – Color coding matches timeline Copyright © 2011 CommonsWare, LLC
  • 9. Finding Hot Spots● Sort table – Exclusive = time taken up just in this method – Inclusive = time taken up in method and any methods it invokes (tree)● Find your code – Appearing in left column – In “parents” of other things consuming lots of time Copyright © 2011 CommonsWare, LLC
  • 10. Limitations● Disables JIT – Result: all Java code slower than normal● Does Not Profile Native Code – Result: native code a “black box”● Overall Result: Absolute Times Inaccurate – Looking for relative times compared to other Java code Copyright © 2011 CommonsWare, LLC
  • 11. Memory Analysis with MAT Copyright © 2011 CommonsWare, LLC
  • 12. Two Types of Memory Issues● Running out of heap – OutOfMemoryError● Running out of stack – StackOverflowError – If stack trace shows mostly Android UI rendering code, use Hierarchy View to identify deepest portions of view hierachy, try to eliminate layers Copyright © 2011 CommonsWare, LLC
  • 13. Finding Your Heap Problems● Allocation Tracking – Through DDMS, records all allocations ● Exception: primitive arrays – See who allocates what, try to figure out why● Memory Analyzer (MAT) – Examine heap dump – Find out what is not getting garbage collected – Find out how many objects exist, sizes Copyright © 2011 CommonsWare, LLC
  • 14. Collecting Heap Dumps● From DDMS – Select your process – Click toolbar button● From Java – android.os.Debug – dumpHprofData() Copyright © 2011 CommonsWare, LLC
  • 15. Loading MAT● DDMS/Eclipse – Dump automatically loaded into MAT● Standalone DDMS – Run hprof-conv on HPROF file, then open in MAT● Java – Copy file from emulator, run hprof-conv, open Copyright © 2011 CommonsWare, LLC
  • 16. Finding Your Leaks● Completely Closed Application – All activities destroyed via BACK (or equivalent) – In theory, none of your objects should appear – Open the Histogram – Enter package in “Regex” (com.yourfirm.*) – See what crops up ● “Merge Shortest Path to GC Roots” context menu, excluding weak references, to find out what is holding these Copyright © 2011 CommonsWare, LLC things
  • 17. Finding Where The Heap Went● Live Application – Finding out where all the RAM is going – Back in Histogram, sort by # of objects – Looking for unusual stuff with lots of objects ● Bitmaps ● Your objects ● Objects from third-party JAR Copyright © 2011 CommonsWare, LLC
  • 18. Finding Where The Heap Went● Live Application – Bring up the Dominator Tree – Sort by shallow heap (objects own memory) or retained heap (memory object is responsible for) – Again, hunt for unusual stuff with lots of heap Copyright © 2011 CommonsWare, LLC
  • 19. Limitations● Only Tracks Bitmaps on Honeycomb – Previously was “native” memory, counted against heap but not visible to MAT – Recommendation ● Focus MAT use on Honeycomb ● Secondary usage on earlier OS levels Copyright © 2011 CommonsWare, LLC