JaneySprings / DotNet.Meteor

A VSCode extension that can run and debug .NET apps (Xamarin, MAUI, Avalonia)
https://marketplace.visualstudio.com/items?itemName=nromanov.dotnet-meteor
MIT License
269 stars 10 forks source link

[4.0.0] Profiling, Debugger++ #72

Closed JaneySprings closed 10 months ago

JaneySprings commented 11 months ago
image
jonathanpeppers commented 10 months ago

Does this have a CI build I can try? I’m interested in the easy-to-get speedscope files. 😀

JaneySprings commented 10 months ago

Hi, @jonathanpeppers! I had attached zip file (build for Windows-x64 and Mac-arm64) (my azure license doesn't allow public access 😒 ) DotNet.Meteor.v4.0.0.zip

or you can build vsix from this pr.

This is still an pre-pre-pre-alpha-0.0.0.01 version, work is in progress, I have not added gcdump yet, only dotnet-trace. Also, the trace does not work on the physical iPhone yet. I want to try using mlaunch --tcp-tunnel instead of --forward-ios from the documentation.

You can install this via vscode -> command palette -> type vsix. After that, open your .NET project and create the .vscode/launch.json file with the following content:

{
    "version": "0.2.0",
    "configurations": [
        // For Debugging
        {
            "name": ".NET Meteor Debugger",
            "type": "dotnet-meteor.debugger",
            "request": "launch",
            "preLaunchTask": "dotnet-meteor: Build"
        },
        // For Profiling
        {
            "name": ".NET Meteor Profiler",
            "type": "dotnet-meteor.debugger",
            "request": "launch",
            "profilerMode": "trace",
            "preLaunchTask": "dotnet-meteor: Build"
        }
    ]
}

Done! Select this configuration in the debug menu and run your app (you need to run the application without debugging, vscode top menu -> run -> run without debugging)

image

When the application starts, you will see a message about the launch of dotnet-trace in the debug console. In the folder .meteor/YOU_APP.bin file will be created (maybe I need to rename this file into .nettrace...?)

image

To complete the trace, stop debugging in VSCode (if you just close the application on the device, the trace may be damaged)

image

After completion, you will see the message:

Stopping the trace. This may take several minutes depending on the application being traced.
Trace completed.

A 'speedscope.json' file will be created In the .meteor folder

image

Enjoy!

Thank you, @jonathanpeppers, for your help with profiler! Without it, I would still be trying to run the log:heapshot,calls.... and get a mldp report 🥹

JaneySprings commented 10 months ago

Hi, @jonathanpeppers ! Now you can officially try the new .NET Meteor extension version (4.0.1). Сheck the readme to find out how to enable the profiler. https://marketplace.visualstudio.com/items?itemName=nromanov.dotnet-meteor

Thank you!

filipnavara commented 10 months ago
  • gcdump (does not work. Ask MS, implement in future minor)

Let me know if there's something that I can help with. I wrote mono-gcdump for .NET 7, have experience with the .NET 8 native support, and I maintain a cross-platform viewer at https://github.com/1hub/dotnet-heapview.

JaneySprings commented 10 months ago

Hi, @filipnavara ! Yep, I have seen these projects, Thanks! Of course, I want to make dotnet-gcdump work, since .NET Meteor already has a dependency on the dotnet diagnostics repository. But at the moment, if I follow the official wiki, I just get the message Waiting for... from gcdump and the application also hangs waiting for the profiler.

I will try to see what can be done, but if nothing works out, then of course I will return to your projects 😉. Anyway, I'll use your heap viewer (I've already put a star ⭐️)

filipnavara commented 10 months ago

the official wiki

Got a link? There's actually more than one wiki page with the instructions. If there's something wrong with them I can try to reproduce and correct it.

JaneySprings commented 10 months ago

I tried to use this guide https://github.com/xamarin/xamarin-android/blob/main/Documentation/guides/tracing.md

filipnavara commented 10 months ago

Here's a minimal set of steps to get the GC dump, tested on my machine.

Prerequisites:

Steps:

JaneySprings commented 10 months ago

Thanks! I think it will work. I'll try it after the new year.

Have you tried the same approach for iOS and Maccatalyst? It seems to me that it should work too, you just need to experiment with the dsrouter options.

In the Macios repository doesn't say anything about gcdump, but it seems to me that the libmono-component-* libraries are the same. https://github.com/xamarin/xamarin-macios/wiki/Profiling

filipnavara commented 10 months ago

Have you tried the same approach for iOS and Maccatalyst?

Yep. The diagnostic component is included by default in Debug builds IIRC, so you don't need extra build parameter for that. The rest of the steps is basically identical, just adjust the dsrouter options accordingly.

In the Macios repository doesn't say anything about gcdump, but it seems to me that the libmono-component-* libraries are the same.

That wiki page predates the .NET 8 dotnet-gcdump support.

JaneySprings commented 9 months ago

Hi, @filipnavara ! I have tested the way that you described above, it works as expected. You are the 'God of magic commands' 😄 Thank you!

image

P.S. The only thing I noticed is that your Heapview tool doesn't start if net7.0 is not installed. I found Microsoft's <RollForward>major</RollForward> option in the DotNet.Diagnostics repository. If it is set, dotnet will search for the TargetFramework version and higher. But in any case, I can pass it on when launching the tool (--roll-forward).

filipnavara commented 9 months ago

The only thing I noticed is that your Heapview tool doesn't start if net7.0 is not installed. I found Microsoft's <RollForward>major</RollForward> option in the DotNet.Diagnostics repository.

My goal was to update the tool to .NET 8 but there's an issue with SkiaSharp in the WebAssembly online version (emsdk version mismatch for the compiled code). I'll update the global tool to add the roll-forward policy. Thanks for bringing it to my attention!

JaneySprings commented 9 months ago

I was able to support gcdump on Android (Emulator/Device), iOS (Emulator/Device) and Windows. For some reason, it is not possible to establish a connection on Maccatalyst.

filipnavara commented 9 months ago

have you come across something like this, or is it better to create an issue in the xamarin-macios repository?

Incidentally, someone filed an issue for this yesterday - https://github.com/dotnet/runtime/issues/96970. I plan to look into it at some point.

JaneySprings commented 9 months ago

Yep, trace broken on MacOS after last update. My app jumps endlessly in the dock =)

image

I remember exactly how it worked.