dotnet / diagnostics

This repository contains the source code for various .NET Core runtime diagnostic tools and documents.
MIT License
1.18k stars 354 forks source link

dotnet-trace always detects 100% CPU usage #3554

Open alexeygritsenko opened 1 year ago

alexeygritsenko commented 1 year ago

Hello, I don’t know if my question is a bug or incorrect use of the utility, but the fact is that it always shows 100% load in reports when in fact it is not.

Steps:

  1. check "top" command and see 0%-24% top
  2. run "dotnet-trace collect -p 1205 --duration 00:00:00:30" command and see report in VS2022, 100% always dotnet-trace report I would appreciate any help to fix this. I want accurate results.

System: 4 core + 8gb ram Ubuntu 20.04.5 LTS .net 6.0.12 sdk + runtime dotnet-trace 6.0.351802

hoyosjs commented 1 year ago

Feel free to correct me @davmason @dramos020 if this is not accurate. The main thing is the runtime emits the events that are used to calculate the stacks of running code

tommcdon commented 1 year ago

I added the documentation label as we should better document dotnet-trace "CPU" time is actually "Thread Time", and so if threads are blocked it will still report the time on that thread the same as CPU execution.

alexeygritsenko commented 1 year ago

Thank you for your responses! Now it is clear that this is not a bug but a nuance. What if make an "exclude" feature for VS viewer? (like as "Right click -> Exclude") Exclude specific namespaces from profiler results and recalculated with exclusions in mind, where we would have more precise results.

davmason commented 1 year ago

Hi @alexeygritsenko,

The issue here is we are reporting fundamentally different data (thread time vs CPU time), and there isn't a good way to massage it to act like CPU time. For any feature requests for VS, the right place to file them is https://developercommunity.visualstudio.com/VisualStudio

romkatv commented 1 year ago

The issue here is we are reporting fundamentally different data (thread time vs CPU time)

I found this out the hard way. I've migrated my code from Windows to Linux and thought I would be able to use dotnet-trace for CPU-profiling my code on Linux the same way I previously used VSPerf.exe on Windows. Unfortunately, dotnet-trace measures wall time, so the profile is dominated by sleeping threads: thread pool threads waiting for work, IO completion threads waiting for IO, various threads waiting on semaphores, etc.

What is the recommended way for collecting CPU profiles of dotnet applications on Linux?

P.S.

I'm sorry if I'm hijacking this issue. I can open another one if you prefer.