Skip to content
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

Can't convert a nettrace file #6

Open
forlayo opened this issue May 23, 2023 · 10 comments
Open

Can't convert a nettrace file #6

forlayo opened this issue May 23, 2023 · 10 comments

Comments

@forlayo
Copy link

forlayo commented May 23, 2023

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()
@filipnavara
Copy link
Owner

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.

@forlayo
Copy link
Author

forlayo commented May 23, 2023

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
Copy link
Author

forlayo commented May 23, 2023

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

@filipnavara
Copy link
Owner

filipnavara commented May 23, 2023

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
Copy link
Owner

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
Copy link
Owner

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.

@tranb3r
Copy link

tranb3r commented Sep 25, 2023

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.

@filipnavara
Copy link
Owner

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

@filipnavara
Copy link
Owner

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.

@jeanplevesque
Copy link

jeanplevesque commented Nov 3, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants