Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to analyse Dalvik GC behaviour?

I am developing an application on Android. It is a long running application that continuously processes sensor data. While running the application I see a lot of GC messages in the logcat; about one every second.

This is most probably because of objects being created and immediately de-referenced in a loop.

How do I find which objects are being created and released immediately?

All the java heap analysis tools that I have tried(*) are bothered with the counts and sizes of objects on the heap. While they are useful, I am more interested in finding out the site where temporary short-lived objects get created the most.

(*) I tried jcat and Eclipse MAT. I couldn't get hat to work on the Android heap-dumps; it complained of an unsupported dump file version.

like image 929
HRJ Avatar asked Dec 27 '10 11:12

HRJ


2 Answers

How do I find which objects are being created and released immediately?

Step #1: Temporarily modify your code (or create a scrap project with the relevant portions of your code), where you can click a button or something to run exactly once through the sensor processing logic.

Step #2: Get into DDMS (standalone or the Eclipse perspective).

Step #3: Choose your emulator, then click on the Allocation Tracker tab

Step #4: Get your application to the point where it is waiting for the button click from step #1, then click on Start Tracking in the DDMS Allocation Tracker tab.

Step #4: Click the button, and when the sensor processing pass is complete, click Get Allocations on the DDMS Allocation Tracker tab.

This will tell you what was allocated during that portion of your code. It does not tell you what is "released", because that's indeterminate until a GC cycle runs.

EDIT

I am not certain, but startAllocCounting() on the android.os.Debug class may have the same effect as clicking the Start Tracking button. If so, you could simply instrument your code to track allocations over one pass of your loop, rather than mess around with the code changes I outlined above.

And, FWIW, here is a short technical article on DDMS and allocation tracking.

like image 167
CommonsWare Avatar answered Oct 28 '22 02:10

CommonsWare


I think you need to give allocation tracker a try :)

(in your /tools dir)

http://developer.android.com/resources/articles/track-mem.html

like image 22
Pedro Loureiro Avatar answered Oct 28 '22 00:10

Pedro Loureiro