[英]How to analyse Dalvik GC behaviour?
I am developing an application on Android. 我正在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;
在运行该应用程序时,我在logcat中看到很多GC消息。 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. 我尝试过的所有Java堆分析工具(*)都被堆上对象的数量和大小所困扰。 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
. (*)我尝试了
jcat
和Eclipse MAT
。 I couldn't get hat
to work on the Android heap-dumps; 我不能让
hat
在Android堆转储工作; it complained of an unsupported dump file version. 它抱怨不支持的转储文件版本。
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. 步骤#1:临时修改代码(或使用代码的相关部分创建剪贴项目),您可以在其中单击按钮或执行某种操作,以完全通过传感器处理逻辑运行一次。
Step #2: Get into DDMS (standalone or the Eclipse perspective). 步骤2:进入DDMS(独立或Eclipse透视图)。
Step #3: Choose your emulator, then click on the Allocation Tracker tab 步骤#3:选择您的模拟器,然后单击分配跟踪器选项卡
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. 步骤4:将您的应用程序移至等待步骤1中单击按钮的位置,然后在DDMS分配跟踪器选项卡中单击开始跟踪。
Step #4: Click the button, and when the sensor processing pass is complete, click Get Allocations on the DDMS Allocation Tracker tab. 步骤#4:单击按钮,并在传感器处理通过完成后,单击DDMS分配跟踪器选项卡上的获取分配。
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.
它不会告诉您“释放”了什么,因为在GC循环运行之前这是不确定的。
EDIT 编辑
I am not certain, but startAllocCounting()
on the android.os.Debug
class may have the same effect as clicking the Start Tracking button. 我不确定,但是
android.os.Debug
类上的startAllocCounting()
可能与单击“开始跟踪”按钮具有相同的效果。 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. 而且,FWIW, 这是一篇有关DDMS和分配跟踪的简短技术文章 。
I think you need to give allocation tracker a try :) 我认为您需要尝试一下分配跟踪器:)
(in your /tools dir) (在您的/ tools目录中)
http://developer.android.com/resources/articles/track-mem.html http://developer.android.com/resources/articles/track-mem.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.