Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Microsoft.Android.Runtime.NativeAOT] Parse debug.dotnet.log (#9824)
Context: https://github.com/dotnet/java-interop/blob/9dea87dc1f3052ed0f9499c9858b27c83e7d139e/samples/Hello-NativeAOTFromAndroid/README.md The NativeAOT sample and related `Microsoft.Android.Runtime.NativeAOT` assembly is based in part on the `Hello-NativeAOTFromAndroid` sample in dotnet/java-interop, which contains this comment about Logging: > The (very!) extensive logging around JNI Global and Local > references mean that this sample should not be used as-is for > startup timing comparison. …because `adb logcat` is absolutely *spammed* by LREF and GREF logs. The "solution" in .NET for Android "proper" is to use the `debug.mono.log` system property to control logging. By default, LREF and GREF logs are disabled, but can be enabled by setting the `debug.mono.log` system property property: adb shell setprop debug.mono.log gref # only grefs adb shell setprop debug.mono.log lref,gref # lrefs & grefs adb shell setprop debug.mono.log all # EVERYTHING Begin plumbing similar support for a new `debug.dotnet.log` system property into `JavaInteropRuntime` via a new `DiagnosticSettings` type. This allows us to e.g. have LREF and GREF logging *disabled by default*, allowing for (somewhat) more representative startup timing comparisons, while allowing these logs to be enabled when needed. adb shell setprop debug.dotnet.log gref # only grefs adb shell setprop debug.dotnet.log lref,gref # only grefs adb shell setprop debug.dotnet.log lref,gref # both, right now Additionally, `=PATH` can be appended to redirect gref or lref logs to the file `PATH`. Note that `PATH` must be writable by the app, and that the value of `debug.dotnet.log` must be shorter than 92 bytes: adb shell mkdir -p /sdcard/Documents/jonp adb shell chmod 777 /sdcard/Documents/jonp adb shell setprop debug.dotnet.log gref=/sdcard/Documents/jonp/jni.txt,lref=/sdcard/Documents/jonp/jni.txt Note that in the above example on a Pixel 8 with Android 15, `/sdcard/Documents/jonp/jni.txt` can only be written to *once*; subsequent attempts to write to the file will error out, so we'll fallback to writing to `adb logcat`: E NativeAot: Failed to open log file `/sdcard/Documents/jonp/jni.txt`: System.UnauthorizedAccessException: UnauthorizedAccess_IODenied_Path, /sdcard/Documents/jonp/jni.txt E NativeAot: ---> System.IO.IOException: Permission denied … D NativeAot:LREF: +l+ lrefc 1 handle 0x723ff2501d/L from thread ''(1) …
- Loading branch information