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

how can I get the CPU usage in percent of my app ? #31921

Closed
John0King opened this issue Feb 7, 2020 · 4 comments
Closed

how can I get the CPU usage in percent of my app ? #31921

John0King opened this issue Feb 7, 2020 · 4 comments
Labels
area-Diagnostics-coreclr EventPipe question Answer questions and provide assistance, not an issue with source code or documentation.

Comments

@John0King
Copy link

I want to get the CPU and Memory usage of my app in .net core, for .net framework , I can use PerformanceCounter class, I have read a few docs about the EventCounter class , but it seems not able to get the info from it.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Feb 7, 2020
@hoyosjs hoyosjs added diagnostic global tooling question Answer questions and provide assistance, not an issue with source code or documentation. area-Diagnostics-coreclr EventPipe and removed untriaged New issue has not been triaged by the area owner labels Feb 7, 2020
@hoyosjs
Copy link
Member

hoyosjs commented Feb 7, 2020

Do you want to use them programatically? Or just see them?

Or have you tried this and still get no information back? What version of the dotnet runtime are you using in this case?

@sywhang @josalem
cc @dotnet/dotnet-diag

@noahfalk
Copy link
Member

noahfalk commented Feb 8, 2020

There are also programmatic options using properties on System.Diagnostics.Process. https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.process.totalprocessortime?view=netcore-3.1

@John0King
Copy link
Author

John0King commented Feb 8, 2020

@hoyosjs
I'm using .net core 3.1, And I want to use it in-proc (show CPU usage and refresh every few seconds ).

Using EventListener on the RuntimeEventSource you can do it in-proc. You can get an idea maybe starting on the Listener

The RuntimeEventSource is internal how do I use that ? Is there a sample ? and does the PerformaceCounter work on Linux ?

@sywhang
Copy link
Contributor

sywhang commented Feb 8, 2020

@John0King You can use EventListener to subscribe to System.Runtime EventSource. Here is a sample EventListener implementation on how to do that: https://github.com/dotnet/diagnostics/blob/master/documentation/design-docs/eventcounters.md#sample-code

PerformanceCounter only works on Windows. EventCounter is the recommended cross-platform API.

@ghost ghost added the will_lock_this label Dec 6, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-Diagnostics-coreclr EventPipe question Answer questions and provide assistance, not an issue with source code or documentation.
Projects
None yet
Development

No branches or pull requests

5 participants