How to take heap snapshot of Xamarin.Android's Mono VM?

前端 未结 2 1511
忘了有多久
忘了有多久 2021-02-01 11:30

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 tr

2条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-02-01 11:54

    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 .

提交回复
热议问题