0

I wonder how can I determine the heap base address and heap size,

I would like to be able to dump my application heap,

Is there any way to do it ?

Plus when I am trying to read the process memory map via /proc/pid/maps, I don't see the [heap] section, why ?

Does the DVM allocate anonymous regions using mmap ?

If yes how can I track them ?

user3498424
  • 47
  • 1
  • 6
  • You can dump the app's managed heap with the built-in hprof tools (e.g. from DDMS). Some technical details about the Dalvik heap can be gleaned from http://stackoverflow.com/questions/21049715/do-dalvik-vm-processes-release-system-ram/21051382#21051382 . – fadden Apr 06 '14 at 22:10

2 Answers2

0

I wonder how can I determine the heap base address and heap size,

I would like to be able to dump my application heap,

Is there any way to do it ?

public static void logHeap() {
                Double allocated = new Double(Debug.getNativeHeapAllocatedSize())/new Double((1048576));
                Double available = new Double(Debug.getNativeHeapSize())/1048576.0;
                Double free = new Double(Debug.getNativeHeapFreeSize())/1048576.0;
                DecimalFormat df = new DecimalFormat();
                df.setMaximumFractionDigits(2);
                df.setMinimumFractionDigits(2);

                Log.d("tag", "debug. =================================");
                Log.d("tag", "debug.heap native: allocated " + df.format(allocated) + "MB of " + df.format(available) + "MB (" + df.format(free) + "MB free)");
                Log.d("tag", "debug.memory: allocated: " + df.format(new Double(Runtime.getRuntime().totalMemory()/1048576)) + "MB of " + df.format(new Double(Runtime.getRuntime().maxMemory()/1048576))+ "MB (" + df.format(new Double(Runtime.getRuntime().freeMemory()/1048576)) +"MB free)");
            }

Does the DVM allocate anonymous regions using mmap ?

If yes how can I track them ?

read https://source.android.com/devices/tech/dalvik/index.html

Matej Špilár
  • 2,617
  • 3
  • 15
  • 28
  • Hi Can you please give more details about the logHeap() ? What are the hard-coded number, and how can I extract heap base and heap size? – user3498424 Apr 06 '14 at 19:31
  • its to much to expleain in comment ... please read this http://stackoverflow.com/questions/2298208/how-to-discover-memory-usage-of-my-application-in-android – Matej Špilár Apr 06 '14 at 19:34
  • still I don't understand how can I get the heap base address, is the heap contiguous in memory ? – user3498424 Apr 07 '14 at 16:32
  • If you want to walk the heap, you will need to understand the heap's structure. To do that, you need to read and understand the relevant Dalvik source code. If you do that, you will see how the heap is allocated and how mspaces are used. Code exists in the VM to walk the heap and emit the details for the hprof dump; just follow that. And understand that it could all change when a new version of Android is released. – fadden Apr 07 '14 at 17:00
0

In linux API, you can use showmap to dump the heap size information, and the section is /ashmem/dalvik-heap . And the Android DDMS gives us two tools for analysis the Java heap and Native heap. Java Heap is Android Hprof, and the native heap is the native heap analysis.

QJGui
  • 907
  • 8
  • 10