Groups | Blog | Home
all groups > dotnet performance > may 2006 >

dotnet performance : Need to set PerformanceCounter.RawValue to a double value



vecozo NO[at]SPAM online.nospam
5/8/2006 11:25:02 AM
Hi,

Is it possible to set the double (or perhaps *calculated*) values of a
Windows NT performance counter? We use the PerformanceCounter.RawValue
property to set counters, such as the total number of requests on a certain
application. However, PerformanceCounter.RawValue is of type long but we
require to set a double value (e.g. to set an averages). An option would be
if we were able to set the denominator and nominator of the calculated value.

I hope you be of any assistance.

Regards,
Martijn Kaag


* Background:
We are working on a library that instruments our applications. The library
collects custom counters (“sources”) and every x minutes distributes these
collected values to various “sinks” such as a database, a user interface or
Windows NT performance counters using the System.Diagnostics namespace.
Because we have our own Counter objects that calculate the average, frequency
etc we do not use the default PerformanceMonitor.Increment and
vecozo NO[at]SPAM online.nospam
5/8/2006 1:17:01 PM

Thanks Greg!

The link cleared up a lot. It works!

Regards,
Martijn


PS For those who are looking for the same answer:
What I did not understand before was that you actually need two performance
counters, a XXXBase (denominator) and an AverageXXX (nominator):

// Add the counter.
CounterCreationData rawFraction = new CounterCreationData();
rawFraction.CounterType =
PerformanceCounterType.AverageCount64;
rawFraction.CounterName = averageCounterName;
CCDC.Add(rawFraction);

// Add the base counter.
CounterCreationData rawFractionBase = new
CounterCreationData();
rawFractionBase.CounterType =
PerformanceCounterType.AverageBase;
rawFractionBase.CounterName = averageCounterNameBase;
CCDC.Add(rawFractionBase);

The averageCounterName now reads [rawFractionCounter].rawvalue /
[rawFractionBase].rawvalue.


______________________________

[quoted text, click to view]
Greg Young
5/8/2006 2:46:53 PM
Better might be to look at AverageXXX performance counters
....CountPerTimeInterval sounds particularly useful for you in this case.
http://www.informit.com/guides/content.asp?g=dotnet&seqNum=254 gives some
examples. The RawFraction type (also included in that article) is exactly
what you describe below.

Cheers,

Greg Young
MVP - C#


[quoted text, click to view]

AddThis Social Bookmark Button