如何采取Xamarin.Android的Mono虚拟机的快照堆? [英] How to take heap snapshot of Xamarin.Android's Mono VM?

查看:399
本文介绍了如何采取Xamarin.Android的Mono虚拟机的快照堆?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我试图追查在Xam​​arin.Android应用程序的内存泄漏。使用DDMS和Eclipse内存分析器,我能看到哪些对象是活的。当试图跟踪拖住他们活着(GC根),我只看到本地堆栈(当然)。

我怎样才能把MONO虚拟机的快照堆?所以,我以后可以用它与IE浏览器heapshot工具?

还是有什么其他的技术,我可以用它来找到拖住对象活着Xamarin.Android的.NET的一部分?是否有可能做一些事情在程序内?

解决方案
  

我怎样才能把MONO虚拟机的快照堆?所以,我以后可以用它与IE浏览器heapshot工具?

现在可以得到单VM堆快照(与Xamarin.Android 4.8.2测试版进行测试,可能适用于之前的版本,您的情况可能有所不同)。这是一个四个步骤:

  1. 启用heapshot记录:

     亚行外壳setprop debug.mono.profile日志:heapshot
     

  2. 启动应用程序。 (如果你的应用程序是之前已经在运行(1),终止并重新启动它。)

    使用你的应用程序。

  3. 抓斗的轮廓数据为您的应用程序:

     亚行拉/data/data/@PACKAGE_NAME@/files/.__override__/profile.mlpd
     

    @PACKAGE_NAME @ 是应用程序的包名,例如:如果你的包是 FooBar.FooBar-Signed.apk ,然后 @PACKAGE_NAME @ FooBar.FooBar

  4. 分析数据:

      mprof-报告profile.mlpd
     

    mprof-报告附带单。

注意 profile.mlpd 的时候发生GC更新,所以你的可以的要调用 GC.Collect的()在一些众所周知的点,以确保 profile.mlpd 定期更新。

Background: I am trying to track down a memory leak in a Xamarin.Android app. Using DDMS and Eclipse Memory Profiler, I am able to see which objects are alive. When trying to track what is holding them alive (GC Root), I only see "Native stack" (of course).

How can I take a heap snapshot of the MONO VM? So I can later use it with i.e. heapshot tool?

Or are there ANY OTHER TECHNIQUES I can use to find what is holding an object alive in Xamarin.Android's .NET part? Is it possible to do something from within the program?

解决方案

How can I take a heap snapshot of the MONO VM? So I can later use it with i.e. heapshot tool?

It is now possible to get heap snapshots of the Mono VM (tested with Xamarin.Android 4.8.2 beta; may apply to prior releases, your mileage may vary). It's a four step process:

  1. Enable heapshot logging:

    adb shell setprop debug.mono.profile log:heapshot
    

  2. Start your app. (If your app was already running before (1), kill and restart it.)

    Use your app.

  3. Grab the profile data for your app:

    adb pull /data/data/@PACKAGE_NAME@/files/.__override__/profile.mlpd
    

    @PACKAGE_NAME@ is the package name of your application, e.g. if your package is FooBar.FooBar-Signed.apk, then @PACKAGE_NAME@ will be FooBar.FooBar.

  4. Analyze the data:

    mprof-report profile.mlpd
    

    mprof-report is included with Mono.

Note: profile.mlpd is only updated when a GC occurs, so you may want to call GC.Collect() at some "well known" point to ensure that profile.mlpd is regularly updated .

这篇关于如何采取Xamarin.Android的Mono虚拟机的快照堆?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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