-
Notifications
You must be signed in to change notification settings - Fork 528
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a target to run application with logging #8324
Conversation
We are frequently faced with the need to look at some detailed information optionally logged by our runtime (as well as by the MonoVM runtime in dotnet) and in order to obtain the necessary data, we ask our users to perform a series of steps on command line. This is a task we can easily wrap in a nice target, so that instead of having to type 5 lines of commands the user invokes a single command which will do the rest for them: dotnet build -t:RunWithLogging The above command will set the `debug.mono.log` property to the desired value, increase logcat buffer, clear the buffer, start the application waiting for it to be fully started, then pause for 1s and dump the logcat buffer to a file. Optionally, the `$(_RunLogVerbose)` property can be set to `true` in order to log verbose MonoVM data and the `$(_RunLogFilePath)` can be set to a logcat output file path (defaults to `$(IntermediateOutputPath)/logcat.txt`)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall the code changes look good to me if CI is green. 👍
For a new public target, I think we usually document in here how to use it:
<PropertyGroup> | ||
<_MonoLog>default,assembly,timing=bare</_MonoLog> | ||
<_MonoLog Condition=" '$(_RunLogVerbose)' != 'false' ">$(_MonoLog),mono_log_level=debug,mono_log_mask=all</_MonoLog> | ||
<_SleepTime>1000</_SleepTime> <!-- milliseconds --> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we make this a public-facing MSBuild property? So, customers could pass -p:Duration=10000
? I could see that an app might take a few seconds before it crashes, and this would be helpful to grab the log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea, however I think Duration
is too generic a name. Will think of something.
I added the docs to https://github.com/xamarin/xamarin-android/blob/main/Documentation/workflow/DevelopmentTips.md as it seemed to be more contextually relevant there. |
You might put it in both docs, but https://learn.microsoft.com/en-us/xamarin/android/deploy-test/building-apps/build-targets |
Properties which affect how the target works: | ||
|
||
* `/p:RunLogVerbose=true` enables even more verbose logging from MonoVM | ||
* `/p:RunLogDelay=X` where `X` should be replaced with time in milliseconds to wait before writing the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RunLogDelayMS
or RunLogDelayInMS
might be a nicer UX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great.
I do wonder if we should add a unit test to the On Device Tests to check that this target runs and produces a log file... just in case something breaks it in the future.
It might not be needed though.
The commands it executes are pretty basic, if they break then we're probably going to notice similar issues in all the on-device tests, since they also execute a set of similar |
I think the MAUI integration test failures can be ignored, they are workload installation issues, not related to this PR. |
* main: [Xamarin.Android.Build.Tasks] Add `RunWithLogging` target (dotnet#8324) [Xamarin.Android.Build.Tasks] AndroidJavaSource refs dependent jars (dotnet#8194) Bump to xamarin/Java.Interop/main@75d8221 (dotnet#8336) Bump NDK to r26 (dotnet#8213)
We are frequently faced with the need to look at some detailed
information optionally logged by our runtime (as well as by the MonoVM
runtime in dotnet) and in order to obtain the necessary data, we ask our
users to perform a series of steps on command line.
This is a task we can easily wrap in a nice target, so that instead of
having to type 5 lines of commands the user invokes a single command
which will do the rest for them:
The above command will set the
debug.mono.log
property to the desiredvalue, increase logcat buffer, clear the buffer, start the application
waiting for it to be fully started, then pause for 1s and dump the
logcat buffer to a file.
Optionally, the
$(_RunLogVerbose)
property can be set totrue
inorder to log verbose MonoVM data and the
$(_RunLogFilePath)
can be setto a logcat output file path (defaults to
$(IntermediateOutputPath)/logcat.txt
)