Skip to content

Commit

Permalink
Merge branch 'main' into xamarin-app-utils
Browse files Browse the repository at this point in the history
* main:
  [docs] how to get gc dumps w/ `dotnet-trace` (dotnet#7875)
  [Xamarin.Android.Build.Tasks] Fix AndroidPackagingOptionsExclude (dotnet#7903)
  Bump to dotnet/installer@c373093 8.0.100-preview.3.23170.5 (dotnet#7901)
  [Xamarin.Android.Build.Tasks] Updating NuGet packages does not update the app (dotnet#7892)
  [vs-workload] Remove @(MultiTargetPackNames) (dotnet#7894)
  • Loading branch information
grendello committed Mar 22, 2023
2 parents 480e22a + 7d97205 commit 80595d5
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 36 deletions.
80 changes: 80 additions & 0 deletions Documentation/guides/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,86 @@ And the output files should be found in the current directory. You can
use the `-o` switch if you would prefer to output them to a specific
directory.

## How to get GC memory dumps?

If running on desktop, you can use the `dotnet-gcdump` global tool.
This can be installed via:

```dotnetcli
$ dotnet tool install --global dotnet-gcdump
```

To use it, for example:

```sh
# `hw-readline` is a standard Hello World, with a `Console.ReadLine()` at the end
$ dotnet run --project hw-readline.csproj
Hello, World!
Press <ENTER> to continue

# Then from another shell...

# Determine which process ID to dump
$ ps | grep 'dotnet.*hw-re'
33972 ttys049 0:01.86 dotnet run --project hw-readline.csproj
33977 ttys050 0:00.00 grep dotnet.*hw-re

# Collect the GC info
$ dotnet gcdump collect --process-id 33972
Writing gcdump to '.../hw-readline/20230314_113922_33972.gcdump'...
Finished writing 5624131 bytes.
```
See the [`dotnet-gcdump` documentation][dotnet-gcdump]
for further details about its usage.

This will connect to a process and save a `*.gcdump` file. You can
open this file in Visual Studio on Windows, for example:

![Visual Studio GC Heap Dump](../images/VS-GC-Dump.png)

To get this data from an Android application, you need all the above
setup for `adb shell`, `dsrouter`, etc. except you need to change the
provider for `dotnet-trace`:

```sh
$ dotnet-trace collect --diagnostic-port /tmp/maui-app --providers Microsoft-DotNETRuntimeMonoProfiler:0xC900001:4
```

`0xC900001`, a bitmask, enables the following event types:

* `GCKeyword`
* `GCHeapCollectKeyword`
* `GCRootKeyword`

See the [`Microsoft-DotNETRuntimeMonoProfiler` event types][mono-events] for more info.

`:4` enables "Informational" verbosity, where the different logging
levels are described by [`dotnet-trace help` output][dotnet-trace-help].

This saves a `.nettrace` file with GC events that are not available
with the default provider.

To actually view this data, you'll have to use one of:

* https://github.com/lateralusX/diagnostics-nettrace-samples
* https://github.com/filipnavara/mono-gcdump

Using `mono-gcdump`:

```sh
$ dotnet run --project path/to/filipnavara/mono-gcdump/mono-gcdump.csproj -- convert foo.nettrace
```

This saves a `foo.gcdump` that you can open in Visual Studio.

See the [dotnet/runtime documentation][gc-dumps-on-mono] for
additional details.

[dotnet-gcdump]: https://learn.microsoft.com/dotnet/core/diagnostics/dotnet-gcdump
[mono-events]: https://github.com/dotnet/runtime/blob/c887c92d8af4ce65b19962b777f96ae8eb997a42/src/coreclr/vm/ClrEtwAll.man#L7433-L7468
[dotnet-trace-help]: https://github.com/dotnet/diagnostics/blob/6d755e8b5435b1380c118e9d81e075654b0330c9/documentation/dotnet-trace-instructions.md#dotnet-trace-help
[gc-dumps-on-mono]: https://github.com/dotnet/runtime/blob/728fd85bc7ad04f5a0ea2ad0d4d8afe371ff9b64/docs/design/mono/diagnostics-tracing.md#collect-gc-dumps-on-monovm

## How to `dotnet trace` our build?

Setting this up is easy, the main issue is there end up being
Expand Down
Binary file added Documentation/images/VS-GC-Dump.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion build-tools/create-packs/vs-workload.in.props
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@
</ShortNames>
<ComponentResources Include="android" Version="@WORKLOAD_VERSION@" Category=".NET" Title=".NET SDK for Android" Description=".NET SDK Workload for building Android applications."/>
<WorkloadPackages Include="$(NuGetPackagePath)\Microsoft.NET.Sdk.Android.Manifest*.nupkg" Version="@WORKLOAD_VERSION@" SupportsMachineArch="true" />
<MultiTargetPackNames Include="Microsoft.Android.Sdk" />
</ItemGroup>
</Project>
20 changes: 10 additions & 10 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="8.0.100-preview.3.23163.4">
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="8.0.100-preview.3.23170.5">
<Uri>https://github.com/dotnet/installer</Uri>
<Sha>cddf8e60e12dc484fd551d18e0c37bf1412e7ec2</Sha>
<Sha>c3730935bc3a06db5d51e8f3f36d88b8056a2cb5</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="8.0.0-preview.3.23159.4" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="8.0.0-preview.3.23168.2" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>a92ed6e2ce778c8b18dfa66f8f75368eca901f99</Sha>
<Sha>2aec3816f9bbc0eda3261daa335a05ea0df31b9c</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.App.Ref" Version="8.0.0-preview.3.23159.4" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Dependency Name="Microsoft.NETCore.App.Ref" Version="8.0.0-preview.3.23168.2" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Uri>https://github.com/dotnet/runtime</Uri>
<Sha>a92ed6e2ce778c8b18dfa66f8f75368eca901f99</Sha>
<Sha>2aec3816f9bbc0eda3261daa335a05ea0df31b9c</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100-preview.3" Version="8.0.0-preview.3.23156.1" CoherentParentDependency="Microsoft.NETCore.App.Ref">
<Dependency Name="Microsoft.NET.Workload.Emscripten.Current.Manifest-8.0.100.Transport" Version="8.0.0-preview.3.23167.1" CoherentParentDependency="Microsoft.NETCore.App.Ref">
<Uri>https://github.com/dotnet/emsdk</Uri>
<Sha>4c1f185a78249c6974c1f6c248dad189fe70497b</Sha>
<Sha>25d9f7a5e38a2d61b94ff341bc0d32135fcb15f9</Sha>
</Dependency>
<Dependency Name="Microsoft.DotNet.Cecil" Version="0.11.4-alpha.23156.1" CoherentParentDependency="Microsoft.NET.ILLink.Tasks">
<Dependency Name="Microsoft.DotNet.Cecil" Version="0.11.4-alpha.23163.1" CoherentParentDependency="Microsoft.NET.ILLink.Tasks">
<Uri>https://github.com/dotnet/cecil</Uri>
<Sha>b126490cd618d6066ed44e0369b4585e845cf9ab</Sha>
<Sha>f32e148d67dbf348685c3076a37e8bc68ab3a30f</Sha>
</Dependency>
</ProductDependencies>
<ToolsetDependencies>
Expand Down
12 changes: 6 additions & 6 deletions eng/Versions.props
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
<Project>
<!--Package versions-->
<PropertyGroup>
<MicrosoftDotnetSdkInternalPackageVersion>8.0.100-preview.3.23163.4</MicrosoftDotnetSdkInternalPackageVersion>
<MicrosoftNETILLinkTasksPackageVersion>8.0.0-preview.3.23159.4</MicrosoftNETILLinkTasksPackageVersion>
<MicrosoftNETCoreAppRefPackageVersion>8.0.0-preview.3.23159.4</MicrosoftNETCoreAppRefPackageVersion>
<MicrosoftDotnetSdkInternalPackageVersion>8.0.100-preview.3.23170.5</MicrosoftDotnetSdkInternalPackageVersion>
<MicrosoftNETILLinkTasksPackageVersion>8.0.0-preview.3.23168.2</MicrosoftNETILLinkTasksPackageVersion>
<MicrosoftNETCoreAppRefPackageVersion>8.0.0-preview.3.23168.2</MicrosoftNETCoreAppRefPackageVersion>
<MicrosoftDotNetApiCompatPackageVersion>7.0.0-beta.22103.1</MicrosoftDotNetApiCompatPackageVersion>
<MicrosoftDotNetBuildTasksFeedPackageVersion>7.0.0-beta.22103.1</MicrosoftDotNetBuildTasksFeedPackageVersion>
<MicrosoftNETWorkloadEmscriptenCurrentManifest80100preview3Version>8.0.0-preview.3.23156.1</MicrosoftNETWorkloadEmscriptenCurrentManifest80100preview3Version>
<MicrosoftNETWorkloadEmscriptenPackageVersion>$(MicrosoftNETWorkloadEmscriptenCurrentManifest80100preview3Version)</MicrosoftNETWorkloadEmscriptenPackageVersion>
<MicrosoftNETWorkloadEmscriptenCurrentManifest80100TransportVersion>8.0.0-preview.3.23167.1</MicrosoftNETWorkloadEmscriptenCurrentManifest80100TransportVersion>
<MicrosoftNETWorkloadEmscriptenPackageVersion>$(MicrosoftNETWorkloadEmscriptenCurrentManifest80100TransportVersion)</MicrosoftNETWorkloadEmscriptenPackageVersion>
<MicrosoftTemplateEngineTasksPackageVersion>7.0.100-rc.1.22410.7</MicrosoftTemplateEngineTasksPackageVersion>
<MicrosoftDotNetCecilPackageVersion>0.11.4-alpha.23156.1</MicrosoftDotNetCecilPackageVersion>
<MicrosoftDotNetCecilPackageVersion>0.11.4-alpha.23163.1</MicrosoftDotNetCecilPackageVersion>
<SystemIOHashingPackageVersion>$(MicrosoftNETCoreAppRefPackageVersion)</SystemIOHashingPackageVersion>
</PropertyGroup>
<PropertyGroup>
Expand Down
6 changes: 5 additions & 1 deletion src/Xamarin.Android.Build.Tasks/Tasks/BuildApk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,16 @@ void ExecuteWithAbi (string [] supportedAbis, string apkInputPath, string apkOut
continue;
}
// check for ignored items
bool exclude = false;
foreach (var pattern in excludePatterns) {
if(pattern.IsMatch (path)) {
Log.LogDebugMessage ($"Ignoring jar entry '{name}' from '{Path.GetFileName (jarFile)}'. Filename matched the exclude pattern '{pattern}'.");
continue;
exclude = true;
break;
}
}
if (exclude)
continue;
if (string.Compare (Path.GetFileName (name), "AndroidManifest.xml", StringComparison.OrdinalIgnoreCase) == 0) {
Log.LogDebugMessage ("Ignoring jar entry {0} from {1}: the same file already exists in the apk", name, Path.GetFileName (jarFile));
continue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -983,24 +983,13 @@ public void BuildAfterAddingNuget ()

//This test validates the _CleanIntermediateIfNeeded target
[Test]
[Category ("DotNetIgnore")] // Xamarin.Forms version is too old, uses net45 MSBuild tasks
[NonParallelizable]
public void BuildAfterUpgradingNuget ()
{
var proj = new XamarinAndroidApplicationProject ();
proj.MainActivity = proj.DefaultMainActivity.Replace ("public class MainActivity : Activity", "public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity");
proj.MainActivity = proj.DefaultMainActivity.Replace ("public class MainActivity : Activity", "public class MainActivity : AndroidX.AppCompat.App.AppCompatActivity");

proj.PackageReferences.Add (KnownPackages.XamarinForms_2_3_4_231);
proj.PackageReferences.Add (KnownPackages.AndroidSupportV4_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCoreUI_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportCoreUtils_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportDesign_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportFragment_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportMediaCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7AppCompat_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7CardView_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.SupportV7MediaRouter_27_0_2_1);
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat);

using (var b = CreateApkBuilder (Path.Combine ("temp", TestContext.CurrentContext.Test.Name))) {
//[TearDown] will still delete if test outcome successful, I need logs if assertions fail but build passes
Expand All @@ -1010,7 +999,7 @@ public void BuildAfterUpgradingNuget ()
if (Directory.Exists (projectDir))
Directory.Delete (projectDir, true);
Assert.IsTrue (b.Build (proj), "first build should have succeeded.");
Assert.IsFalse (b.Output.IsTargetSkipped ("_CleanIntermediateIfNeeded"), "`_CleanIntermediateIfNeeded` should have run!");
Assert.IsFalse (b.Output.IsTargetSkipped ("_CleanIntermediateIfNeeded"), "`_CleanIntermediateIfNeeded` should have run for the first build!");

var nugetStamp = Path.Combine (Root, b.ProjectDirectory, proj.IntermediateOutputPath, "stamp", "_CleanIntermediateIfNeeded.stamp");
FileAssert.Exists (nugetStamp, "`_CleanIntermediateIfNeeded` did not create stamp file!");
Expand All @@ -1019,12 +1008,12 @@ public void BuildAfterUpgradingNuget ()

proj.PackageReferences.Clear ();
//NOTE: we can get all the other dependencies transitively, yay!
proj.PackageReferences.Add (KnownPackages.XamarinForms_4_0_0_425677);
proj.PackageReferences.Add (KnownPackages.AndroidXAppCompat_1_6_0_1);
b.Save (proj, doNotCleanupOnUpdate: true);
Assert.IsTrue (b.Build (proj), "second build should have succeeded.");
Assert.IsFalse (b.Output.IsTargetSkipped ("_CleanIntermediateIfNeeded"), "`_CleanIntermediateIfNeeded` should have run!");
Assert.IsFalse (b.Output.IsTargetSkipped ("_CleanIntermediateIfNeeded"), "`_CleanIntermediateIfNeeded` should have run for the second build!");
FileAssert.Exists (nugetStamp, "`_CleanIntermediateIfNeeded` did not create stamp file!");
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, "Refreshing Xamarin.Android.Support.v7.AppCompat.dll"), "`ResolveLibraryProjectImports` should not skip `Xamarin.Android.Support.v7.AppCompat.dll`!");
Assert.IsTrue (StringAssertEx.ContainsText (b.LastBuildOutput, "Refreshing Xamarin.AndroidX.AppCompat.dll"), "`ResolveLibraryProjectImports` should not skip `Xamarin.AndroidX.AppCompat.dll`!");
FileAssert.Exists (build_props, "build.props should exist after second build.");

proj.MainActivity = proj.MainActivity.Replace ("clicks", "CLICKS");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ public void CheckExcludedFilesAreMissing ()
string expected = $"Ignoring jar entry 'kotlin/Error.kotlin_metadata'";
Assert.IsTrue (b.LastBuildOutput.ContainsText (expected), $"Error.kotlin_metadata should have been ignored.");
using (var zip = ZipHelper.OpenZip (apk)) {
Assert.IsFalse (zip.ContainsEntry ("Error.kotlin_metadata"), "Error.kotlin_metadata should have been ignored.");
Assert.IsFalse (zip.ContainsEntry ("kotlin/Error.kotlin_metadata"), "Error.kotlin_metadata should have been ignored.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ public static class KnownPackages
Version = "1.1.0.1",
TargetFramework = "MonoAndroid10",
};
public static Package AndroidXAppCompat_1_6_0_1 = new Package {
Id = "Xamarin.AndroidX.AppCompat",
Version = "1.6.0.1",
TargetFramework = "MonoAndroid10",
};
public static Package AndroidXBrowser = new Package {
Id = "Xamarin.AndroidX.Browser",
Version = "1.2.0.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,7 @@ because xbuild doesn't support framework reference assemblies.
<AndroidAddKeepAlives Condition="'$(AndroidAddKeepAlives)' == '' And '$(AndroidIncludeDebugSymbols)' != 'True'">True</AndroidAddKeepAlives>
<AndroidLinkResources Condition="'$(AndroidLinkResources)' == '' And '$(AndroidIncludeDebugSymbols)' != 'True'">False</AndroidLinkResources>
<_AndroidBuildPropertiesCacheExists Condition=" Exists('$(_AndroidBuildPropertiesCache)') ">True</_AndroidBuildPropertiesCacheExists>
<_NuGetAssetsFile Condition=" Exists('$(ProjectAssetsFile)') ">$(ProjectAssetsFile)</_NuGetAssetsFile>
<_NuGetAssetsFile Condition=" Exists('$(ProjectLockFile)') ">$(ProjectLockFile)</_NuGetAssetsFile>
<_NuGetAssetsFile Condition=" '$(_NuGetAssetsFile)' == '' and Exists('packages.config') ">packages.config</_NuGetAssetsFile>
<_NuGetAssetsTimestamp Condition=" '$(_NuGetAssetsFile)' != '' ">$([System.IO.File]::GetLastWriteTime('$(_NuGetAssetsFile)').Ticks)</_NuGetAssetsTimestamp>
Expand Down

0 comments on commit 80595d5

Please sign in to comment.