Search code examples
xamarinxamarin.formsxamarin.androidmono

Xamarin Android no longer printing MONO GC log messages


I have a Xamarin.Forms app that runs on Android, which has been in development for several years. Until recently, when running the app I would see MONO GC messages whenever a garbage collection occurred, similar to the following:

04-11 16:46:22.658 D/Mono    (14892): GC_BRIDGE waiting for bridge processing to finish
04-11 16:46:22.661 D/Mono    (14892): GC_TAR_BRIDGE bridges 424 objects 2303 colors 445 ignored 814 sccs 424 xref 150 cache 0/0 setup 0.16ms tarjan 2.39ms scc-setup 0.20ms gather-xref 0.06ms xref-setup 0.02ms cleanup 0.31ms
04-11 16:46:22.661 D/Mono    (14892): GC_BRIDGE: Complete, was running for 49.28ms
04-11 16:46:22.661 D/Mono    (14892): GC_MAJOR: (LOS overflow) time 27.89ms, stw 29.64ms los size: 2048K in use: 467K
04-11 16:46:22.661 D/Mono    (14892): GC_MAJOR_SWEEP: major size: 3936K in use: 2558K

But now when I run the app I do NOT see any of these types of messages when a GC is performed. I see output from ART, such as:

[art] Starting a blocking GC Explicit
[art] Explicit concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 24% free, 1693KB/2MB, paused 712us total 30.887ms

When I use the environment.txt file to configure more verbose logging (e.g. MONO_LOG_LEVEL=info) then I get one additional line of output from MONO like:

[monodroid-gc] GC cleanup summary: 25 objects tested - resurrecting 25.

But this is not really useful to me. I want to see the information from GC_BRIDGE, GC_MAJOR, and GC_MAJOR_SWEEP. I have searched and searched and cannot find anyone else reporting this issue, but it seems that something changed in Xamarin.Android at some point.


Solution

  • It turns out that Mono DID turn off GC messages as the default. See this issue I posted on Github for details: https://github.com/dotnet/android/issues/6483

    The resolution is to use the following adb command to reenable the log messages:

    $ adb shell setprop debug.mono.log default,mono_log_level=info,mono_log_mask=gc
    

    Note that this command needs to be sent before the application is started.

    Note that you can also set these environment variables using an environment.txt file that is compiled with the application.