开发者

"Live" memory analysis tool for Android

开发者 https://www.devze.com 2023-03-15 16:44 出处:网络
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开发者_Python百科 (which is great), but I wo

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开发者_Python百科 (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.

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.


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.


More information from this post on milk.com:

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:

Get a command shell on the device:

$ adb shell

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

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

# kill -10 <pid>

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.

Next:

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

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

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

You now have the hprof dump in dump.hprof.

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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消