Click or drag to resize

PerformanceCounter Class

Represents an extension of the basic PerformanceCounter providing additional statistical logic.
Inheritance Hierarchy
SystemObject
  GSF.DiagnosticsPerformanceCounter

Namespace: GSF.Diagnostics
Assembly: GSF.Core (in GSF.Core.dll) Version: 2.4.207-beta+1781b796b2aa7a54013a031eb432fe4ccee31867
Syntax
public class PerformanceCounter : IDisposable
View Source

The PerformanceCounter type exposes the following members.

Constructors
 NameDescription
Public methodPerformanceCounter(String, String, String) Initializes a new instance of the PerformanceCounter class.
Public methodPerformanceCounter(String, String, String, String) Initializes a new instance of the PerformanceCounter class.
Public methodPerformanceCounter(String, String, String, String, String) Initializes a new instance of the PerformanceCounter class.
Public methodPerformanceCounter(String, String, String, String, String, Single, Boolean) Initializes a new instance of the PerformanceCounter class.
Top
Properties
 NameDescription
Public propertyAliasName Gets or sets an alias name for the PerformanceCounter.
Public propertyAverageValue Gets the average value from the samples of the BaseCounter.
Public propertyBaseCounter Gets the PerformanceCounter object that this PerformanceCounter objects wraps.
Public propertyLastValue Gets the last sample value from the samples of the BaseCounter.
Public propertyLifetimeAverageValue Gets the average sample value over the entire lifetime of the BaseCounter.
Public propertyLifetimeMaximumValue Gets the maximum sample value over the entire lifetime of the BaseCounter.
Public propertyLifetimeSampleCount Gets the total values sampled over the entire lifetime of the BaseCounter.
Public propertyMaximumValue Gets the maximum sample value from the samples of the BaseCounter.
Public propertyMinimumValue Gets the minimum sample value from the samples of the BaseCounter.
Public propertySampleAdjuster Gets or sets an optional custom sample adjustment function. Can be used to apply linear adjustments to sampled values.
Public propertySampleFilter Gets or sets an optional custom sample filter function. Can be used to skip sampled values that are unreasonable.
Public propertySamples Gets a list of sampled values from the BaseCounter
Public propertySamplingWindow Gets or sets the number of samples to use to determine the LastValue, MinimumValue, MaximumValue and AverageValue.
Public propertyValueDivisor Gets or sets the divisor to be applied to the LastValue, MinimumValue, MaximumValue and AverageValue.
Public propertyValueUnit Gets or sets the measurement unit of LastValue, MinimumValue, MaximumValue and AverageValue
Top
Methods
 NameDescription
Public methodDispose Releases all the resources used by the PerformanceCounter object.
Protected methodDispose(Boolean) Releases the unmanaged resources used by the PerformanceCounter object and optionally releases the managed resources.
Public methodEqualsDetermines whether the specified object is equal to the current object.
(Inherited from Object)
Protected methodFinalize Releases the unmanaged resources before the PerformanceCounter object is reclaimed by GC.
(Overrides ObjectFinalize)
Public methodGetHashCodeServes as the default hash function.
(Inherited from Object)
Public methodGetTypeGets the Type of the current instance.
(Inherited from Object)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object.
(Inherited from Object)
Public methodReset Resets the PerformanceCounter object to its initial state.
Public methodSample Obtains a sample value from the BaseCounter.
Public methodToStringReturns a string that represents the current object.
(Inherited from Object)
Top
Fields
 NameDescription
Public fieldStatic memberDefaultSamplingWindow Default number of samples over which statistical values are to be calculated.
Public fieldStatic memberDefaultValueDivisor Default divisor to be applied to the statistical value.
Public fieldStatic memberDefaultValueUnit Default measurement unit of the statistical values.
Top
Extension Methods
 NameDescription
Public Extension MethodGetEnumValueOrDefault Gets the enumeration constant for value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Public Extension MethodGetEnumValueOrDefaultT Gets the enumeration constant for this value, if defined in the enumeration, or a default value.
(Defined by EnumExtensions)
Top
Example
This example shows how to create a performance counter for processor utilization:
C#
using System;
using System.Threading;
using GSF.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        PerformanceCounter counter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
        while (true)
        {
            Thread.Sleep(1000);
            counter.Sample();
            Console.WriteLine(string.Format("Last value: {0}", counter.LastValue));
            Console.WriteLine(string.Format("Minimum value: {0}", counter.MinimumValue));
            Console.WriteLine(string.Format("Maximum value: {0}", counter.MaximumValue));
            Console.WriteLine(string.Format("Average value: {0}", counter.AverageValue));
            Console.WriteLine(new string('-', 30));
        }
    }
}
See Also