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

PerformanceCounters - Read OS counters on .NET Core #15468

Closed
manu-st opened this issue Oct 16, 2015 · 21 comments
Closed

PerformanceCounters - Read OS counters on .NET Core #15468

manu-st opened this issue Oct 16, 2015 · 21 comments
Labels
area-System.Diagnostics.PerformanceCounter enhancement Product code improvement that does NOT require public API changes/additions help wanted [up-for-grabs] Good issue for external contributors
Milestone

Comments

@manu-st
Copy link

manu-st commented Oct 16, 2015

Currently CoreFX generates the reference assembly System.Diagnostics.PerformanceCounter.dll however, there doesn't seem to be any counter part implementation for it, nor can I see an entry for this in the progress page at https://github.com/dotnet/corefx-progress/blob/master/src-diff/README.md.

Is this expected?

Thanks

@joshfree
Copy link
Member

@karelz
Copy link
Member

karelz commented Nov 10, 2016

Next step: We need implementation of the Desktop API surface - Windows can just port it from Desktop. Mono has implementation on Linux, maybe we can leverage part of it here for Linux.

Complexity: Medium (packaging will be similar to Registry)

@karelz karelz changed the title PerformanceCounter status Add PerformanceCounter to .NET Core Nov 10, 2016
@vancem
Copy link
Contributor

vancem commented Jan 25, 2017

Perf counters mean different things. Often people only want to READ existing perf counters. This is relative straightforward, and is the kind of thing that we might add (or others could simply make a clone of this that is .NET Core compatible). For this case, however we really would rather we identify the most important of these that are CROSS PLATFORM (e.g. working set, CPU usage ...), and provide a SIMPLER interface to get these that is platform neutral (basically a class or set of classes that have properties that represent he live value of this in a particular process).

However creating NEW performance counter (you are logging new data), is more problematic because windows Performance counters require ADMIN install, and are a MACHINE WIDE SHARED RESOURCE (which makes xcopy deployment and side-by-side problematic).

We would prefer that people who need to log use EventSources or EventCounters for this.

See Event Counter Tutorial for more on event counters.

See EventSource Tutorial for more on EventSource.

@karelz
Copy link
Member

karelz commented Feb 9, 2017

Note: Fully x-plat Performance Counters are tracked by dotnet/corefx#4577.

@roji
Copy link
Member

roji commented Feb 9, 2017

Just wanted to second @vancem's distinction between reading existing perf counters vs. creating a publishing new ones. I maintain Npgsql, which publishes connection pool perf information on Windows (just like SqlClient does), and it's important for something like this to be possible in a x-plat way with .NET Core.

@galvesribeiro
Copy link
Member

@roji yeah we understand that. Perhaps we should have a revamp on those counters in .Net Core to make it crossplat.

@karelz karelz changed the title Add PerformanceCounter to .NET Core PerformanceCounter - Read Windows OS counters on .NET Core Mar 2, 2017
@karelz karelz changed the title PerformanceCounter - Read Windows OS counters on .NET Core PerformanceCounter - Read OS counters on .NET Core Mar 2, 2017
@danmoseley
Copy link
Member

Also note that if and when we implement this, the ref definition is incomplete. It is missing at least these from its desktop counterparts:

MembersMustExist : Member 'System.Diagnostics.PerformanceCounter.CloseSharedResources()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Diagnostics.PerformanceCounter.Decrement()' does not exist in the implementation but it does exist in the contract.
MembersMustExist : Member 'System.Diagnostics.PerformanceCounter.Dispose(System.Boolean)' does not exist in the implementation but it does exist in the contract.

@karelz
Copy link
Member

karelz commented May 3, 2017

Looks like PerformanceCoutners are used for example by NLog, we could look at it as example of customer usage, to see how to migrate such code to .NET Core / .NET Standard.

@bloudraak
Copy link

bloudraak commented May 4, 2017

I started a project to allow an external system to get performance metrics. I'm really interested not only in extracting metrics or"performance counters", but an API to discover them and report them for a given process.

I'm actively working on making it possible for Prometheus amongst others to extract metrics from an aspnet core process.

So in summary, I'd like to discover what metrics are available in the process (be it specific to the app, a subsystem like EF or ASPNET, platform like GC or exceptions/sec , or OS like memory, disk queue length.

@karelz

@karelz karelz changed the title PerformanceCounter - Read OS counters on .NET Core PerformanceCounters - Read OS counters on .NET Core May 26, 2017
@mi-hol
Copy link

mi-hol commented Jul 20, 2017

Also Powershell Core is affected by missing basic PerformanceCounter features like ElapsedTime https://github.com/PowerShell/PowerShell/issues/4295
From my view adding just the basic 'read' counters dealing with time measures would be a great improvement for many use cases and would boost compatibility!
This improvement could potentially be accomplished within just a few hours :)

@danmoseley
Copy link
Member

cc @brianrob

@evil-shrike
Copy link

Currently (2.0) we can reference a nuget/assembly lib built for full .net in .net core 2.0. But if that library uses PerformanceCounterType we'll get runtime exception like:
Message: System.TypeLoadException : Could not load type 'System.Diagnostics.PerformanceCounterType' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I understand that it's expected. But is these any workaround for this? Like a nuget package with stubs for all PerformanceCounters types?

@danmoseley
Copy link
Member

@brianrob ?

@brianrob
Copy link
Member

I suspect that there are no workarounds at this time as PerformanceCounters are a desktop-only feature. Do you have a scenario where you need to reference this type other than for using PerformanceCounters, which don't currently run on core?

@evil-shrike
Copy link

I encountered runtime exception Could not load type 'System.Diagnostics.PerformanceCounterType' while tried to use Devart's ado.net provider for Postgres (built for .net fw 3.5) on core2.

@danmoseley
Copy link
Member

Folks who would use this on .NET Core please thumb up the top post.

@smbecker
Copy link

For those that need this sooner, I used this article to implement what I needed. Then I just light up the various perf counters that I need when running on windows.

@danmoseley
Copy link
Member

danmoseley commented Nov 20, 2017

This port is done (eg dotnet/corefx#24579)!

It is currently up on nuget marked preview. It will be marked stable next year, but can be used now (we don't know of issues with it.) It is included in the new compat pack. so it's easiest to just reference that to get it.

I'll close this as complete - please try out the package and open new issues with any bugs you find.

@blugri
Copy link

blugri commented Nov 23, 2017

I am trying to use this in a .NET core 2.0 application to use a 3rd party library that is written in .NETFramework,Version=v4.6.1. Unfortunately I still get the following exception

TypeLoadException: Could not load type 'System.Diagnostics.PerformanceCounter' from assembly 'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

@danmosemsft Am I doing something wrong? Should your port solve my issue?

Cheers

@danmoseley
Copy link
Member

@blugri can you please instead reference the full compat pack and see I'd that fixes this?
https://www.nuget.org/packages/Microsoft.Windows.Compatibility

@blugri
Copy link

blugri commented Nov 24, 2017

@danmosemsft Thanks. It is working :-)

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@dotnet dotnet locked as resolved and limited conversation to collaborators Jan 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Diagnostics.PerformanceCounter enhancement Product code improvement that does NOT require public API changes/additions help wanted [up-for-grabs] Good issue for external contributors
Projects
None yet
Development

No branches or pull requests