"现场"内存分析工具为Android [英] "Live" memory analysis tool for Android

查看:137
本文介绍了"现场"内存分析工具为Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个活的内存分析器工具(类似仪器的X code)为Android?大多数搜索内存分析,使我的内存分析工具(这是伟大的),但我非常AP preciate可以的生命周期中动态地告诉我哪些类消费(和释放)内存的工具我应用,因为它正在执行

Is there a "live" memory profiler tool (similar to Instruments in XCode) for Android? Most searches for memory profiling, leads me to Memory Analyzer Tool (which is great), but I would very much appreciate a tool which can dynamically show me which classes consume (and release) memory during the life-cycle of my application, as it is executing.

注:我的不可以寻找一个内存分析工具为Android(内存分析器工具的工作对我非常好)。我曾经遇到过的所有方法/工具,采取堆的快照,并将其保存到一个文件中。我要寻找一个工具,它提供哪些部分堆正在使用的各种对象的实时计数器/更新,这是更新的第二/亚秒级的基础。这是可能的,这可能是不可能与Android。但是,我还没有找到一个明确的答复拉上。

Note: I am not looking for a memory profiling tool for Android (Memory Analyzer Tools works very well for me). All the methods/tools I have encountered, take a snapshot of the heap and save it to a file. I am looking for a tool which provides a live counter/update on what portion of the heap is being used by various objects, and this is updated on a second/sub-second basis. It is possible that this might not be possible with Android. However, I have not found a definite answer one way or another.

推荐答案

看看这个视频这里在周围的35分钟里,他们展示如何分析你的应用程序,不知道你是否能做到这一点'活'寿。

Take a look at this video here at around 35mins in they show how to profile your app, not sure if you can do it 'live' tho.

更多信息上milk.com :

因为没有试过Android 1.6及不知道你是否能做到这一点活,但你曾经是能够通过生成堆数据:

Haven't tried this since android 1.6 and not sure if you could do it live but you used to be able to generate heap data by:

获取命令shell设备上:

Get a command shell on the device:

$ adb shell

您可以验证你正在运行root的id命令。响应应该是这样的uid = 0(根)GID = 0(根)。如果没有,键入su,然后重试。如果苏失败,你的运气了。

You can verify that you're running as root with the id command. The response should look like uid=0(root) gid=0(root). If not, type su and try again. If su fails, you're out of luck.

接下来,确保目标目录存在:

Next, ensure the target directory exists:

# mkdir /data/misc
# chmod 777 /data/misc

使用PS或DDMS来确定应用程序的进程ID,然后发送一个SIGUSR1到目标进程:

Use ps or DDMS to determine the process ID of your application, then send a SIGUSR1 to the target process:

# kill -10 <pid>

该信号会导致GC,其次是堆转储(是完全准确的,但实际发生的同时,但是结果在堆转储反映后GC状态)。这可能需要几秒钟,所以你必须留意是否GC日志消息,知道什么时候完成。

The signal causes a GC, followed by the heap dump (to be completely accurate, they actually happen concurrently, but the results in the heap dump reflect the post-GC state). This can take a couple of seconds, so you have to watch for the GC log message to know when it's complete.

下一篇:

# ls /data/misc/heap-dump*
# exit

使用ls查看文件名,然后退出,退出设备命令shell。

Use ls to check the file names, then exit to quit the device command shell.

您应该看到两个输出文件,命名为/data/misc/heap-dump-BLAH-BLAH.hprof和.hprof头,其中BLAH是运行时生成的值,以确保文件名是唯一的。拉他们关闭设备,并删除该设备端副本:

You should see two output files, named /data/misc/heap-dump-BLAH-BLAH.hprof and .hprof-head, where BLAH is a runtime-generated value that ensures the filename is unique. Pull them off of the device and remove the device-side copy:

$ adb pull /data/misc/heap-dump-BLAH-BLAH.hprof tail.hprof
$ adb pull /data/misc/heap-dump-BLAH-BLAH.hprof-head head.hprof
$ adb shell rm /data/misc/heap-dump-BLAH-BLAH.hprof /data/misc/heap-dump-BLAH-BLAH.hprof-head

合并在一起并删除中间体:

Merge them together and remove the intermediates:

$ cat head.hprof tail.hprof > dump.hprof
$ rm head.hprof tail.hprof

您现在在dump.hprof的HPROF转储。

You now have the hprof dump in dump.hprof.

中的数据文件格式略有共同HPROF格式的增强,以及由于许可限制修改的帽子工具不能进行分配。 A转换工具,HPROF-CONV,可以用来从输出剥离Android的特定部分。该工具最早包含在1.5,但将与旧版本的Andr​​oid系统。

The data file format was augmented slightly from the common hprof format, and due to licensing restrictions the modified hat tool cannot be distributed. A conversion tool, hprof-conv, can be used to strip the Android-specific portions from the output. This tool was first included in 1.5, but will work with older versions of Android.

转换后输出应该与任何HPROF数据分析,包括与jHat,这是免费的在Sun的JDK和Eclipse MAT。

The converted output should work with any hprof data analyzer, including jhat, which is available for free in the Sun JDK, and Eclipse MAT.

这篇关于&QUOT;现场&QUOT;内存分析工具为Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