Maoni0 / realmon

A monitoring tool that tells you when GCs happen in a process and some characteristics about these GCs
MIT License
281 stars 25 forks source link

Use .NET 6 NativeAOT compilation #5

Closed hez2010 closed 2 years ago

hez2010 commented 2 years ago

Use .NET 6 NativeAOT toolchain for compilation which only produces a 9mb executable and some necessary native dependencies (~6mb). Build artifacts can be distributed without needs of runtime installation.

Build:

dotnet publish -c Release -r win-x64

Then go to bin\Release\net6.0\win-x64\publish to see build artifacts.

Uploaded my build artifacts for testing:

GCRealTimeMon.zip

Maoni0 commented 2 years ago

thanks! can you please make this as a separate dir so if someone wants to do AoT they can, but otherwise it's a normal build? we already don't ship binaries in this repo (might in the future) which means people would have to build it anyway, unless they wanna copy the resulting binaries somewhere (and want to copy less) they wouldn't need the AoT part.

hez2010 commented 2 years ago

Sure. I've added a property AotCompilation and only build the project with NativeAOT when /p:AotCompilation=true is specified. By default AotCompilation is false so building with Visual Studio won't go through aot compiler.

Maoni0 commented 2 years ago

thanks! I should clarify what I meant. I would prefer to not have to change the current default solution at all. and I'm not sure why GCRealTimeMon.sln was moved to the root dir? AFAIK you cannot use .sln on linux. so this is all windows specific.

then we could have a sub dir in src\windows like src\windows\aot. and if you build from that dir you would get AoT compilation. so you can put whatever build specific stuff there, like the Directory.Build.props/rd.xml.

does this make sense?

hez2010 commented 2 years ago

AFAIK you cannot use .sln on linux.

Actually .sln work with dotnet cli on linux, it's no longer Windows specified.

does this make sense?

Yeah. Will reorganize the directory structure.

Maoni0 commented 2 years ago

Actually .sln work with dotnet cli on linux, it's no longer Windows specified.

ahh, I learned something new :) if you could please update the readme.md with the instructions of building .sln on linux (especially for people who are inept at using .sln's 😅) that'd be much appreciated.

Maoni0 commented 2 years ago

BTW, since now I know that .sln can be built on linux it means you just implemented the 2nd part of this issue. so we can mark that part as done after this one gets merged.

my request of making AoT a separate dir still applies but it would make sense to move the default .sln into the root dir. so you can build the default build on windows or linux and go to the AoT dir to build the AoT build. does that sound reasonable?

kant2002 commented 2 years ago

@Maoni0 I think @hez2010 do most sensible way. I will try to explain why I think he is right, and this way would not harm building this tool.

AOT is jut another flavor of packaging EXE file. Right now it can be thought of as ReadyToRun+. ReadyToRun would not be invoked if special flags to build not given, same in the Steve's proposal. If /p:AotCompilation=true would no be given, nothing changed in regular build for any developer who do not care about AOT.

May I ask you what's your concern and why you want place AOT stuff in separte folder? May I also vivisect whole PR to such point, to show you why placing that stuff in separate folder probably would be useless? Obviously I'm not sure that I would convince you, but no harm in asking.

Reason why I want to go great length in explaining this change, is because you are authority in the .NET world, and most likely people will copy patterns found in your repo. I would like to have AOT enabling changes in simplest possible way, so if people follow your lead, they would go easiest possible way. There a lot of problems with AOT, and tooling setup is not one of them.

hez2010 commented 2 years ago

@Maoni0 ~Unfortunately realmon won't work on Linux simply by this PR because Microsoft.Diagnostics.Tracing.TraceEvent isn't cross-platform, though it can successfully build on Linux. See https://github.com/microsoft/perfview/blob/2a9d7d865972ed72ef57f40333db16302c8bf376/src/TraceEvent/TraceEventNativeMethods.cs?_pjax=%23repo-content-pjax-container#L498~

Update: I've seen #9 successfully make realmon work on Linux. You can merge #9 first and I'll reorganize the directory and update README.md.

hez2010 commented 2 years ago

I've reorganized the directories but still use /p:AotCompilation=true for AOT compilation instead of a separate directory. I think /p:AotCompilation=true is the same with /p:PublishReadyToRun=true, i.e. AOT is a compilation option instead of a project.

Maoni0 commented 2 years ago

very cool! thank you so much :)