mono-gcdump icon indicating copy to clipboard operation
mono-gcdump copied to clipboard

Can't convert a nettrace file

Open forlayo opened this issue 2 years ago • 10 comments

I got the following crash..

PS D:\workspace> dotnet run --project .\mono-gcdump\mono-gcdump.csproj -- convert d:\workspace\maui-app_20230523_170231.nettrace
Unhandled exception: System.TimeoutException: Heap dump didn't start within 5 seconds
   at MonoGCDump.MonoMemoryGraphBuilder.Build(EventPipeEventSource source, MonoGCRootRangeTracker rootRangeTracker, Action stop) in D:\workspace\mono-gcdump\MonoMemoryGraphBuilder.cs:line 98
   at MonoGCDump.Program.HandleConvert(String inputFileName, String outputFileName) in D:\workspace\mono-gcdump\Program.cs:line 47
   at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.AnonymousCommandHandler.SyncUsingAsync(InvocationContext context)
   at System.CommandLine.Invocation.AnonymousCommandHandler.Invoke(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()

forlayo avatar May 23 '23 15:05 forlayo

Can you share the .nettrace file? Most likely the correct events were not recorded. It can be analyzed with PerfView to see the details, but it's not the most user friendly tool.

filipnavara avatar May 23 '23 15:05 filipnavara

Sure, here you go:

maui-app_20230523_172130.zip

I had follow the guide that I found here: https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/tracing.md

However my app is a MAUI App, I am trying to found the issue that's causing a lot of GC on Android version of the app..

forlayo avatar May 23 '23 15:05 forlayo

I have a couple more of netrace files, all of them giving error with mono-gcdump, here you go in case they're helpful maui-app_20230523_others.zip

forlayo avatar May 23 '23 15:05 forlayo

Thanks, I will check the provided .nettrace files later today when I get home.

I had follow the guide that I found here: https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/tracing.md

That guide should work as long as you specify --providers Microsoft-DotNETRuntimeMonoProfiler:0xC900001:4 for the dotnet-trace tool. I generally recommend to use mono-gcdump directly instead of going through the .nettrace intermediate files.

filipnavara avatar May 23 '23 15:05 filipnavara

I checked the .nettrace file and, unfortunately, it's missing some of the GC events (GCHeapDumpStart, GCHeapDumpStop, GCHeapDumpObjectReferenceData, GCRoots, etc.). Hence the Heap dump didn't start within 5 seconds error message in the output.

It does have few others (GCEvent, GCRootRegister, GCRootUnregister). This usually means that the mask for dotnet-trace didn't use the correct parameters, or that it didn't capture a garbage collection. It is quite tricky to get that done correctly which is why I recommend using mono-gcdump collect --interactive --diagnostic-port ~/mylocalport,connect -o memory.gcdump instead. You already got the hard part done with setting up the diagnostic port machinery, so this step should be the easy one.

filipnavara avatar May 23 '23 18:05 filipnavara

FWIW... if using dotnet-collect the recommended parameter is --providers Microsoft-DotNETRuntimeMonoProfiler:0xC900003:4:heapcollect=ondemand which forces the garbage collections. The linked guide specifies --providers Microsoft-DotNETRuntimeMonoProfiler:0xC900001:4 which also works for me, at least most of the time, but it's not guaranteed to force the GC dump.

I also updated the tool to work in the listen mode if dotnet-dsrouter is used in the client-server mode. It is still recommended to use the dotnet-dsrouter server-server mode but since various guides use the dotnet-dsrouter client-server command I fixed the support for it.

filipnavara avatar Jun 07 '23 11:06 filipnavara

I'm having the same issue. I understand that following the official tracing guide from xamarin-android should work now, right? Also, I've tried all your suggestions, but still cannot make it work.

tranb3r avatar Sep 25 '23 13:09 tranb3r

@tranb3r If you can share the .nettrace file privately (filipnavara AT gmail) I can have a look.

filipnavara avatar Sep 25 '23 13:09 filipnavara

I'm having the same issue. I understand that following the official tracing guide from xamarin-android should work now, right? Also, I've tried all your suggestions, but still cannot make it work.

The trace file is recorded with .NET 8. For .NET 8 you should get the latest version of dotnet-gcdump and use that instead. MonoVM was improved to emit the same events that CoreCLR does and official support for the .NET diagnostic tools was added.

filipnavara avatar Sep 25 '23 14:09 filipnavara

I think I'm having the same error. I was following the steps explained here. I think I used the right providers but may be I made a mistake somewhere.

Here's my nettrace and the commands I used: uno-app-trace3.zip

dotnet-dsrouter

dotnet-dsrouter client-server -tcps 127.0.0.1:9001 -ipcc /tmp/uno-app3 --verbose debug

dotnet-trace

PS C:\Repos\UnoApplicationTemplate\src\app\ApplicationTemplate.Mobile> dotnet-trace collect --diagnostic-port /tmp/uno-app3 -o uno-app-trace3 --providers Microsoft-DotNETRuntimeMonoProfiler:0xC900001:4

Provider Name                           Keywords            Level               Enabled By
Microsoft-DotNETRuntimeMonoProfiler     0x000000000C900001  Informational(4)    --providers

Waiting for connection on tmp/uno-app3
Start an application with the following environment variable: DOTNET_DiagnosticPorts=tmp/uno-app3
Process        : uno-app3
Output File    : C:\Repos\UnoApplicationTemplate\src\app\ApplicationTemplate.Mobile\uno-app-trace3


[00:00:00:51]   Recording trace 1.1737   (MB)
Press <Enter> or <Ctrl+C> to exit...
Stopping the trace. This may take several minutes depending on the application being traced.

Trace completed.

dotnet build

PS C:\Repos\UnoApplicationTemplate\src\app\ApplicationTemplate.Mobile> dotnet build -f net7.0-android -t:run -c Release /p:RunAOTCompilation=true /p:AndroidEnableProfiler=true

mono-gcdump

PS C:\Repos\UnoApplicationTemplate\src\app\ApplicationTemplate.Mobile> dotnet run --project ..\..\..\..\mono-gcdump\mono-gcdump.csproj -- convert uno-app-trace3.nettrace
C:\Repos\mono-gcdump\MonoGCRootRangeTracker.cs(63,31): warning CS8632: The annotation for nullable reference types should on
ly be used in code within a '#nullable' annotations context. [C:\Repos\mono-gcdump\mono-gcdump.csproj]
C:\Repos\mono-gcdump\MonoGCRootRangeTracker.cs(15,47): warning CS8632: The annotation for nullable reference types should on
ly be used in code within a '#nullable' annotations context. [C:\Repos\mono-gcdump\mono-gcdump.csproj]
C:\Repos\mono-gcdump\MonoGCRootRangeTracker.cs(15,67): warning CS8632: The annotation for nullable reference types should on
ly be used in code within a '#nullable' annotations context. [C:\Repos\mono-gcdump\mono-gcdump.csproj]
C:\Repos\mono-gcdump\Microsoft.Diagnostics.NETCore.Client\DiagnosticsClient\DiagnosticsClient.cs(480,17): warning CS8073: Th
e result of the expression is always 'false' since a value of type 'Guid' is never equal to 'null' of type 'Guid?' [C:\Repos
\mono-gcdump\mono-gcdump.csproj]
C:\Repos\mono-gcdump\Microsoft.Diagnostics.NETCore.Client\DiagnosticsClient\DiagnosticsClient.cs(527,17): warning CS8073: Th
e result of the expression is always 'false' since a value of type 'Guid' is never equal to 'null' of type 'Guid?' [C:\Repos
\mono-gcdump\mono-gcdump.csproj]
Unhandled exception: System.TimeoutException: Heap dump didn't start within 5 seconds
   at MonoGCDump.MonoMemoryGraphBuilder.Build(EventPipeEventSource source, MonoGCRootRangeTracker rootRangeTracker, Action stop) in C:\Repos\mono-gcdump\MonoMemoryGraphBuilder.cs:line 98
   at MonoGCDump.Program.HandleConvert(String inputFileName, String outputFileName) in C:\Repos\mono-gcdump\Program.cs:line 48
   at System.CommandLine.Invocation.AnonymousCommandHandler.InvokeAsync(InvocationContext context)
   at System.CommandLine.Invocation.AnonymousCommandHandler.SyncUsingAsync(InvocationContext context)
   at System.CommandLine.Invocation.AnonymousCommandHandler.Invoke(InvocationContext context)
   at System.CommandLine.Invocation.InvocationPipeline.<>c__DisplayClass4_0.<<BuildInvocationChain>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass17_0.<<UseParseErrorReporting>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass12_0.<<UseHelp>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass22_0.<<UseVersionOption>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass19_0.<<UseTypoCorrections>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<UseSuggestDirective>b__18_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass16_0.<<UseParseDirective>b__0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<<RegisterWithDotnetSuggest>b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
   at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<<UseExceptionHandler>b__0>d.MoveNext()```

Oh and here's the project I'm trying to profile, if that helps. https://github.com/nventive/UnoApplicationTemplate

jeanplevesque avatar Nov 03 '23 14:11 jeanplevesque