Android的:如何分析本机堆转储?本机、Android、堆转储

2023-09-06 13:07:57 作者:18.舍弃执念

我已经使用命令 dumpheap -n&LT创建本机堆转储文件; <文件> 。该文件是人类可读的格式,但包含的太难理解的信息。我如何可以分析此文件,并获取有用的信息出来的吗?

I have created a native heap dump file by using the command dumpheap -n <PID> <file>. The file is in human readable format but contains information that is too hard to understand. How can I analyze this file and get useful information out of it?

函数地址使用功能名称的地方提供。在该文件的底部设置的映射。是否有任何工具来绘制这些并提供有意义的输出功能的/ lib目录的名称,而不是地址(负载库/函数的符号)。如果没有一个,那么如何DDMS做到这一点?还有如何加载,显示函数名的符号?

The function address are provided in the place of function names. The mapping is provided at the bottom of the file. Is there any tool to map these and provide meaningful output with function/lib names instead of addresses (load the symbols for libraries/functions). If there isn't one then how does ddms do this? Also how to load the symbols to display the function names?

有什么办法,我可以比较两个或更多的本机堆转储?

Is there any way that I can compare two or more native heap dumps?

这是我得到的转储堆文件看起来像这样

The dump heap file that I got looks like this

Android原生堆转储V1.0

Android Native Heap Dump v1.0

总内存:13863984 分配记录:3108

Total memory: 13863984 Allocation records: 3108

Z 1 SZ 8388608号码1胜40afcd1a 40afbc0e 40119d30 40795210 407a9bae 407941a0 4076c264 40770b6c 407a47f4 407a481e 40786d44 407a6da6 407a800e 407a58c4 407a820a 40798ac8 40115bb4 4011530c

z 1 sz 8388608 num 1 bt 40afcd1a 40afbc0e 40119d30 40795210 407a9bae 407941a0 4076c264 40770b6c 407a47f4 407a481e 40786d44 407a6da6 407a800e 407a58c4 407a820a 40798ac8 40115bb4 4011530c

Z 1 SZ 1516906号码1胜40afcd1a 40afbc0e 40119d30 400658fe 402563d8 5a400b10 5d6c3ed2 5d6c3efc 5d6c3f34 5d69d556 5d6a9de0 40794664 407aafa0 4076c264 40770b6c 407a47f4 407a481e 407af4a8 407aff8c 407678b0 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e 401de472 4005ddd2 40119ed4

z 1 sz 1516906 num 1 bt 40afcd1a 40afbc0e 40119d30 400658fe 402563d8 5a400b10 5d6c3ed2 5d6c3efc 5d6c3f34 5d69d556 5d6a9de0 40794664 407aafa0 4076c264 40770b6c 407a47f4 407a481e 407af4a8 407aff8c 407678b0 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e 401de472 4005ddd2 40119ed4

Z 1 SZ 262144 NUM 1胜40afcd1a 40afbc0e 40119d30 400658fe 40a14416 40a144e0 40a154a4 40a1570e 40a1d8cc 40a20d42 40a1a9e4 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 401f0c90 40762e34 40792086 4076c264 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e 401de472 4005ddd2

z 1 sz 262144 num 1 bt 40afcd1a 40afbc0e 40119d30 400658fe 40a14416 40a144e0 40a154a4 40a1570e 40a1d8cc 40a20d42 40a1a9e4 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 401f0c90 40762e34 40792086 4076c264 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e 401de472 4005ddd2

Z 1 SZ 262144 NUM 1胜40afcd1a 40afbc0e 40119d30 400658fe 40a14416 40a144e0 40a154a4 40a1570e 40a1d8cc 40a20d42 40a1a9e4 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 401f0c90 40762e34 40792086 4076c264 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e

z 1 sz 262144 num 1 bt 40afcd1a 40afbc0e 40119d30 400658fe 40a14416 40a144e0 40a154a4 40a1570e 40a1d8cc 40a20d42 40a1a9e4 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 401f0c90 40762e34 40792086 4076c264 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e

Z 1 SZ 65536 NUM 1胜40afcd1a 40afbc0e 40119d30 400658fe 40a14400 40a15714 40a1d8cc 40a20d42 40a1a9e4 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 401f0c90 40762e34 40792086 4076c264 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e 401de472 4005ddd2 40119ed4

z 1 sz 65536 num 1 bt 40afcd1a 40afbc0e 40119d30 400658fe 40a14400 40a15714 40a1d8cc 40a20d42 40a1a9e4 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 401f0c90 40762e34 40792086 4076c264 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e 401de472 4005ddd2 40119ed4

