Skip to content

Commit

Permalink
Merge branch 'main' into native-profiling-and-debugging
Browse files Browse the repository at this point in the history
* main:
  Bump to mono/mono@6dd9def5 (dotnet#7574)
  Bump to dotnet/installer@296eeb3 8.0.100-alpha.1.22570.9 (dotnet#7571)
  [ci] Add API-33 to the nightly build (dotnet#7552)
  [docs] Fix typo in XA0134 (dotnet#7569)
  [docs] how to `dotnet trace` our build (dotnet#7573)
  [Xamarin.Android.Build.Tasks] Useful errors when using binutils (dotnet#7566)
  Bump SQLite to 3.40.0 (dotnet#7564)
  • Loading branch information
grendello committed Nov 22, 2022
2 parents 02f72bf + d61b32f commit 065faaf
Show file tree
Hide file tree
Showing 12 changed files with 109 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .external
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
xamarin/monodroid:main@8f925e3346c8aea63f3481a26c811374915b8d18
mono/mono:2020-02@a96bde9730e4c2244536ce5f4250e5e4f4e6780a
mono/mono:2020-02@6dd9def57ce969ca04a0ecd9ef72c0a8f069112d
2 changes: 1 addition & 1 deletion Documentation/guides/messages/xa0134.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ the Xamarin.Android build system for Debug builds.

## Solution

Please check that you to not have the 'android:debuggable' attribute set on the 'application' element in your 'AndroidManifest.xml'.
Please check that you do not have the 'android:debuggable' attribute set on the 'application' element in your 'AndroidManifest.xml'.
If you have a class that derives from 'Android.App.Application' and are using the '[Application]' make sure the
'Debuggable' property is not set at all as it will override the value for debug builds.
If neither of these solutions work please raise an issue at [https://github.com/xamarin/xamarin-android/issues/new/choose](https://github.com/xamarin/xamarin-android/issues/new/choose).
38 changes: 38 additions & 0 deletions Documentation/guides/tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,41 @@ Writing: hellomaui-app-trace.speedscope.json
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 `dotnet trace` our build?

Setting this up is easy, the main issue is there end up being
potentially *a lot* of threads (30-40) depending on the build.

Before getting started, I would recommend doing these things to make
the trace smaller and easier to understand:

* Set `$DOTNET_CLI_TELEMETRY_OPTOUT` to `1`, to avoid any dotnet CLI
telemetry in the trace.
* Profile a single `.csproj` build, not a `.sln`. This keeps
the build in-process.
* Always `restore` in a separate step and use `--no-restore` when you
trace. This avoids NuGet logic in the trace.
* Save a `.binlog`, so you can review that the build actually did what
you expected. `dotnet trace` tends to hide all the console output.

So, for example, to profile a build:

```dotnetcli
dotnet restore foo.csproj
dotnet trace collect --format speedscope -- dotnet build -bl --no-restore foo.csproj
```

This should result in `.speedscope` and `.nettrace` files in the
current directory.

If you wanted to profile deploy & app launch, do a build first:

```dotnetcli
dotnet build foo.csproj
dotnet trace collect --format speedscope -- dotnet build "-t:Run" -bl --no-restore foo.csproj
```

I found that `"` is necessary when `:` characters are present in the
command. This appears to be some kind of argument parsing issue with
`dotnet trace`.
4 changes: 4 additions & 0 deletions build-tools/automation/azure-pipelines-nightly.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ stages:
avdApiLevel: 31
avdAbi: x86_64
avdType: default
Android33-x86_64:
avdApiLevel: 33
avdAbi: x86_64
avdType: google_apis
pool:
vmImage: $(HostedMacImage)
workspace:
Expand Down
8 changes: 4 additions & 4 deletions eng/Version.Details.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<Dependencies>
<ProductDependencies>
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="8.0.100-alpha.1.22562.2">
<Dependency Name="Microsoft.Dotnet.Sdk.Internal" Version="8.0.100-alpha.1.22570.9">
<Uri>https://github.com/dotnet/installer</Uri>
<Sha>355d6643bdcd7e5a918550b67d12e35e65d8c646</Sha>
<Sha>296eeb3fa3d9b4fdf6552a1aa3ed07092e12f403</Sha>
</Dependency>
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="7.0.100-1.22560.1" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Dependency Name="Microsoft.NET.ILLink.Tasks" Version="7.0.100-1.22564.1" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Uri>https://github.com/dotnet/linker</Uri>
<Sha>9c993bf401377209cd7b4e84b60deab5e4f421a2</Sha>
<Sha>13b8d6d68a07a47e52e13705313bc32d5540edf5</Sha>
</Dependency>
<Dependency Name="Microsoft.NETCore.App.Ref" Version="8.0.0-alpha.1.22559.2" CoherentParentDependency="Microsoft.Dotnet.Sdk.Internal">
<Uri>https://github.com/dotnet/runtime</Uri>
Expand Down
4 changes: 2 additions & 2 deletions eng/Versions.props
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project>
<!--Package versions-->
<PropertyGroup>
<MicrosoftDotnetSdkInternalPackageVersion>8.0.100-alpha.1.22562.2</MicrosoftDotnetSdkInternalPackageVersion>
<MicrosoftNETILLinkTasksPackageVersion>7.0.100-1.22560.1</MicrosoftNETILLinkTasksPackageVersion>
<MicrosoftDotnetSdkInternalPackageVersion>8.0.100-alpha.1.22570.9</MicrosoftDotnetSdkInternalPackageVersion>
<MicrosoftNETILLinkTasksPackageVersion>7.0.100-1.22564.1</MicrosoftNETILLinkTasksPackageVersion>
<MicrosoftNETCoreAppRefPackageVersion>8.0.0-alpha.1.22559.2</MicrosoftNETCoreAppRefPackageVersion>
<MicrosoftDotNetApiCompatPackageVersion>7.0.0-beta.22103.1</MicrosoftDotNetApiCompatPackageVersion>
<MicrosoftDotNetBuildTasksFeedPackageVersion>7.0.0-beta.22103.1</MicrosoftDotNetBuildTasksFeedPackageVersion>
Expand Down
2 changes: 1 addition & 1 deletion external/sqlite
9 changes: 5 additions & 4 deletions src/Xamarin.Android.Build.Tasks/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -530,11 +530,12 @@ In this message, the term "binding" means a piece of generated code that makes i
"r10d" is the version of the NDK.</comment>
</data>
<data name="XA3006" xml:space="preserve">
<value>Could not compile native assembly file: {0}</value>
<comment>In this message, the term "assembly" means the low-level language that an assembler like `as` takes as input. (This is different from most of the other messages, where the term "assembly" means the file type that the C# compiler produces.)</comment>
<value>Could not compile native assembly file: {0}{1}</value>
<comment>In this message, the term "assembly" means the low-level language that an assembler like `as` takes as input. (This is different from most of the other messages, where the term "assembly" means the file type that the C# compiler produces). The '{1}' placeholder is replaced with full output of the failed command, starting and ending with a newline.</comment>
</data>
<data name="XA3007" xml:space="preserve">
<value>Could not link native shared library: {0}</value>
<value>Could not link native shared library: {0}{1}</value>
<comment>The '{1}' placeholder is replaced with full output of the failed command, starting and ending with a newline.</comment>
</data>
<data name="XA4209" xml:space="preserve">
<value>Failed to generate Java type for class: {0} due to {1}</value>
Expand Down Expand Up @@ -886,4 +887,4 @@ In this message, the term "handheld app" means "app for handheld devices."
{1} - A Filename.
</comment>
</data>
</root>
</root>
17 changes: 12 additions & 5 deletions src/Xamarin.Android.Build.Tasks/Tasks/CompileNativeAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,24 @@ void RunAssembler (Config config)

string assemblerName = Path.GetFileName (config.AssemblerPath);
LogDebugMessage ($"[LLVM llc] {psi.FileName} {psi.Arguments}");

var stdoutLines = new List<string> ();
var stderrLines = new List<string> ();

using (var proc = new Process ()) {
proc.OutputDataReceived += (s, e) => {
if (e.Data != null)
if (e.Data != null) {
OnOutputData (assemblerName, s, e);
else
stdoutLines.Add (e.Data);
} else
stdout_completed.Set ();
};

proc.ErrorDataReceived += (s, e) => {
if (e.Data != null)
if (e.Data != null) {
OnErrorData (assemblerName, s, e);
else
stderrLines.Add (e.Data);
} else
stderr_completed.Set ();
};

Expand All @@ -87,7 +93,8 @@ void RunAssembler (Config config)
stdout_completed.WaitOne (TimeSpan.FromSeconds (30));

if (proc.ExitCode != 0) {
LogCodedError ("XA3006", Properties.Resources.XA3006, Path.GetFileName (config.InputSource));
var sb = MonoAndroidHelper.MergeStdoutAndStderrMessages (stdoutLines, stderrLines);
LogCodedError ("XA3006", Properties.Resources.XA3006, Path.GetFileName (config.InputSource), sb.ToString ());
Cancel ();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Threading;

using Microsoft.Build.Framework;
Expand Down Expand Up @@ -67,18 +68,24 @@ void RunLinker (Config config)

string linkerName = Path.GetFileName (config.LinkerPath);
LogDebugMessage ($"[Native Linker] {psi.FileName} {psi.Arguments}");

var stdoutLines = new List<string> ();
var stderrLines = new List<string> ();

using (var proc = new Process ()) {
proc.OutputDataReceived += (s, e) => {
if (e.Data != null)
if (e.Data != null) {
OnOutputData (linkerName, s, e);
else
stdoutLines.Add (e.Data);
} else
stdout_completed.Set ();
};

proc.ErrorDataReceived += (s, e) => {
if (e.Data != null)
if (e.Data != null) {
OnErrorData (linkerName, s, e);
else
stderrLines.Add (e.Data);
} else
stderr_completed.Set ();
};

Expand All @@ -96,7 +103,8 @@ void RunLinker (Config config)
stdout_completed.WaitOne (TimeSpan.FromSeconds (30));

if (proc.ExitCode != 0) {
LogCodedError ("XA3007", Properties.Resources.XA3007, Path.GetFileName (config.OutputSharedLibrary));
var sb = MonoAndroidHelper.MergeStdoutAndStderrMessages (stdoutLines, stderrLines);
LogCodedError ("XA3007", Properties.Resources.XA3007, Path.GetFileName (config.OutputSharedLibrary), sb.ToString ());
Cancel ();
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/Xamarin.Android.Build.Tasks/Utilities/MonoAndroidHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,30 @@ public partial class MonoAndroidHelper
public static AndroidVersions SupportedVersions;
public static AndroidSdkInfo AndroidSdk;

public static StringBuilder MergeStdoutAndStderrMessages (List<string> stdout, List<string> stderr)
{
var sb = new StringBuilder ();

sb.AppendLine ();
AppendLines ("stdout", stdout, sb);
sb.AppendLine ();
AppendLines ("stderr", stderr, sb);
sb.AppendLine ();

return sb;

void AppendLines (string prefix, List<string> lines, StringBuilder sb)
{
if (lines == null || lines.Count == 0) {
return;
}

foreach (string line in lines) {
sb.AppendLine ($"{prefix} | {line}");
}
}
}

public static int RunProcess (string name, string args, DataReceivedEventHandler onOutput, DataReceivedEventHandler onError, Dictionary<string, string> environmentVariables = null)
{
var psi = new ProcessStartInfo (name, args) {
Expand Down
4 changes: 4 additions & 0 deletions tests/Mono.Android-Tests/System.Net/NetworkInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ bool AddressesAreEqual (List <IPAddress> one, List <IPAddress> two)

bool HardwareAddressesAreEqual (byte[] one, byte[] two)
{
// Under API 33 .Net doesn't return the hardware address. So we need to ignore it
if (Android.OS.Build.VERSION.SdkInt == Android.OS.BuildVersionCodes.Tiramisu)
return true;
if (one == two)
return true;
if (one == null || two == null)
Expand Down Expand Up @@ -184,6 +187,7 @@ byte[] GetHardwareAddress (MNetworkInterface inf)
// if all the bytes are zero return null like Java does.
if (bytes.All (x => x == 0))
return null;

return bytes;
}

Expand Down

0 comments on commit 065faaf

Please sign in to comment.