Z 1 SZ 65536 NUM 1胜40afcd1a 40afbc0e 40119d30 400658fe 40a14400 40a15714 40a1d8cc 40a20d42 40a1a9e4 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 401f0c90 40762e34 40792086 4076c264 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e 401de472 4005ddd2

z 1 sz 65536 num 1 bt 40afcd1a 40afbc0e 40119d30 400658fe 40a14400 40a15714 40a1d8cc 40a20d42 40a1a9e4 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 40a1aa26 401f0c90 40762e34 40792086 4076c264 40770b6c 407a4aba 407ac010 4076c264 40770b6c 407a47f4 4078e676 401dd98e 401de472 4005ddd2

什么是这些数字说明?

推荐答案

数据正在由 dumpNativeHeap()函数生成的 android_os_Debug.cpp 。每一项都是一个分配记录,其中包含:

The data is being generated by the dumpNativeHeap() function in android_os_Debug.cpp. Each entry is one allocation record, which contains:

在受精卵子标志:以Z 0 是指受精卵过程中进行配置, Z 1 意味着它发生在受精卵子(即叉后一个应用程序进程())。这个用于确定是否一个特定的分配可能多个进程之间凭借副本上写共用是很有用的。 分配的大小,以字节为单位。 分配的具有完全相同的尺寸和回溯数。 在回溯地址(最多32个)。 The "zygote child" flag: z 0 means the allocation was performed in the zygote process, z 1 means it happened in a child of zygote (i.e. an app process after the fork()). This is useful for determining whether a particular allocation might be shared between multiple processes by virtue of copy-on-write. The size of the allocation, in bytes. The number of allocations with the exact same size and backtrace. The backtrace addresses (up to 32).

该地址没有意义,没有复制的/ proc /&LT; PID&GT; /图来看看有什么二进制文件被定位在哪里,所以副本包括在结束。

The addresses aren't meaningful without a copy of /proc/<pid>/maps to see what binaries were mapped where, so a copy is included at the end.

有关转换二进制+地址符号的基本工具是addr2line.您需要从地址减去库的基址堆栈跟踪来获取库偏移。

The basic tool for converting binary + address to symbol is addr2line. You need to subtract the base address of the library from the address in the stack trace to get the library offset.

还有一个更简单的方法。是,用于生成这些堆转储同样的机制也可以用于饲料DDMS机堆跟踪。这提供了一个完整的用户界面浏览本机堆的内容。你可以找到关于它的更多信息here和here.

There's an easier way. The same mechanism that is used to generate these heap dumps can also be used to feed the DDMS Native Heap Tracker. This provides a full UI for browsing the contents of your native heap. You can find more information about it here and here.

FWIW,这里是做它的硬办法的一个例子。我甩的日历应用程序的堆,看到这一行:

FWIW, here's an example of doing it the "hard way". I dumped the heap of the Calendar app and saw this line:

z 1  sz    49152  num    1  bt b5aac102 b5aac2f6 b6f8599a b5a5e946 b5a3f268 b6f8d6a0 b6f8b83e

从地图条目相关的线路有:

The relevant lines from the maps entry are:

b59ea000-b5a92000 r-xp 00000000 b3:19 817        /system/lib/libdvm.so
b5a9f000-b5ae0000 r-xp 00000000 b3:19 782        /system/lib/libc_malloc_debug_leak.so
b6f78000-b6fbf000 r-xp 00000000 b3:19 780        /system/lib/libc.so

该库的基址必须先减去在回溯地址。你弄清楚它是什么库中通过查找映射条目包含回溯地址的地址范围。左工作到右(调用堆栈的顶部至底部):

The base address of the library must be subtracted from the address in the backtrace. You figure out what library it's in by finding the maps entry with an address range that contains the backtrace address. Working from left to right (top of the call stack to the bottom):

b5aac102 - b5a9f000 = d102
addr2line -C -f -e [...]/symbols/system/lib/libc_malloc_debug_leak.so d102
--> leak_malloc (malloc_debug_leak.cpp:283)

b5aac2f6...
--> leak_calloc (malloc_debug_leak.cpp:338)

b6f8599a - b6f78000 = d99a
addr2line -C -f -e [...]/symbols/system/lib/libc.so d99a
--> calloc (malloc_debug_common.cpp:231)

b5a5e946 - b59ea000 = 74946
addr2line -C -f -e [...]/symbols/system/lib/libdvm.so 74946
--> compilerThreadStartup (Compiler.cpp:434)

b5a3f268...
--> internalThreadStart(void*) (Thread.cpp:1752)

...等等。该跟踪对应于行的Dalvik / VM /编译器/ Compiler.cpp

pJitTable = (JitEntry*)
            calloc(gDvmJit.jitTableSize, sizeof(*pJitTable));
 
精彩推荐
图片推荐