Freigeben über


PerformanceCounterType-Enumeration

Gibt die Formel an, mit der die NextValue-Methode für eine PerformanceCounter-Instanz berechnet wird.

Namespace: System.Diagnostics
Assembly: System (in system.dll)

Syntax

'Declaration
Public Enumeration PerformanceCounterType
'Usage
Dim instance As PerformanceCounterType
public enum PerformanceCounterType
public enum class PerformanceCounterType
public enum PerformanceCounterType
public enum PerformanceCounterType

Member

  Membername Beschreibung
AverageBase Ein Basiszähler, der für die Berechnung der Durchschnittswerte von Zeit oder Anzahl verwendet wird, z. B. AverageTimer32 und AverageCount64. Speichert den Nenner für die Berechnung eines Indikators, um "Zeit pro Operation" oder "Anzahl pro Operation" auszugeben. 
AverageCount64 Ein Durchschnittsindikator, der die durchschnittliche Anzahl der während einer Operation verarbeiteten Elemente anzeigt. Indikatoren dieses Typs zeigen das Verhältnis der verarbeiteten Elemente und der Anzahl der durchgeführten Operationen an. Dieses Verhältnis wird durch Vergleich der Anzahl der innerhalb des letzten Zeitintervalls verarbeiteten Elemente mit der Anzahl der in diesem Intervall durchgeführten Operationen berechnet. 

Formel: (N1 -N0)/(B1 -B0), wobei N1 und N0 Leistungsindikator-Messwerte und B1 sowie B0 die entsprechenden AverageBase-Werte darstellen. Der Zähler stellt somit die Anzahl der im Messintervall verarbeiteten Elemente und der Nenner die Anzahl der im Messintervall durchgeführten Operationen dar.

Zu den Indikatoren von diesem Typ gehören Physikalischer Datenträger\ Mittlere Bytes/Übertragung.

AverageTimer32 Ein Durchschnittsindikator, der die durchschnittliche Dauer eines Prozesses oder einer Operation angibt. Indikatoren dieses Typs geben das Verhältnis der Gesamtdauer des Messintervalls und der Anzahl der während dieser Zeit durchgeführten Prozesse oder Operationen an. Dieser Indikatortyp misst die Zeit in Ticks der Systemuhr. 

Formel: ((N1 -N0)/F)/(B1 -B0), wobei N1 und N0 Leistungsindikator-Messwerte sowie B1 und B0 die entsprechenden AverageBase-Werte darstellen und F für die Anzahl der Ticks pro Sekunde steht. Durch den Faktor F wird das Ergebnis in Sekunden umgerechnet. Der Zähler stellt die Anzahl der Ticks im letzten Messintervall, F die Tickfrequenz und der Nenner die Anzahl der im letzten Messintervall durchgeführten Operationen dar.

Zu den Indikatoren von diesem Typ gehören Physikalischer Datenträger\ Mittlere Sek./Übertragung.

CounterDelta32 Ein Differenzindikator, der die Änderung des gemessenen Attributs zwischen den beiden letzten Messintervallen anzeigt. 

Formel: N1 -N0, wobei N1 und N0 Leistungsindikator-Messwerte darstellen.

CounterDelta64 Ein Differenzindikator, der die Änderung des gemessenen Attributs zwischen den beiden letzten Messintervallen anzeigt. Er unterscheidet sich vom CounterDelta32-Indikatortyp nur dadurch, dass er größere Felder verwendet, um größere Werte verarbeiten zu können. 

Formel: N1 -N0, wobei N1 und N0 Leistungsindikator-Messwerte darstellen.

CounterMultiBase Ein Basisindikator, der die Anzahl der gemessenen Elemente angibt. Er wird als Nenner bei Durchschnittsberechnungen von Zeitwerten für mehrere gleichartige Elemente verwendet. Wird mit CounterMultiTimer, CounterMultiTimerInverse, CounterMultiTimer100Ns und CounterMultiTimer100NsInverse verwendet. 
CounterMultiTimer Ein Prozentindikator, der die Aktivitätsdauer mindestens einer Komponente als prozentualen Teil der Gesamtdauer des Messintervalls darstellt. Da der Zähler die Aktivitätsdauer von gleichzeitig aktiven Komponenten angibt, kann das prozentuale Ergebnis 100 Prozent überschreiten. 

Dieser Indikator ist ein Multitimer. Multitimer sammeln Daten von mehreren Instanzen einer Komponente, z. B. von Prozessoren oder Festplatten. Dieser Indikatortyp unterscheidet sich von CounterMultiTimer100Ns dadurch, dass die Zeit nicht in Einheiten von 100 Nanosekunden, sondern in Ticks des Systemzeitgebers gemessen wird.

Formel: ((N1-N0)/(D1-D0)) x 100/B, wobei N1 und N0 Leistungsindikator-Messwerte, D1 und D0 die entsprechenden Zeitmesswerte in Ticks des Systemzeitgebers darstellen und die Variable B die Basiszählung für die überwachten Komponenten angibt (mit einem Basiszähler vom Typ CounterMultiBase). Der Zähler stellt den Anteil des Messintervalls dar, während dessen die überwachten Komponenten aktiv waren, und der Nenner stellt die Gesamtdauer des Messintervalls dar.

CounterMultiTimer100Ns Ein Prozentindikator, der die Aktivitätsdauer mindestens einer Komponente als prozentualen Teil der Gesamtdauer des Messintervalls anzeigt. Die Zeit wird dabei in Einheiten von 100 Nanosekunden (ns) gemessen. 

Dieser Indikatortyp ist ein Multitimer. Multitimer sind zur Überwachung von mehreren Instanzen einer Komponente bestimmt, z. B. von Prozessoren oder Festplatten.

Formel: ((N1-N0)/(D1-D0)) x 100/B, wobei N1 und N0 Leistungsindikator-Messwerte, D1 und D0 die entsprechenden Zeitmesswerte in Einheiten von 100 Nanosekunden darstellen und die Variable B die Basiszählung für die überwachten Komponenten angibt (mit einem Basiszähler vom Typ CounterMultiBase). Der Zähler stellt den Anteil des Messintervalls dar, während dessen die überwachten Komponenten aktiv waren, und der Nenner stellt die Gesamtdauer des Messintervalls dar.

CounterMultiTimer100NsInverse Ein Prozentindikator, der die Aktivitätsdauer mindestens einer Komponente als prozentualen Teil der Gesamtdauer des Messintervalls anzeigt. Die Zeit wird bei diesem Indikatortyp in Einheiten von 100 Nanosekunden (ns) gemessen. Die Aktivitätszeit wird ermittelt, indem die Zeit gemessen wird, in der die Komponenten nicht aktiv waren, und das Ergebnis vom Produkt von 100 Prozent mit der Anzahl der überwachten Objekte subtrahiert wird. 

Dieser Indikatortyp ist ein inverser Multitimer. Multitimer sind zur Überwachung von mehreren Instanzen einer Komponente bestimmt, z. B. von Prozessoren oder Festplatten. Inverse Zähler messen die Zeit, in der eine Komponente nicht aktiv ist, und leiten die Aktivitätsdauer aus der Messung der Inaktivitätsdauer ab.

Formel: (B-((N1-N0)/(D1-D0))) x 100, wobei der Nenner die Gesamtdauer des Messintervalls darstellt, der Zähler den Zeitraum, während dessen die überwachten Komponenten inaktiv waren, und B die Anzahl der mit einem Basiszähler vom Typ CounterMultiBase überwachten Komponenten.

CounterMultiTimerInverse Ein Prozentindikator, der die Aktivitätsdauer mindestens einer Komponente als prozentualen Teil der Gesamtdauer des Messintervalls anzeigt. Die Aktivitätszeit wird ermittelt, indem die Zeit gemessen wird, in der die Komponenten nicht aktiv waren, und das Ergebnis vom Produkt von 100 Prozent mit der Anzahl der überwachten Objekte subtrahiert wird. 

Dieser Indikatortyp ist ein inverser Multitimer. Multitimer überwachen mehrere Instanzen einer Komponente, z. B. Prozessoren oder Festplatten. Inverse Indikatoren messen die Zeit, in der eine Komponente nicht aktiv ist, und leiten die Aktivitätsdauer aus dieser Messung ab.

Dieser Indikator unterscheidet sich von CounterMultiTimer100NsInverse dadurch, dass die Zeit nicht in Einheiten von 100 Nanosekunden, sondern in Ticks des Systemzeitgebers gemessen wird.

Formel: (B-((N1-N0)/(D1-D0))) x 100, wobei der Nenner die Gesamtdauer des Messintervalls darstellt, der Zähler den Zeitraum, während dessen die überwachten Komponenten inaktiv waren, und B die Anzahl der mit einem Basiszähler vom Typ CounterMultiBase überwachten Komponenten.

CounterTimer Ein Prozentindikator, der die mittlere Aktivitätsdauer einer Komponente als prozentualen Anteil der Gesamtdauer des Messintervalls anzeigt. 

Formel: (N1-N0)/(D1-D0)), wobei N1 und N0 Leistungsindikator-Messwerte und D1 sowie D0 die entsprechenden Zeitmesswerte darstellen. Der Zähler stellt den Anteil des Messintervalls dar, während dessen die überwachten Komponenten aktiv waren, und der Nenner stellt die Gesamtdauer des Messintervalls dar.

CounterTimerInverse Ein Prozentindikator, der den durchschnittlichen prozentualen Anteil der während eines Messintervalls beobachteten Aktivitätsdauer anzeigt. Der Wert dieser Indikatoren wird berechnet, indem der prozentuale Anteil der Aktivitätsdauer des Dienstes von 100 Prozent subtrahiert wird. 

Dies ist ein inverser Indikatortyp. Inverse Indikatoren messen die Zeit, in der eine Komponente nicht aktiv ist, und leiten die Aktivitätsdauer aus dieser Messung ab. Dieser Indikatortyp unterscheidet sich von CounterTimer100NsInv nur dadurch, dass die Zeit nicht in Einheiten von 100 Nanosekunden, sondern in Ticks des Systemzeitgebers gemessen wird.

Formel: (1-((N1-N0)/(D1-D0))) x 100, wobei der Zähler die Inaktivitätsdauer der überwachten Komponenten innerhalb des Messintervalls und der Nenner die Gesamtdauer des Messintervalls darstellt.

CountPerTimeInterval32 Ein Durchschnittsindikator, der die durchschnittliche Länge einer Warteschlange für eine Ressource über einen Zeitraum wiedergibt. Er zeigt den Quotienten aus der Differenz der während der letzten zwei Messintervalle beobachteten Warteschlangenlängen und der Dauer des Intervalls an. Dieser Typ eines Indikators wird i. d. R. zum Überwachen der Anzahl der Elemente verwendet, die sich in der Warteschlange oder im Wartezustand befinden. 

Formel: (N1-N0)/(D1-D0), wobei der Zähler die Anzahl der Elemente in der Warteschlange und der Nenner die Gesamtdauer des letzten Messintervalls darstellt.

CountPerTimeInterval64 Ein Durchschnittsindikator, der die durchschnittliche Länge einer Warteschlange für eine Ressource über einen Zeitraum wiedergibt. Zähler dieses Typs zeigen den Quotienten aus der Differenz der während der letzten zwei Messintervalle beobachteten Warteschlangenlängen und der Dauer des Intervalls an. Dieser Indikatortyp unterscheidet sich von CountPerTimeInterval32 nur dadurch, dass er größere Felder verwendet, um größere Werte verarbeiten zu können. Dieser Typ eines Indikators wird i. d. R. zum Überwachen umfangreicher oder sehr zahlreicher Elemente verwendet, die sich in der Warteschlange oder im Wartezustand befinden. 

Formel: (N1-N0)/(D1-D0), wobei der Zähler die Anzahl der Elemente in einer Warteschlange und der Nenner die Gesamtdauer des Messintervalls darstellt.

ElapsedTime Ein Differenzzeitgeber, der die Gesamtzeit zwischen dem Startzeitpunkt der Komponente oder des Prozesses und dem Zeitpunkt der Berechnung dieses Werts anzeigt. 

Formel: (D0-N0)/F, wobei D 0 die aktuelle Zeit, N0 die Startzeit des Objekts und F die Anzahl der Zeiteinheiten pro Sekunde darstellt. Durch den Faktor F wird das Ergebnis in Sekunden umgerechnet.

Zu den Indikatoren dieses Typs gehört System\ Systembetriebszeit.

NumberOfItems32 Ein unmittelbarer Indikator, der den zuletzt beobachteten Wert anzeigt. Wird z. B. verwendet, um einen einfachen Zähler für Elemente oder Operationen zu verwalten. 

Formel: Keine. Zeigt keinen Durchschnittswert an, sondern die unformatierten Daten in dem Zustand, in dem sie erfasst werden.

Zu den Indikatoren dieses Typs gehört Speicher\ Verfügbare Bytes.

NumberOfItems64 Ein unmittelbarer Indikator, der den zuletzt beobachteten Wert anzeigt. Wird z. B. verwendet, um einen einfachen Zähler für eine sehr große Anzahl von Elementen oder Operationen zu verwalten. Er unterscheidet sich von NumberOfItems32 nur dadurch, dass er größere Felder verwendet, um größere Werte verarbeiten zu können. 

Formel: Keine. Zeigt keinen Durchschnittswert an, sondern die unformatierten Daten in dem Zustand, in dem sie erfasst werden.

NumberOfItemsHEX32 Ein unmittelbarer Indikator, der den zuletzt beobachteten Wert im Hexadezimalformat anzeigt. Wird z. B. verwendet, um einen einfachen Zähler für Elemente oder Operationen zu verwalten. 

Formel: Keine. Zeigt keinen Durchschnittswert an, sondern die unformatierten Daten in dem Zustand, in dem sie erfasst werden.

NumberOfItemsHEX64 Ein unmittelbarer Indikator, der den zuletzt beobachteten Wert anzeigt. Wird z. B. verwendet, um einen einfachen Zähler für eine sehr große Anzahl von Elementen oder Operationen zu verwalten. Er unterscheidet sich von NumberOfItemsHEX32 nur dadurch, dass er größere Felder verwendet, um größere Werte verarbeiten zu können. 

Formel: Keine. Zeigt keinen Durchschnittswert an, sondern die unformatierten Daten in dem Zustand, in dem sie erfasst werden.

RateOfCountsPerSecond32 Ein Differenzindikator, der die mittlere Anzahl der pro Sekunde des Messintervalls durchgeführten Operationen anzeigt. Indikatoren dieses Typs messen die Zeit in Ticks der Systemuhr. 

Formel: (N1-N0)/((D1-D0)/F), wobei N1 und N0 Leistungsindikator-Messwerte sowie D1 und D0 die entsprechenden Zeitmesswerte darstellen und F für die Anzahl der Ticks pro Sekunde steht. Der Zähler stellt die Anzahl der im letzten Messintervall durchgeführten Operationen dar, der Nenner die Anzahl der Ticks im letzten Messintervall, und F ist die Tickfrequenz. Durch den Faktor F wird das Ergebnis in Sekunden umgerechnet.

Zu den Indikatoren dieses Typs gehört System\ Lesevorgänge/s.

RateOfCountsPerSecond64 Ein Differenzindikator, der die mittlere Anzahl der pro Sekunde des Messintervalls durchgeführten Operationen anzeigt. Indikatoren dieses Typs messen die Zeit in Ticks der Systemuhr. Dieser Indikatortyp unterscheidet sich von RateOfCountsPerSecond32 nur dadurch, dass er größere Felder verwendet, um größere Werte verarbeiten und eine große Anzahl von Elementen oder Operationen pro Sekunde verfolgen zu können, z. B. eine Byte-Übertragungsrate. 

Formel: (N1-N0)/((D1-D0)/F), wobei N1 und N0 Leistungsindikator-Messwerte sowie D1 und D0 die entsprechenden Zeitmesswerte darstellen und F für die Anzahl der Ticks pro Sekunde steht. Der Zähler stellt die Anzahl der im letzten Messintervall durchgeführten Operationen dar, der Nenner die Anzahl der Ticks im letzten Messintervall, und F ist die Tickfrequenz. Durch den Faktor F wird das Ergebnis in Sekunden umgerechnet.

Zu den Indikatoren dieses Typs gehört System\ Bytes gelesen/s.

RawBase Ein Basisindikator, in dem der Nenner eines Indikators gespeichert wird, der einen arithmetischen Bruch darstellt. Stellen Sie sicher, dass dieser Wert größer als 0 ist, bevor Sie ihn als Nenner in einer RawFraction-Wertberechnung verwenden. 
RawFraction Ein unmittelbarer Prozentindikator, der das Verhältnis einer Teilmenge zur zugehörigen Menge in Prozent anzeigt. Es kann z. B. die Anzahl der auf einer Festplatte verwendeten Bytes mit der Gesamtzahl der Bytes auf der Festplatte verglichen werden. Indikatoren dieses Typs zeigen keinen durchschnittlichen Wert über eine Zeitspanne an, sondern den aktuellen Prozentwert. 

Formel: (N0/D0) x 100, wobei D0 ein (mithilfe eines Basiszählers vom Typ RawBase) gemessenes Attribut und N0 eine Komponente dieses Attributs darstellt.

Zu den Indikatoren dieses Typs gehört Auslagerungsdatei\ Maximale Belegung (%).

SampleBase Ein Basisindikator, der die Anzahl der Samplingabtastungen speichert und als Nenner der Samplingbruchzahl verwendet wird. Die Samplingbruchzahl ist die Anzahl der Messungen, die für eine Messabtastung 1 (oder true) ergeben haben. Stellen Sie sicher, dass dieser Wert größer als 0 ist, bevor Sie ihn in einer Berechnung von SampleCounter oder SampleFraction als Nenner verwenden. 
SampleCounter Ein Durchschnittsindikator, der die durchschnittliche Anzahl der in einer Sekunde durchgeführten Operationen anzeigt. Bei einem Indikator dieses Typs ergibt eine Samplingabtastung entweder 1 oder 0. Bei den Indikatordaten handelt es sich um die Anzahl der gemessenen Einsen. Die Zeiteinheit ist dabei ein Tick des Systemzeitgebers. 

Formel: (N 1 – N 0) / ((D 1 – D 0) / F), wobei der Zähler (N) die Anzahl der abgeschlossenen Vorgänge, der Nenner (D) die verstrichene Zeit in Ticks des Systemleistungs-Zeitgebers und F die Anzahl der in einer Sekunde verstrichenen Ticks darstellen. Durch den Faktor F wird das Ergebnis in Sekunden umgerechnet.

SampleFraction Ein Prozentindikator, der das durchschnittliche Verhältnis der Anzahl der Erfolge und der Gesamtzahl der Operationen während der letzten zwei Messintervalle angibt. 

Formel: ((N1-N0)/(D1-D0)) x 100, wobei der Zähler die Anzahl der erfolgreichen Operationen während des letzten Messintervalls und der Nenner die geänderte Anzahl der im Messintervall durchgeführten Operationen (des gemessenen Typs) unter Verwendung von Zählern vom Typ SampleBase darstellt.

Zu den Indikatoren dieses Typs gehört Cache\ Festsetzung - Lesetreffer (%).

Timer100Ns Ein Prozentindikator, der die Aktivitätsdauer einer Komponente als prozentualen Anteil der Gesamtdauer des Messintervalls darstellt. Die Zeit wird dabei in Einheiten von 100 Nanosekunden (ns) gemessen. Zeiger dieses Typs sind zur Messung der Aktivität einer einzelnen Komponente vorgesehen. 

Formel: (N1-N0)/(D1-D0) x 100, wobei der Zähler den Anteil des Messintervalls, innerhalb dessen die überwachten Komponenten aktiv waren, und der Nenner die Gesamtdauer des Messintervalls darstellt.

Zu den Indikatoren dieses Typs gehört Prozessor\ Benutzerzeit (%).

Timer100NsInverse Ein Prozentindikator, der den durchschnittlichen prozentualen Anteil der während eines Messintervalls beobachteten Aktivitätsdauer anzeigt. 

Dies ist ein inverser Indikator. Bei Indikatoren dieses Typs wird die Aktivitätszeit berechnet, indem der prozentuale Anteil der gemessenen Inaktivitätsdauer des Dienstes von 100 Prozent subtrahiert wird.

Formel: (1-((N1-N0)/(D1-D0))) x 100, wobei der Zähler die Inaktivitätsdauer der überwachten Komponenten innerhalb des Messintervalls und der Nenner die Gesamtdauer des Messintervalls darstellt.

Zu den Indikatoren dieses Typs gehört Prozessor\ Prozessorzeit (%).

Hinweise

Einige Indikatortypen stellen unformatierte Daten dar, wohingegen andere Indikatortypen andere berechnete Werte darstellen, die auf einer oder mehreren Indikatormessungen beruhen. Die folgenden Kategorien klassifizieren die verfügbaren Typen von Leistungsindikatoren.

  • Durchschnitt: Regelmäßige Messung eines Werts und Anzeige des Durchschnitts der letzten zwei Messungen. Jedem Durchschnittsindikator ist ein Basisindikator zugeordnet, der die Anzahl der beteiligten Messungen zählt.

  • Differenz: Subtraktion der letzten Messung von der vorigen und Anzeige der Differenz, wenn diese positiv ist. Anzeige von 0, wenn die Differenz negativ ist.

  • Unmittelbar: Anzeige der letzten Messung.

  • Prozent: Anzeige der berechneten Werte als Prozentwerte.

  • Rate: Wiederholte Messung von Ereignissen und Division der Indikatorwertedifferenz durch die Zeitdifferenz, sodass eine Aktivitätsrate angezeigt wird.

Beim Sampling von Daten für Leistungsindikatoren können Indikatortypen, die durchschnittliche Werte darstellen, für Ihre Zwecke sinnvoller als die unberechneten Werte sein. Der Indikator für unformatierte Daten NumberOfItems64 kann z. B. Daten ergeben, die für die einzelnen Messungen annähernd zufällig erscheinen. Die Formel für eine Durchschnittsberechnung der Werte, die der Zähler zurückgibt, lautet (X0+X1+…+Xn)/n, wobei jedes Xi für eine Basiszählermessung steht.

Ratenindikatoren sind Durchschnittsindikatoren ähnlich. Sie sind aber in Fällen zu empfehlen, in denen die Rate während der Verwendung einer Ressource ansteigt. Eine Formel zur schnellen Berechnung des Durchschnitts lautet ((Xn-X0)/(Tn-T0))/Häufigkeit, wobei jedes Xi für eine Zählermessung und jedes Ti für den Zeitpunkt der entsprechenden Messung steht. Das Ergebnis ist die durchschnittliche Verwendung pro Sekunde.

Hinweis

Wenn nicht anders angegeben, wird die Zeit in der Basiseinheit Sekunden angegeben.

Beim Instrumentieren von Anwendungen (Erstellen und Programmieren von benutzerdefinierten Leistungsindikatoren) verwenden Sie möglicherweise Leistungsindikatortypen, die einen bei Berechnungen verwendeten entsprechenden Basisindikator benötigen. In der von der Anwendung verwendeten CounterCreationDataCollection-Auflistung muss der Basiszähler direkt auf den zugehörigen Zähler folgen. In der folgenden Tabelle sind die Basisindikatortypen mit den entsprechenden Leistungsindikatortypen aufgeführt.

Basisindikatortyp

Leistungsindikatortypen

AverageBase

AverageTimer32

AverageCount64

CounterMultiBase

CounterMultiTimer

CounterMultiTimerInverse

CounterMultiTimer100Ns

CounterMultiTimer100NsInverse

RawBase

RawFraction

SampleBase

SampleCounter

SampleFraction

Beispiel

Die folgenden Beispiele veranschaulichen verschiedene Zählertypen in der PerformanceCounterType-Enumeration.

AverageCount64

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics

 _

Public Class App
   
   Private Shared PC As PerformanceCounter
   Private Shared BPC As PerformanceCounter
   
   
   Public Shared Sub Main()
      
      Dim samplesList As New ArrayList()
      
      SetupCategory()
      CreateCounters()
      CollectSamples(samplesList)
      CalculateResults(samplesList)
   End Sub 'Main
    
   
   
   Private Shared Function SetupCategory() As Boolean
      If Not PerformanceCounterCategory.Exists("AverageCounter64SampleCategory") Then
         
         Dim CCDC As New CounterCreationDataCollection()
         
         ' Add the counter.
         Dim averageCount64 As New CounterCreationData()
         averageCount64.CounterType = PerformanceCounterType.AverageCount64
         averageCount64.CounterName = "AverageCounter64Sample"
         CCDC.Add(averageCount64)
         
         ' Add the base counter.
         Dim averageCount64Base As New CounterCreationData()
         averageCount64Base.CounterType = PerformanceCounterType.AverageBase
         averageCount64Base.CounterName = "AverageCounter64SampleBase"
         CCDC.Add(averageCount64Base)
         
         ' Create the category.
         PerformanceCounterCategory.Create("AverageCounter64SampleCategory", "Demonstrates usage of the AverageCounter64 performance counter type.", CCDC)
         
         Return True
      Else
         Console.WriteLine("Category exists - AverageCounter64SampleCategory")
         Return False
      End If
   End Function 'SetupCategory
   
   
   Private Shared Sub CreateCounters()
      ' Create the counters.

      PC = New PerformanceCounter("AverageCounter64SampleCategory", "AverageCounter64Sample", False)
      
      BPC = New PerformanceCounter("AverageCounter64SampleCategory", "AverageCounter64SampleBase", False)
      
      
      PC.RawValue = 0
      BPC.RawValue = 0
   End Sub 'CreateCounters
   
   
   Private Shared Sub CollectSamples(samplesList As ArrayList)
      
      Dim r As New Random(DateTime.Now.Millisecond)
      
      ' Loop for the samples.
      Dim j As Integer
      For j = 0 To 99
         
         Dim value As Integer = r.Next(1, 10)
         Console.Write((j + " = " + value))
         
         PC.IncrementBy(value)
         
         BPC.Increment()
         
         If j Mod 10 = 9 Then
            OutputSample(PC.NextSample())
            samplesList.Add(PC.NextSample())
         Else
            Console.WriteLine()
         End If 
         System.Threading.Thread.Sleep(50)
      Next j
   End Sub 'CollectSamples
    
   
   Private Shared Sub CalculateResults(samplesList As ArrayList)
      Dim i As Integer
      For i = 0 To (samplesList.Count - 1) - 1
         ' Output the sample.
         OutputSample(CType(samplesList(i), CounterSample))
         OutputSample(CType(samplesList((i + 1)), CounterSample))
         
         ' Use .NET to calculate the counter value.
         Console.WriteLine((".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
         
         ' Calculate the counter value manually.
         Console.WriteLine(("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
      Next i
   End Sub 'CalculateResults
   
   
   
   
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   '    Description - This counter type shows how many items are processed, on average,
   '        during an operation. Counters of this type display a ratio of the items 
   '        processed (such as bytes sent) to the number of operations completed. The  
   '        ratio is calculated by comparing the number of items processed during the 
   '        last interval to the number of operations completed during the last interval. 
   ' Generic type - Average
   '    Formula - (N1 - N0) / (D1 - D0), where the numerator (N) represents the number 
   '        of items processed during the last sample interval and the denominator (D) 
   '        represents the number of operations completed during the last two sample 
   '        intervals. 
   '    Average (Nx - N0) / (Dx - D0)  
   '    Example PhysicalDisk\ Avg. Disk Bytes/Transfer 
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   Private Shared Function MyComputeCounterValue(s0 As CounterSample, s1 As CounterSample) As [Single]
      Dim numerator As [Single] = CType(s1.RawValue, [Single]) - CType(s0.RawValue, [Single])
      Dim denomenator As [Single] = CType(s1.BaseValue, [Single]) - CType(s0.BaseValue, [Single])
      Dim counterValue As [Single] = numerator / denomenator
      Return counterValue
   End Function 'MyComputeCounterValue
   
   
   ' Output information about the counter sample.
   Private Shared Sub OutputSample(s As CounterSample)
      Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
      Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
      Console.WriteLine(("   BaseValue        = " + s.BaseValue))
      Console.WriteLine(("   CounterFrequency = " + s.CounterFrequency))
      Console.WriteLine(("   CounterTimeStamp = " + s.CounterTimeStamp))
      Console.WriteLine(("   CounterType      = " + s.CounterType))
      Console.WriteLine(("   RawValue         = " + s.RawValue))
      Console.WriteLine(("   SystemFrequency  = " + s.SystemFrequency))
      Console.WriteLine(("   TimeStamp        = " + s.TimeStamp))
      Console.WriteLine(("   TimeStamp100nSec = " + s.TimeStamp100nSec))
      Console.WriteLine("++++++++++++++++++++++")
   End Sub 'OutputSample
End Class 'App
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;

public class App {

    private static PerformanceCounter PC;
    private static PerformanceCounter BPC;

    public static void Main()
    {   
    
        ArrayList samplesList = new ArrayList();

        SetupCategory();
        CreateCounters();
        CollectSamples(samplesList);
        CalculateResults(samplesList);

    }
    

    private static bool SetupCategory()
    {       
        if ( !PerformanceCounterCategory.Exists("AverageCounter64SampleCategory") ) 
        {

            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();
            
            // Add the counter.
            CounterCreationData averageCount64 = new CounterCreationData();
            averageCount64.CounterType = PerformanceCounterType.AverageCount64;
            averageCount64.CounterName = "AverageCounter64Sample";
            CCDC.Add(averageCount64);
            
            // Add the base counter.
            CounterCreationData averageCount64Base = new CounterCreationData();
            averageCount64Base.CounterType = PerformanceCounterType.AverageBase;
            averageCount64Base.CounterName = "AverageCounter64SampleBase";
            CCDC.Add(averageCount64Base);

            // Create the category.
            PerformanceCounterCategory.Create("AverageCounter64SampleCategory", 
                "Demonstrates usage of the AverageCounter64 performance counter type.", 
                CCDC);
                
            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - AverageCounter64SampleCategory");
            return(false);
        }
    }
    
    private static void CreateCounters()
    {
        // Create the counters.

        PC = new PerformanceCounter("AverageCounter64SampleCategory", 
            "AverageCounter64Sample", 
            false);
        

        BPC = new PerformanceCounter("AverageCounter64SampleCategory", 
            "AverageCounter64SampleBase", 
            false);
        
        
        PC.RawValue=0;
        BPC.RawValue=0;
    }
    
    private static void CollectSamples(ArrayList samplesList)
    {
        
        Random r = new Random( DateTime.Now.Millisecond );

        // Loop for the samples.
        for (int j = 0; j < 100; j++) 
        {
            
            int value = r.Next(1, 10);
            Console.Write(j + " = " + value);

            PC.IncrementBy(value);

            BPC.Increment();

            if ((j % 10) == 9) 
            {
                OutputSample(PC.NextSample());
                samplesList.Add( PC.NextSample() );
            }
            else
                Console.WriteLine();
            
            System.Threading.Thread.Sleep(50);
        }

    }
    
    private static void CalculateResults(ArrayList samplesList)
    {
        for(int i = 0; i < (samplesList.Count - 1); i++)
        {
            // Output the sample.
            OutputSample( (CounterSample)samplesList[i] );
            OutputSample( (CounterSample)samplesList[i+1] );

            // Use .NET to calculate the counter value.
            Console.WriteLine(".NET computed counter value = " +
                CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );

            // Calculate the counter value manually.
            Console.WriteLine("My computed counter value = " + 
                MyComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );

        }
    }
    
    
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    //  Description - This counter type shows how many items are processed, on average,
    //      during an operation. Counters of this type display a ratio of the items 
    //      processed (such as bytes sent) to the number of operations completed. The  
    //      ratio is calculated by comparing the number of items processed during the 
    //      last interval to the number of operations completed during the last interval. 
    // Generic type - Average
    //      Formula - (N1 - N0) / (D1 - D0), where the numerator (N) represents the number 
    //      of items processed during the last sample interval and the denominator (D) 
    //      represents the number of operations completed during the last two sample 
    //      intervals. 
    //  Average (Nx - N0) / (Dx - D0)  
    //  Example PhysicalDisk\ Avg. Disk Bytes/Transfer 
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
    {
        Single numerator = (Single)s1.RawValue - (Single)s0.RawValue;
        Single denomenator = (Single)s1.BaseValue - (Single)s0.BaseValue;
        Single counterValue = numerator / denomenator;
        return(counterValue);
    }
        
    // Output information about the counter sample.
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("\r\n+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.BaseValue);
        Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
        Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
        Console.WriteLine("   CounterType      = " + s.CounterType);
        Console.WriteLine("   RawValue         = " + s.RawValue);
        Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
        Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
        Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
        Console.WriteLine("++++++++++++++++++++++");
    }
}
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
using namespace System::Diagnostics;

// Output information about the counter sample.
void OutputSample( CounterSample s )
{
   Console::WriteLine( "\r\n+++++++++++" );
   Console::WriteLine( "Sample values - \r\n" );
   Console::WriteLine( "   BaseValue        = {0}", s.BaseValue );
   Console::WriteLine( "   CounterFrequency = {0}", s.CounterFrequency );
   Console::WriteLine( "   CounterTimeStamp = {0}", s.CounterTimeStamp );
   Console::WriteLine( "   CounterType      = {0}", s.CounterType );
   Console::WriteLine( "   RawValue         = {0}", s.RawValue );
   Console::WriteLine( "   SystemFrequency  = {0}", s.SystemFrequency );
   Console::WriteLine( "   TimeStamp        = {0}", s.TimeStamp );
   Console::WriteLine( "   TimeStamp100nSec = {0}", s.TimeStamp100nSec );
   Console::WriteLine( "++++++++++++++++++++++" );
}

//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
//    Description - This counter type shows how many items are processed, on average,
//        during an operation. Counters of this type display a ratio of the items 
//        processed (such as bytes sent) to the number of operations completed. The  
//        ratio is calculated by comparing the number of items processed during the 
//        last interval to the number of operations completed during the last interval. 
// Generic type - Average
//      Formula - (N1 - N0) / (D1 - D0), where the numerator (N) represents the number 
//        of items processed during the last sample interval and the denominator (D) 
//        represents the number of operations completed during the last two sample 
//        intervals. 
//    Average (Nx - N0) / (Dx - D0)  
//    Example PhysicalDisk\ Avg. Disk Bytes/Transfer 
//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
float MyComputeCounterValue( CounterSample s0, CounterSample s1 )
{
   float numerator = (float)s1.RawValue - (float)s0.RawValue;
   float denomenator = (float)s1.BaseValue - (float)s0.BaseValue;
   float counterValue = numerator / denomenator;
   return counterValue;
}

bool SetupCategory()
{
   if (  !PerformanceCounterCategory::Exists( "AverageCounter64SampleCategory" ) )
   {
      CounterCreationDataCollection^ CCDC = gcnew CounterCreationDataCollection;
      
      // Add the counter.
      CounterCreationData^ averageCount64 = gcnew CounterCreationData;
      averageCount64->CounterType = PerformanceCounterType::AverageCount64;
      averageCount64->CounterName = "AverageCounter64Sample";
      CCDC->Add( averageCount64 );
      
      // Add the base counter.
      CounterCreationData^ averageCount64Base = gcnew CounterCreationData;
      averageCount64Base->CounterType = PerformanceCounterType::AverageBase;
      averageCount64Base->CounterName = "AverageCounter64SampleBase";
      CCDC->Add( averageCount64Base );
      
      // Create the category.
      PerformanceCounterCategory::Create( "AverageCounter64SampleCategory", "Demonstrates usage of the AverageCounter64 performance counter type.", CCDC );
      return (true);
   }
   else
   {
      Console::WriteLine( "Category exists - AverageCounter64SampleCategory" );
      return (false);
   }
}

void CreateCounters( PerformanceCounter^% PC, PerformanceCounter^% BPC )
{
   
   // Create the counters.
   PC = gcnew PerformanceCounter( "AverageCounter64SampleCategory","AverageCounter64Sample",false );

   BPC = gcnew PerformanceCounter( "AverageCounter64SampleCategory","AverageCounter64SampleBase",false );
   PC->RawValue = 0;
   BPC->RawValue = 0;
}

void CollectSamples( ArrayList^ samplesList, PerformanceCounter^ PC, PerformanceCounter^ BPC )
{
   Random^ r = gcnew Random( DateTime::Now.Millisecond );

   // Loop for the samples.
   for ( int j = 0; j < 100; j++ )
   {
      int value = r->Next( 1, 10 );
      Console::Write( "{0} = {1}", j, value );
      PC->IncrementBy( value );
      BPC->Increment();
      if ( (j % 10) == 9 )
      {
         OutputSample( PC->NextSample() );
         samplesList->Add( PC->NextSample() );
      }
      else
            Console::WriteLine();
      System::Threading::Thread::Sleep( 50 );
   }
}

void CalculateResults( ArrayList^ samplesList )
{
   for ( int i = 0; i < (samplesList->Count - 1); i++ )
   {
      // Output the sample.
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i ]) );
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) );
      
      // Use .NET to calculate the counter value.
      Console::WriteLine( ".NET computed counter value = {0}", CounterSampleCalculator::ComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );
      
      // Calculate the counter value manually.
      Console::WriteLine( "My computed counter value = {0}", MyComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );
   }
}

int main()
{
   ArrayList^ samplesList = gcnew ArrayList;
   PerformanceCounter^ PC;
   PerformanceCounter^ BPC;
   SetupCategory();
   CreateCounters( PC, BPC );
   CollectSamples( samplesList, PC, BPC );
   CalculateResults( samplesList );
}
import System.*;  
import System.Collections.*;  
import System.Collections.Specialized.*;  
import System.Diagnostics.*;  

public class App
{
    private static PerformanceCounter pc;
    private static PerformanceCounter bpc;

    public static void main(String[] args)
    {
        ArrayList samplesList = new ArrayList();
        SetupCategory();
        CreateCounters();
        CollectSamples(samplesList);
        CalculateResults(samplesList);
    } //main

    private static boolean SetupCategory()
    {
        if (!(PerformanceCounterCategory.Exists(
            "AverageCounter64SampleCategory"))) {
            CounterCreationDataCollection ccdc = 
                new CounterCreationDataCollection();
            // Add the counter.
            CounterCreationData averageCount64 = new CounterCreationData();
            averageCount64.
                set_CounterType(PerformanceCounterType.AverageCount64);
            averageCount64.set_CounterName("AverageCounter64Sample");
            ccdc.Add(averageCount64);
            // Add the base counter.
            CounterCreationData averageCount64Base = new CounterCreationData();
            averageCount64Base.set_CounterType(PerformanceCounterType.
                AverageBase);
            averageCount64Base.set_CounterName("AverageCounter64SampleBase");
            ccdc.Add(averageCount64Base);
            // Create the category.
            PerformanceCounterCategory.Create("AverageCounter64SampleCategory",
                "Demonstrates usage of the AverageCounter64 performance "
                + "counter type.", ccdc);
            return true;
        }
        else {
            Console.WriteLine("Category exists - AverageCounter64SampleCategory");
            return false;
        }
    } //SetupCategory

    private static void CreateCounters()
    {
        // Create the counters.
        pc = new PerformanceCounter("AverageCounter64SampleCategory",
            "AverageCounter64Sample", false);
        bpc = new PerformanceCounter("AverageCounter64SampleCategory",
            "AverageCounter64SampleBase", false);
        pc.set_RawValue(0);
        bpc.set_RawValue(0);
    } //CreateCounters

    private static void CollectSamples(ArrayList samplesList)
    {
        Random r = new Random(DateTime.get_Now().get_Millisecond());
        // Loop for the samples.
        for (int j = 0; j < 100; j++) {
            int value = r.Next(1, 10);
            Console.Write(j + " = " + value);
            pc.IncrementBy(value);
            bpc.Increment();

            if (j % 10 == 9) {
                OutputSample(pc.NextSample());
                samplesList.Add(pc.NextSample());
            }
            else {
                Console.WriteLine();
            }
            System.Threading.Thread.Sleep(50);
        }
    } //CollectSamples

    private static void CalculateResults(ArrayList samplesList)
    {
        for (int i = 0; i < samplesList.get_Count() - 1; i++) {
            // Output the sample.
            OutputSample((CounterSample)samplesList.get_Item(i));
            OutputSample((CounterSample)samplesList.get_Item(i + 1));
            // Use.NET to calculate the counter value.
            Console.WriteLine(".NET computed counter value = " 
                + CounterSampleCalculator.ComputeCounterValue((CounterSample)
                samplesList.get_Item(i), 
                (CounterSample)samplesList.get_Item(i + 1)));
            // Calculate the counter value manually.
            Console.WriteLine("My computed counter value = "
                + MyComputeCounterValue((CounterSample)samplesList.get_Item(i),
                (CounterSample)samplesList.get_Item(i + 1)));
        }
    } //CalculateResults

    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    //++++++++
    //    Description - This counter type shows how many items are processed, 
    //        on average,during an operation.Counters of this type display a
    //        ratio of the items processed (such as bytes sent) to the number
    //        of operations completed. The ratio is calculated by comparing
    //        the number of items processed during the last interval to the 
    //        number of operations completed during the last interval. 
    //  Generic type - Average
    //        Formula - (N1 - N0) / (D1 - D0), where the numerator (N) 
    //        represents the number of items processed during the last sample
    //        interval and the denominator (D) represents the number of
    //        operations completed during the last two sample 
    //        intervals. 
    //    Average (Nx - N0) / (Dx - D0)  
    //    Example PhysicalDisk\ Avg. Disk Bytes/Transfer 
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    //++++++++
    private static float MyComputeCounterValue(CounterSample s0,
        CounterSample s1)
    {
        float numerator = (float)s1.get_RawValue() - (float)s0.get_RawValue();
        float denomenator = (float)s1.get_BaseValue() - (float)s0.
            get_BaseValue();
        float counterValue = numerator / denomenator;
        return counterValue;
    } //MyComputeCounterValue

    // Output information about the counter sample.
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("\r\n+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.get_BaseValue());
        Console.WriteLine("   CounterFrequency = " + s.get_CounterFrequency());
        Console.WriteLine("   CounterTimeStamp = " + s.get_CounterTimeStamp());
        Console.WriteLine("   CounterType      = " + s.get_CounterType());
        Console.WriteLine("   RawValue         = " + s.get_RawValue());
        Console.WriteLine("   SystemFrequency  = " + s.get_SystemFrequency());
        Console.WriteLine("   TimeStamp        = " + s.get_TimeStamp());
        Console.WriteLine("   TimeStamp100nSec = " + s.get_TimeStamp100nSec());
        Console.WriteLine("++++++++++++++++++++++");
    } //OutputSample
} //App

AverageTimer32

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic

Public Class App

    Private Const categoryName As String = "AverageTimer32SampleCategory"
    Private Const counterName As String = "AverageTimer32Sample"
    Private Const baseCounterName As String = "AverageTimer32SampleBase"

    Private Shared PC As PerformanceCounter
    Private Shared BPC As PerformanceCounter


    Public Shared Sub Main()
        Dim samplesList As New ArrayList()

        SetupCategory()
        CreateCounters()
        CollectSamples(samplesList)
        CalculateResults(samplesList)
    End Sub


    Private Shared Function SetupCategory() As Boolean

        If Not PerformanceCounterCategory.Exists(categoryName) Then

            Dim CCDC As New CounterCreationDataCollection()

            ' Add the counter.
            Dim averageTimer32 As New CounterCreationData()
            averageTimer32.CounterType = PerformanceCounterType.AverageTimer32
            averageTimer32.CounterName = counterName
            CCDC.Add(averageTimer32)

            ' Add the base counter.
            Dim averageTimer32Base As New CounterCreationData()
            averageTimer32Base.CounterType = PerformanceCounterType.AverageBase
            averageTimer32Base.CounterName = baseCounterName
            CCDC.Add(averageTimer32Base)

            ' Create the category.
            PerformanceCounterCategory.Create( _
               categoryName, _
               "Demonstrates usage of the AverageTimer32 performance counter type", _
                 PerformanceCounterCategoryType.SingleInstance, CCDC)

            Console.WriteLine("Category created - " + categoryName)

            Return True
        Else
            Console.WriteLine(("Category exists - " + _
               categoryName))
            Return False
        End If
    End Function


    Private Shared Sub CreateCounters()
        ' Create the counters.
        PC = New PerformanceCounter(categoryName, _
              counterName, False)

        BPC = New PerformanceCounter(categoryName, _
              baseCounterName, False)

        PC.RawValue = 0
        BPC.RawValue = 0
    End Sub


    Private Shared Sub CollectSamples(ByVal samplesList As ArrayList)

        Dim r As New Random(DateTime.Now.Millisecond)

        ' Loop for the samples.
        Dim i As Integer
        For i = 0 To 9

            PC.RawValue = Stopwatch.GetTimeStamp()

            BPC.IncrementBy(10)

            System.Threading.Thread.Sleep(1000)
            Console.WriteLine(("Next value = " + PC.NextValue().ToString()))
            samplesList.Add(PC.NextSample())
        Next i
    End Sub


    Private Shared Sub CalculateResults(ByVal samplesList As ArrayList)
        Dim i As Integer
        Dim sample1 As CounterSample
        Dim sample2 As CounterSample
        For i = 0 To (samplesList.Count - 1) - 1
            ' Output the sample.
            sample1 = CType(samplesList(i), CounterSample)
            sample2 = CType(samplesList(i + 1), CounterSample)
            OutputSample(sample1)
            OutputSample(sample2)

            ' Use .NET to calculate the counter value.
            Console.WriteLine((".NET computed counter value = " _
               + CounterSample.Calculate(sample1, sample2).ToString()))

            ' Calculate the counter value manually.
            Console.WriteLine(("My computed counter value = " _
               + MyComputeCounterValue(sample1, sample2).ToString()))

        Next i
    End Sub


    '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
    ' PERF_AVERAGE_TIMER
    '  Description - This counter type measures the time it takes, on 
    '     average, to complete a process or operation. Counters of this
    '     type display a ratio of the total elapsed time of the sample 
    '     interval to the number of processes or operations completed
    '     during that time. This counter type measures time in ticks 
    '     of the system clock. The F variable represents the number of
    '     ticks per second. The value of F is factored into the equation
    '     so that the result can be displayed in seconds.
    '
    '  Generic type - Average
    '
    '  Formula - ((N1 - N0) / F) / (D1 - D0), where the numerator (N)
    '     represents the number of ticks counted during the last 
    '     sample interval, F represents the frequency of the ticks, 
    '     and the denominator (D) represents the number of operations
    '     completed during the last sample interval.
    '
    '  Average - ((Nx - N0) / F) / (Dx - D0)
    '
    '  Example - PhysicalDisk\ Avg. Disk sec/Transfer 
    '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
    Private Shared Function MyComputeCounterValue( _
    ByVal s0 As CounterSample, _
    ByVal s1 As CounterSample) As Single
        Dim n1 As Int64 = s1.RawValue
        Dim n0 As Int64 = s0.RawValue
        Dim f As Decimal = CType(s1.SystemFrequency, Decimal)
        Dim d1 As Int64 = s1.BaseValue
        Dim d0 As Int64 = s0.BaseValue

        Dim numerator As Double = System.Convert.ToDouble(n1 - n0)
        Dim denominator As Double = System.Convert.ToDouble(d1 - d0)
        Dim counterValue As Single = CType(numerator, Single)
        counterValue = counterValue / CType(f, Single)
        counterValue = counterValue / CType(denominator, Single)

        Return counterValue
    End Function


    ' Output information about the counter sample.
    Private Shared Sub OutputSample(ByVal s As CounterSample)
        Console.WriteLine("+++++++++++")
        Console.WriteLine("Sample values - " + ControlChars.Cr _
              + ControlChars.Lf)
        Console.WriteLine(("   CounterType      = " + _
              s.CounterType.ToString()))
        Console.WriteLine(("   RawValue         = " + _
              s.RawValue.ToString()))
        Console.WriteLine(("   BaseValue        = " _
              + s.BaseValue.ToString()))
        Console.WriteLine(("   CounterFrequency = " + _
              s.CounterFrequency.ToString()))
        Console.WriteLine(("   CounterTimeStamp = " + _
              s.CounterTimeStamp.ToString()))
        Console.WriteLine(("   SystemFrequency  = " + _
              s.SystemFrequency.ToString()))
        Console.WriteLine(("   TimeStamp        = " + _
              s.TimeStamp.ToString()))
        Console.WriteLine(("   TimeStamp100nSec = " + _
              s.TimeStamp100nSec.ToString()))
        Console.WriteLine("++++++++++++++++++++++")
    End Sub


End Class
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Runtime.InteropServices;

public class App
{

    private static PerformanceCounter PC;
    private static PerformanceCounter BPC;

    private const String categoryName = "AverageTimer32SampleCategory";
    private const String counterName = "AverageTimer32Sample";
    private const String baseCounterName = "AverageTimer32SampleBase";

    public static void Main()
    {
        ArrayList samplesList = new ArrayList();

        SetupCategory();
        CreateCounters();
        CollectSamples(samplesList);
        CalculateResults(samplesList);
    }




    private static bool SetupCategory()
    {

        if (!PerformanceCounterCategory.Exists(categoryName))
        {

            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData averageTimer32 = new CounterCreationData();
            averageTimer32.CounterType = PerformanceCounterType.AverageTimer32;
            averageTimer32.CounterName = counterName;
            CCDC.Add(averageTimer32);

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

            // Create the category.
            PerformanceCounterCategory.Create(categoryName, 
                "Demonstrates usage of the AverageTimer32 performance counter type", 
                PerformanceCounterCategoryType.SingleInstance, CCDC);

            Console.WriteLine("Category created - " + categoryName);

            return (true);
        }
        else
        {
            Console.WriteLine("Category exists - " + categoryName);
            return (false);
        }
    }

    private static void CreateCounters()
    {
        // Create the counters.
        PC = new PerformanceCounter(categoryName,
                 counterName,
                 false);

        BPC = new PerformanceCounter(categoryName,
            baseCounterName,
            false);

        PC.RawValue = 0;
        BPC.RawValue = 0;
    }


    private static void CollectSamples(ArrayList samplesList)
    {

        Random r = new Random(DateTime.Now.Millisecond);

        // Loop for the samples.
        for (int i = 0; i < 10; i++)
        {

            PC.RawValue = Stopwatch.GetTimestamp();

            BPC.IncrementBy(10);

            System.Threading.Thread.Sleep(1000);

            Console.WriteLine("Next value = " + PC.NextValue().ToString());
            samplesList.Add(PC.NextSample());

        }

    }

    private static void CalculateResults(ArrayList samplesList)
    {
        for (int i = 0; i < (samplesList.Count - 1); i++)
        {
            // Output the sample.
            OutputSample((CounterSample)samplesList[i]);
            OutputSample((CounterSample)samplesList[i + 1]);

            // Use .NET to calculate the counter value.
            Console.WriteLine(".NET computed counter value = " +
                CounterSample.Calculate((CounterSample)samplesList[i],
                (CounterSample)samplesList[i + 1]));

            // Calculate the counter value manually.
            Console.WriteLine("My computed counter value = " +
                MyComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i + 1]));

        }
    }



    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
    // PERF_AVERAGE_TIMER
    //  Description - This counter type measures the time it takes, on 
    //     average, to complete a process or operation. Counters of this
    //     type display a ratio of the total elapsed time of the sample 
    //     interval to the number of processes or operations completed
    //     during that time. This counter type measures time in ticks 
    //     of the system clock. The F variable represents the number of
    //     ticks per second. The value of F is factored into the equation
    //     so that the result can be displayed in seconds.
    //    
    //  Generic type - Average
    //    
    //  Formula - ((N1 - N0) / F) / (D1 - D0), where the numerator (N)
    //     represents the number of ticks counted during the last 
    //     sample interval, F represents the frequency of the ticks, 
    //     and the denominator (D) represents the number of operations
    //     completed during the last sample interval.
    //    
    //  Average - ((Nx - N0) / F) / (Dx - D0)
    //    
    //  Example - PhysicalDisk\ Avg. Disk sec/Transfer 
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//+++++++
    private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
    {
        Int64 n1 = s1.RawValue;
        Int64 n0 = s0.RawValue;
        ulong f = (ulong)s1.SystemFrequency;
        Int64 d1 = s1.BaseValue;
        Int64 d0 = s0.BaseValue;

        double numerator = (double)(n1 - n0);
        double denominator = (double)(d1 - d0);
        Single counterValue = (Single)((numerator / f) / denominator);
        return (counterValue);
    }

    // Output information about the counter sample.
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   CounterType      = " + s.CounterType);
        Console.WriteLine("   RawValue         = " + s.RawValue);
        Console.WriteLine("   BaseValue        = " + s.BaseValue);
        Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
        Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
        Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
        Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
        Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
        Console.WriteLine("++++++++++++++++++++++");
    }
}

ElapsedTime

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics
Imports System.Runtime.InteropServices
Imports Microsoft.VisualBasic

Public Class App
   
   Public Shared Sub Main()
      CollectSamples()
   End Sub
   
   Private Shared Sub CollectSamples()

      Dim categoryName as String = "ElapsedTimeSampleCategory"
      Dim counterName as String = "ElapsedTimeSample"

      If Not PerformanceCounterCategory.Exists(categoryName) Then
         
         Dim CCDC As New CounterCreationDataCollection()
         
         ' Add the counter.
         Dim ETimeData As New CounterCreationData()
         ETimeData.CounterType = PerformanceCounterType.ElapsedTime
         ETimeData.CounterName = counterName
         CCDC.Add(ETimeData)
         
         ' Create the category.
         PerformanceCounterCategory.Create(categoryName, _
            "Demonstrates ElapsedTime performance counter usage.", CCDC)
       
      Else
         Console.WriteLine("Category exists - {0}", categoryName)
      End If

      ' Create the counter.
      Dim PC As PerformanceCounter
      PC = New PerformanceCounter(categoryName, counterName, False)
     
      ' Initialize the counter.
      PC.RawValue = Stopwatch.GetTimestamp()

      Dim Start As DateTime = DateTime.Now
      
      ' Loop for the samples.
      Dim j As Integer
      For j = 0 To 99
         ' Output the values.
         If j Mod 10 = 9 Then
            Console.WriteLine(("NextValue() = " _
                + PC.NextValue().ToString()))
            Console.WriteLine(("Actual elapsed time = " _
                + DateTime.Now.Subtract(Start).ToString()))
            OutputSample(PC.NextSample())
         End If
         
         ' Reset the counter every 20th iteration.
         If j Mod 20 = 0 Then
            PC.RawValue = Stopwatch.GetTimestamp()
            Start = DateTime.Now
         End If
         System.Threading.Thread.Sleep(50)
      Next j
      
      Console.WriteLine(("Elapsed time = " + _
            DateTime.Now.Subtract(Start).ToString()))
   End Sub 
   
   
   Private Shared Sub OutputSample(s As CounterSample)
      Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++")

      Console.WriteLine("Sample values - " + ControlChars.Cr _
            + ControlChars.Lf)
      Console.WriteLine(("   BaseValue        = " _
            + s.BaseValue.ToString()))
      Console.WriteLine(("   CounterFrequency = " + _
            s.CounterFrequency.ToString()))
      Console.WriteLine(("   CounterTimeStamp = " + _
            s.CounterTimeStamp.ToString()))
      Console.WriteLine(("   CounterType      = " + _
            s.CounterType.ToString()))
      Console.WriteLine(("   RawValue         = " + _
            s.RawValue.ToString()))
      Console.WriteLine(("   SystemFrequency  = " + _
            s.SystemFrequency.ToString()))
      Console.WriteLine(("   TimeStamp        = " + _
            s.TimeStamp.ToString()))
      Console.WriteLine(("   TimeStamp100nSec = " + _
            s.TimeStamp100nSec.ToString()))
      
      Console.WriteLine("+++++++")
   End Sub
End Class
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;
using System.Runtime.InteropServices;

public class App 
{

    public static void Main()
    {   
        CollectSamples();
    }

   
    public static void CollectSamples()
    {
        const String categoryName = "ElapsedTimeSampleCategory";
        const String counterName = "ElapsedTimeSample";

        if ( !PerformanceCounterCategory.Exists(categoryName) ) 
        {

            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData ETimeData = new CounterCreationData();
            ETimeData.CounterType = PerformanceCounterType.ElapsedTime;
            ETimeData.CounterName = counterName;
            CCDC.Add(ETimeData);       
        
            // Create the category.
            PerformanceCounterCategory.Create(categoryName, 
                    "Demonstrates ElapsedTime performance counter usage.",
                    CCDC);

        }
        else
        {
            Console.WriteLine("Category exists - {0}", categoryName);
        }        

        // Create the performance counter.
        PerformanceCounter PC = new PerformanceCounter(categoryName, 
                                                       counterName, 
                                                       false);
        // Initialize the counter.
        PC.RawValue = Stopwatch.GetTimestamp();

        DateTime Start = DateTime.Now;

        // Loop for the samples.
        for (int j = 0; j < 100; j++) 
        {
            // Output the values.
            if ((j % 10) == 9) 
            {
                Console.WriteLine("NextValue() = " + PC.NextValue().ToString());
                Console.WriteLine("Actual elapsed time = " + DateTime.Now.Subtract(Start).ToString());
                OutputSample(PC.NextSample());
            }

            // Reset the counter on every 20th iteration.
            if (j % 20 == 0)
            {
                PC.RawValue = Stopwatch.GetTimestamp();
                Start = DateTime.Now;
            }
            System.Threading.Thread.Sleep(50);
        }

        Console.WriteLine("Elapsed time = " + DateTime.Now.Subtract(Start).ToString());
    }

    
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("\r\n+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.BaseValue);
        Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
        Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
        Console.WriteLine("   CounterType      = " + s.CounterType);
        Console.WriteLine("   RawValue         = " + s.RawValue);
        Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
        Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
        Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
        Console.WriteLine("++++++++++++++++++++++");
    }
}
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
using namespace System::Diagnostics;
using namespace System::Runtime::InteropServices;

void OutputSample( CounterSample s )
{
   Console::WriteLine( "\r\n+++++++++++" );
   Console::WriteLine( "Sample values - \r\n" );
   Console::WriteLine( "   BaseValue        = {0}", s.BaseValue );
   Console::WriteLine( "   CounterFrequency = {0}", s.CounterFrequency );
   Console::WriteLine( "   CounterTimeStamp = {0}", s.CounterTimeStamp );
   Console::WriteLine( "   CounterType      = {0}", s.CounterType );
   Console::WriteLine( "   RawValue         = {0}", s.RawValue );
   Console::WriteLine( "   SystemFrequency  = {0}", s.SystemFrequency );
   Console::WriteLine( "   TimeStamp        = {0}", s.TimeStamp );
   Console::WriteLine( "   TimeStamp100nSec = {0}", s.TimeStamp100nSec );
   Console::WriteLine( "++++++++++++++++++++++" );
}

void CollectSamples()
{
   String^ categoryName = "ElapsedTimeSampleCategory";
   String^ counterName = "ElapsedTimeSample";
   
   // Create the performance counter category.
   if (  !PerformanceCounterCategory::Exists( categoryName ) )
   {
      CounterCreationDataCollection^ CCDC = gcnew CounterCreationDataCollection;
      
      // Add the counter.
      CounterCreationData^ ETimeData = gcnew CounterCreationData;
      ETimeData->CounterType = PerformanceCounterType::ElapsedTime;
      ETimeData->CounterName = counterName;
      CCDC->Add( ETimeData );
      
      // Create the category.
      PerformanceCounterCategory::Create( categoryName,
         "Demonstrates ElapsedTime performance counter usage.",
         CCDC );
   }
   else
   {
      Console::WriteLine( "Category exists - {0}", categoryName );
   }

   
   // Create the performance counter.
   PerformanceCounter^ PC = gcnew PerformanceCounter( categoryName,
                                                      counterName,
                                                      false );
   // Initialize the counter.
   PC->RawValue = Stopwatch::GetTimestamp();

   DateTime Start = DateTime::Now;
   
   // Loop for the samples.
   for ( int j = 0; j < 100; j++ )
   {
      // Output the values.
      if ( (j % 10) == 9 )
      {
         Console::WriteLine( "NextValue() = {0}", PC->NextValue() );
         Console::WriteLine( "Actual elapsed time = {0}", DateTime::Now.Subtract( Start ) );
         OutputSample( PC->NextSample() );
      }
      
      // Reset the counter on every 20th iteration.
      if ( j % 20 == 0 )
      {
         PC->RawValue = Stopwatch::GetTimestamp();
         Start = DateTime::Now;
      }
      System::Threading::Thread::Sleep( 50 );
   }

   Console::WriteLine( "Elapsed time = {0}", DateTime::Now.Subtract( Start ) );
}

int main()
{
   CollectSamples();
}
import System.*;
import System.Collections.*;
import System.Collections.Specialized.*;
import System.Diagnostics.*;
import System.Runtime.InteropServices.*;

public class App
{
    public static void main(String[] args)
    {
        CollectSamples();
    } //main

    public static void CollectSamples()
    {
        final String categoryName = "ElapsedTimeSampleCategory";
        final String counterName = "ElapsedTimeSample";

        if (!(PerformanceCounterCategory.Exists(categoryName))) {
            CounterCreationDataCollection ccdc = 
                new CounterCreationDataCollection();
            // Add the counter.
            CounterCreationData eTimeData = new CounterCreationData();
            eTimeData.set_CounterType(PerformanceCounterType.ElapsedTime);
            eTimeData.set_CounterName(counterName);
            ccdc.Add(eTimeData);
            // Create the category.
            PerformanceCounterCategory.Create(categoryName, 
                "Demonstrates ElapsedTime performance counter usage.", ccdc);
        }
        else {
            Console.WriteLine("Category exists - {0}", categoryName);
        }
        // Create the performance counter.
        PerformanceCounter pc = new PerformanceCounter(categoryName,
            counterName, false);
        // Initialize the counter.
        pc.set_RawValue(Stopwatch.GetTimestamp());
        DateTime start = DateTime.get_Now();
        // Loop for the samples.
        for (int j = 0; j < 100; j++) {
            // Output the values.
            if (j % 10 == 9) {
                Console.WriteLine("NextValue() = " + ((Single)pc.NextValue()).
                    ToString());
                Console.WriteLine("Actual elapsed time = "
                    + DateTime.get_Now().Subtract(start).ToString());
                OutputSample(pc.NextSample());
            }
            // Reset the counter on every 20th iteration.
            if (j % 20 == 0) {
                pc.set_RawValue(Stopwatch.GetTimestamp());
                start = DateTime.get_Now();
            }
            System.Threading.Thread.Sleep(50);
        }
        Console.WriteLine("Elapsed time = " + DateTime.get_Now().
            Subtract(start).ToString());
    } //CollectSamples

    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("\r\n+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.get_BaseValue());
        Console.WriteLine("   CounterFrequency = " + s.get_CounterFrequency());
        Console.WriteLine("   CounterTimeStamp = " + s.get_CounterTimeStamp());
        Console.WriteLine("   CounterType      = " + s.get_CounterType());
        Console.WriteLine("   RawValue         = " + s.get_RawValue());
        Console.WriteLine("   SystemFrequency  = " + s.get_SystemFrequency());
        Console.WriteLine("   TimeStamp        = " + s.get_TimeStamp());
        Console.WriteLine("   TimeStamp100nSec = " + s.get_TimeStamp100nSec());
        Console.WriteLine("++++++++++++++++++++++");
    } //OutputSample
} //App

NumberOfItems32

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics

 _

Public Class NumberOfItems64
   
   Private Shared PC As PerformanceCounter
   
   
   Public Shared Sub Main()
      Dim samplesList As New ArrayList()
      
      SetupCategory()
      CreateCounters()
      CollectSamples(samplesList)
      CalculateResults(samplesList)
   End Sub 'Main
   
   
   Private Shared Function SetupCategory() As Boolean
      If Not PerformanceCounterCategory.Exists("NumberOfItems32SampleCategory") Then
         
         Dim CCDC As New CounterCreationDataCollection()
         
         ' Add the counter.
         Dim NOI64 As New CounterCreationData()
         NOI64.CounterType = PerformanceCounterType.NumberOfItems64
         NOI64.CounterName = "NumberOfItems32Sample"
         CCDC.Add(NOI64)
         
         ' Create the category.
         PerformanceCounterCategory.Create("NumberOfItems32SampleCategory", "Demonstrates usage of the NumberOfItems32 performance counter type.", CCDC)
         
         Return True
      Else
         Console.WriteLine("Category exists - NumberOfItems32SampleCategory")
         Return False
      End If
   End Function 'SetupCategory
   
   
   Private Shared Sub CreateCounters()
      ' Create the counter.
      PC = New PerformanceCounter("NumberOfItems32SampleCategory", "NumberOfItems32Sample", False)
      
      PC.RawValue = 0
   End Sub 'CreateCounters
    
   
   Private Shared Sub CollectSamples(samplesList As ArrayList)
      
      
      
      Dim r As New Random(DateTime.Now.Millisecond)
      
      ' Loop for the samples.
      Dim j As Integer
      For j = 0 To 99
         
         Dim value As Integer = r.Next(1, 10)
         Console.Write((j + " = " + value))
         
         PC.IncrementBy(value)
         
         If j Mod 10 = 9 Then
            OutputSample(PC.NextSample())
            samplesList.Add(PC.NextSample())
         Else
            Console.WriteLine()
         End If 
         System.Threading.Thread.Sleep(50)
      Next j
   End Sub 'CollectSamples
    
   
   
   
   Private Shared Sub CalculateResults(samplesList As ArrayList)
      Dim i As Integer
      For i = 0 To (samplesList.Count - 1) - 1
         ' Output the sample.
         OutputSample(CType(samplesList(i), CounterSample))
         OutputSample(CType(samplesList((i + 1)), CounterSample))
         
         ' Use .NET to calculate the counter value.
         Console.WriteLine((".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
         
         ' Calculate the counter value manually.
         Console.WriteLine(("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
      Next i
   End Sub 'CalculateResults
   
   
   
   
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   Private Shared Function MyComputeCounterValue(s0 As CounterSample, s1 As CounterSample) As [Single]
      Dim counterValue As [Single] = s1.RawValue
      Return counterValue
   End Function 'MyComputeCounterValue
   
   
   ' Output information about the counter sample.
   Private Shared Sub OutputSample(s As CounterSample)
      Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
      Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
      Console.WriteLine(("   BaseValue        = " + s.BaseValue))
      Console.WriteLine(("   CounterFrequency = " + s.CounterFrequency))
      Console.WriteLine(("   CounterTimeStamp = " + s.CounterTimeStamp))
      Console.WriteLine(("   CounterType      = " + s.CounterType))
      Console.WriteLine(("   RawValue         = " + s.RawValue))
      Console.WriteLine(("   SystemFrequency  = " + s.SystemFrequency))
      Console.WriteLine(("   TimeStamp        = " + s.TimeStamp))
      Console.WriteLine(("   TimeStamp100nSec = " + s.TimeStamp100nSec))
      Console.WriteLine("++++++++++++++++++++++")
   End Sub 'OutputSample
End Class 'NumberOfItems64 

using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;

public class NumberOfItems64
{

    private static PerformanceCounter PC;

    public static void Main()
    {   
        ArrayList samplesList = new ArrayList();

        SetupCategory();
        CreateCounters();
        CollectSamples(samplesList);
        CalculateResults(samplesList);
    }

    private static bool SetupCategory()
    {       
        if ( !PerformanceCounterCategory.Exists("NumberOfItems32SampleCategory") ) 
        {

            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData NOI64 = new CounterCreationData();
            NOI64.CounterType = PerformanceCounterType.NumberOfItems64;
            NOI64.CounterName = "NumberOfItems32Sample";
            CCDC.Add(NOI64);

            // Create the category.
            PerformanceCounterCategory.Create("NumberOfItems32SampleCategory", 
                "Demonstrates usage of the NumberOfItems32 performance counter type.", 
                CCDC);

            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - NumberOfItems32SampleCategory");
            return(false);
        }
    }

    private static void CreateCounters()
    {
        // Create the counter.
        PC = new PerformanceCounter("NumberOfItems32SampleCategory", 
            "NumberOfItems32Sample", 
            false);

        PC.RawValue=0;
        
    }

    private static void CollectSamples(ArrayList samplesList)
    {
    
        
        
        Random r = new Random( DateTime.Now.Millisecond );

        // Loop for the samples.
        for (int j = 0; j < 100; j++) 
        {
            
            int value = r.Next(1, 10);
            Console.Write(j + " = " + value);

            PC.IncrementBy(value);

            if ((j % 10) == 9) 
            {
                OutputSample(PC.NextSample());
                samplesList.Add( PC.NextSample() );
            }
            else
                Console.WriteLine();
            
            System.Threading.Thread.Sleep(50);
        }

        
    }


    private static void CalculateResults(ArrayList samplesList)
    {
        for(int i = 0; i < (samplesList.Count - 1); i++)
        {
            // Output the sample.
            OutputSample( (CounterSample)samplesList[i] );
            OutputSample( (CounterSample)samplesList[i+1] );

            // Use .NET to calculate the counter value.
            Console.WriteLine(".NET computed counter value = " + 
                CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );

            // Calculate the counter value manually.
            Console.WriteLine("My computed counter value = " + 
                MyComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );

        }
    }
    

    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
    {
        Single counterValue = s1.RawValue;
        return(counterValue);
    }
    
    // Output information about the counter sample.
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("\r\n+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.BaseValue);
        Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
        Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
        Console.WriteLine("   CounterType      = " + s.CounterType);
        Console.WriteLine("   RawValue         = " + s.RawValue);
        Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
        Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
        Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
        Console.WriteLine("++++++++++++++++++++++");
    }


    
}
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
using namespace System::Diagnostics;
float MyComputeCounterValue( CounterSample s0, CounterSample s1 )
{
   float counterValue = (float)s1.RawValue;
   return counterValue;
}

// Output information about the counter sample.
void OutputSample( CounterSample s )
{
   Console::WriteLine( "\r\n+++++++++++" );
   Console::WriteLine( "Sample values - \r\n" );
   Console::WriteLine( "   BaseValue        = {0}", s.BaseValue );
   Console::WriteLine( "   CounterFrequency = {0}", s.CounterFrequency );
   Console::WriteLine( "   CounterTimeStamp = {0}", s.CounterTimeStamp );
   Console::WriteLine( "   CounterType      = {0}", s.CounterType );
   Console::WriteLine( "   RawValue         = {0}", s.RawValue );
   Console::WriteLine( "   SystemFrequency  = {0}", s.SystemFrequency );
   Console::WriteLine( "   TimeStamp        = {0}", s.TimeStamp );
   Console::WriteLine( "   TimeStamp100nSec = {0}", s.TimeStamp100nSec );
   Console::WriteLine( "++++++++++++++++++++++" );
}

bool SetupCategory()
{
   if (  !PerformanceCounterCategory::Exists( "NumberOfItems32SampleCategory" ) )
   {
      CounterCreationDataCollection^ CCDC = gcnew CounterCreationDataCollection;

      // Add the counter.
      CounterCreationData^ NOI64 = gcnew CounterCreationData;
      NOI64->CounterType = PerformanceCounterType::NumberOfItems64;
      NOI64->CounterName = "NumberOfItems32Sample";
      CCDC->Add( NOI64 );

      // Create the category.
      PerformanceCounterCategory::Create( "NumberOfItems32SampleCategory", "Demonstrates usage of the NumberOfItems32 performance counter type.", CCDC );
      return true;
   }
   else
   {
      Console::WriteLine( "Category exists - NumberOfItems32SampleCategory" );
      return false;
   }
}

void CreateCounters( PerformanceCounter^% PC )
{
   // Create the counter.
   PC = gcnew PerformanceCounter( "NumberOfItems32SampleCategory","NumberOfItems32Sample",false );
   PC->RawValue = 0;
}

void CollectSamples( ArrayList^ samplesList, PerformanceCounter^ PC )
{
   Random^ r = gcnew Random( DateTime::Now.Millisecond );

   // Loop for the samples.
   for ( int j = 0; j < 100; j++ )
   {
      int value = r->Next( 1, 10 );
      Console::Write( "{0} = {1}", j, value );
      PC->IncrementBy( value );
      if ( (j % 10) == 9 )
      {
         OutputSample( PC->NextSample() );
         samplesList->Add( PC->NextSample() );
      }
      else
            Console::WriteLine();
      System::Threading::Thread::Sleep( 50 );

   }
}

void CalculateResults( ArrayList^ samplesList )
{
   for ( int i = 0; i < (samplesList->Count - 1); i++ )
   {
      // Output the sample.
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i ]) );
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) );

      // Use .NET to calculate the counter value.
      Console::WriteLine( ".NET computed counter value = {0}", CounterSampleCalculator::ComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );

      // Calculate the counter value manually.
      Console::WriteLine( "My computed counter value = {0}", MyComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );
   }
}

void main()
{
   ArrayList^ samplesList = gcnew ArrayList;
   PerformanceCounter^ PC;
   SetupCategory();
   CreateCounters( PC );
   CollectSamples( samplesList, PC );
   CalculateResults( samplesList );
}

NumberOfItems64

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics

 _

Public Class NumberOfItems64
   
   Private Shared PC As PerformanceCounter
   
   
   Public Shared Sub Main()
      Dim samplesList As New ArrayList()
      
      SetupCategory()
      CreateCounters()
      CollectSamples(samplesList)
      CalculateResults(samplesList)
   End Sub 'Main
   
   
   Private Shared Function SetupCategory() As Boolean
      If Not PerformanceCounterCategory.Exists("NumberOfItems64SampleCategory") Then
         
         Dim CCDC As New CounterCreationDataCollection()
         
         ' Add the counter.
         Dim NOI64 As New CounterCreationData()
         NOI64.CounterType = PerformanceCounterType.NumberOfItems64
         NOI64.CounterName = "NumberOfItems64Sample"
         CCDC.Add(NOI64)
         
         ' Create the category.
         PerformanceCounterCategory.Create("NumberOfItems64SampleCategory", "Demonstrates usage of the NumberOfItems64 performance counter type.", CCDC)
         
         Return True
      Else
         Console.WriteLine("Category exists - NumberOfItems64SampleCategory")
         Return False
      End If
   End Function 'SetupCategory
   
   
   Private Shared Sub CreateCounters()
      ' Create the counters.
      PC = New PerformanceCounter("NumberOfItems64SampleCategory", "NumberOfItems64Sample", False)
      
      PC.RawValue = 0
   End Sub 'CreateCounters
    
   
   Private Shared Sub CollectSamples(samplesList As ArrayList)
      
      Dim r As New Random(DateTime.Now.Millisecond)
      
      ' Loop for the samples.
      Dim j As Integer
      For j = 0 To 99
         
         Dim value As Integer = r.Next(1, 10)
         Console.Write((j + " = " + value))
         
         PC.IncrementBy(value)
         
         If j Mod 10 = 9 Then
            OutputSample(PC.NextSample())
            samplesList.Add(PC.NextSample())
         Else
            Console.WriteLine()
         End If 
         System.Threading.Thread.Sleep(50)
      Next j
   End Sub 'CollectSamples
    
   
   Private Shared Sub CalculateResults(samplesList As ArrayList)
      Dim i As Integer
      For i = 0 To (samplesList.Count - 1) - 1
         ' Output the sample.
         OutputSample(CType(samplesList(i), CounterSample))
         OutputSample(CType(samplesList((i + 1)), CounterSample))
         
         ' Use .NET to calculate the counter value.
         Console.WriteLine((".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
         
         ' Calculate the counter value manually.
         Console.WriteLine(("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
      Next i
   End Sub 'CalculateResults
   
   
   
   
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   Private Shared Function MyComputeCounterValue(s0 As CounterSample, s1 As CounterSample) As [Single]
      Dim counterValue As [Single] = s1.RawValue
      Return counterValue
   End Function 'MyComputeCounterValue
   
   
   ' Output information about the counter sample.
   Private Shared Sub OutputSample(s As CounterSample)
      Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
      Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
      Console.WriteLine(("   BaseValue        = " + s.BaseValue))
      Console.WriteLine(("   CounterFrequency = " + s.CounterFrequency))
      Console.WriteLine(("   CounterTimeStamp = " + s.CounterTimeStamp))
      Console.WriteLine(("   CounterType      = " + s.CounterType))
      Console.WriteLine(("   RawValue         = " + s.RawValue))
      Console.WriteLine(("   SystemFrequency  = " + s.SystemFrequency))
      Console.WriteLine(("   TimeStamp        = " + s.TimeStamp))
      Console.WriteLine(("   TimeStamp100nSec = " + s.TimeStamp100nSec))
      Console.WriteLine("++++++++++++++++++++++")
   End Sub 'OutputSample
End Class 'NumberOfItems64 
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;

public class NumberOfItems64
{

    private static PerformanceCounter PC;

    public static void Main()
    {   
        ArrayList samplesList = new ArrayList();

        SetupCategory();
        CreateCounters();
        CollectSamples(samplesList);
        CalculateResults(samplesList);
    }

    private static bool SetupCategory()
    {       
        if ( !PerformanceCounterCategory.Exists("NumberOfItems64SampleCategory") ) 
        {

            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData NOI64 = new CounterCreationData();
            NOI64.CounterType = PerformanceCounterType.NumberOfItems64;
            NOI64.CounterName = "NumberOfItems64Sample";
            CCDC.Add(NOI64);

            // Create the category.
            PerformanceCounterCategory.Create("NumberOfItems64SampleCategory", 
                "Demonstrates usage of the NumberOfItems64 performance counter type.", 
                CCDC);

            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - NumberOfItems64SampleCategory");
            return(false);
        }
    }

    private static void CreateCounters()
    {
        // Create the counters.
        PC = new PerformanceCounter("NumberOfItems64SampleCategory", 
            "NumberOfItems64Sample", 
            false);

        PC.RawValue=0;
        
    }

    private static void CollectSamples(ArrayList samplesList)
    {
        
        Random r = new Random( DateTime.Now.Millisecond );

        // Loop for the samples.
        for (int j = 0; j < 100; j++) 
        {
            
            int value = r.Next(1, 10);
            Console.Write(j + " = " + value);

            PC.IncrementBy(value);

            if ((j % 10) == 9) 
            {
                OutputSample(PC.NextSample());
                samplesList.Add( PC.NextSample() );
            }
            else
                Console.WriteLine();
            
            System.Threading.Thread.Sleep(50);
        }

    }

    private static void CalculateResults(ArrayList samplesList)
    {
        for(int i = 0; i < (samplesList.Count - 1); i++)
        {
            // Output the sample.
            OutputSample( (CounterSample)samplesList[i] );
            OutputSample( (CounterSample)samplesList[i+1] );

            // Use .NET to calculate the counter value.
            Console.WriteLine(".NET computed counter value = " + 
                CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );

            // Calculate the counter value manually.
            Console.WriteLine("My computed counter value = " + 
                MyComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );

        }
    }

    
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
    {
        Single counterValue = s1.RawValue;
        return(counterValue);
    }
    
    // Output information about the counter sample.
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("\r\n+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.BaseValue);
        Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
        Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
        Console.WriteLine("   CounterType      = " + s.CounterType);
        Console.WriteLine("   RawValue         = " + s.RawValue);
        Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
        Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
        Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
        Console.WriteLine("++++++++++++++++++++++");
    }

}
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
using namespace System::Diagnostics;
float MyComputeCounterValue( CounterSample s0, CounterSample s1 )
{
   float counterValue = (float)s1.RawValue;
   return counterValue;
}


// Output information about the counter sample.
void OutputSample( CounterSample s )
{
   Console::WriteLine( "\r\n+++++++++++" );
   Console::WriteLine( "Sample values - \r\n" );
   Console::WriteLine( "   BaseValue        = {0}", s.BaseValue );
   Console::WriteLine( "   CounterFrequency = {0}", s.CounterFrequency );
   Console::WriteLine( "   CounterTimeStamp = {0}", s.CounterTimeStamp );
   Console::WriteLine( "   CounterType      = {0}", s.CounterType );
   Console::WriteLine( "   RawValue         = {0}", s.RawValue );
   Console::WriteLine( "   SystemFrequency  = {0}", s.SystemFrequency );
   Console::WriteLine( "   TimeStamp        = {0}", s.TimeStamp );
   Console::WriteLine( "   TimeStamp100nSec = {0}", s.TimeStamp100nSec );
   Console::WriteLine( "++++++++++++++++++++++" );
}

bool SetupCategory()
{
   if (  !PerformanceCounterCategory::Exists( "NumberOfItems64SampleCategory" ) )
   {
      CounterCreationDataCollection^ CCDC = gcnew CounterCreationDataCollection;

      // Add the counter.
      CounterCreationData^ NOI64 = gcnew CounterCreationData;
      NOI64->CounterType = PerformanceCounterType::NumberOfItems64;
      NOI64->CounterName = "NumberOfItems64Sample";
      CCDC->Add( NOI64 );

      // Create the category.
      PerformanceCounterCategory::Create( "NumberOfItems64SampleCategory", "Demonstrates usage of the NumberOfItems64 performance counter type.", CCDC );
      return true;
   }
   else
   {
      Console::WriteLine( "Category exists - NumberOfItems64SampleCategory" );
      return false;
   }
}

void CreateCounters( PerformanceCounter^% PC )
{
   // Create the counters.
   PC = gcnew PerformanceCounter( "NumberOfItems64SampleCategory","NumberOfItems64Sample",false );
   PC->RawValue = 0;
}

void CollectSamples( ArrayList^ samplesList, PerformanceCounter^ PC )
{
   Random^ r = gcnew Random( DateTime::Now.Millisecond );

   // Loop for the samples.
   for ( int j = 0; j < 100; j++ )
   {
      int value = r->Next( 1, 10 );
      Console::Write( "{0} = {1}", j, value );
      PC->IncrementBy( value );
      if ( (j % 10) == 9 )
      {
         OutputSample( PC->NextSample() );
         samplesList->Add( PC->NextSample() );
      }
      else
            Console::WriteLine();
      System::Threading::Thread::Sleep( 50 );
   }
}

void CalculateResults( ArrayList^ samplesList )
{
   for ( int i = 0; i < (samplesList->Count - 1); i++ )
   {
      // Output the sample.
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i ]) );
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) );

      // Use .NET to calculate the counter value.
      Console::WriteLine( ".NET computed counter value = {0}", CounterSampleCalculator::ComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );

      // Calculate the counter value manually.
      Console::WriteLine( "My computed counter value = {0}", MyComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );
   }
}

int main()
{
   ArrayList^ samplesList = gcnew ArrayList;
   PerformanceCounter^ PC;
   SetupCategory();
   CreateCounters( PC );
   CollectSamples( samplesList, PC );
   CalculateResults( samplesList );
}

RateOfCountsPerSecond32

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics

 _

Public Class App
   Private Shared PC As PerformanceCounter
   
   
   Public Shared Sub Main()
      Dim samplesList As New ArrayList()
      
      SetupCategory()
      CreateCounters()
      CollectSamples(samplesList)
      CalculateResults(samplesList)
   End Sub 'Main
   
   
   Private Shared Function SetupCategory() As Boolean
      
      If Not PerformanceCounterCategory.Exists("RateOfCountsPerSecond32SampleCategory") Then
         
         
         Dim CCDC As New CounterCreationDataCollection()
         
         ' Add the counter.
         Dim rateOfCounts32 As New CounterCreationData()
         rateOfCounts32.CounterType = PerformanceCounterType.RateOfCountsPerSecond32
         rateOfCounts32.CounterName = "RateOfCountsPerSecond32Sample"
         CCDC.Add(rateOfCounts32)
         
         ' Create the category.
         PerformanceCounterCategory.Create("RateOfCountsPerSecond32SampleCategory", "Demonstrates usage of the RateOfCountsPerSecond32 performance counter type.", CCDC)
         Return True
      Else
         Console.WriteLine("Category exists - RateOfCountsPerSecond32SampleCategory")
         Return False
      End If
   End Function 'SetupCategory
   
   
   Private Shared Sub CreateCounters()
      ' Create the counter.
      PC = New PerformanceCounter("RateOfCountsPerSecond32SampleCategory", "RateOfCountsPerSecond32Sample", False)
      
      PC.RawValue = 0
   End Sub 'CreateCounters
    
   
   Private Shared Sub CollectSamples(samplesList As ArrayList)
      
      Dim r As New Random(DateTime.Now.Millisecond)
      
      ' Initialize the performance counter.
      PC.NextSample()
      
      ' Loop for the samples.
      Dim j As Integer
      For j = 0 To 99
         
         Dim value As Integer = r.Next(1, 10)
         PC.IncrementBy(value)
         Console.Write((j + " = " + value))
         
         If j Mod 10 = 9 Then
            Console.WriteLine((";       NextValue() = " + PC.NextValue().ToString()))
            OutputSample(PC.NextSample())
            samplesList.Add(PC.NextSample())
         Else
            Console.WriteLine()
         End If 
         System.Threading.Thread.Sleep(50)
      Next j
   End Sub 'CollectSamples
   
   
   Private Shared Sub CalculateResults(samplesList As ArrayList)
      Dim i As Integer
      For i = 0 To (samplesList.Count - 1) - 1
         ' Output the sample.
         OutputSample(CType(samplesList(i), CounterSample))
         OutputSample(CType(samplesList((i + 1)), CounterSample))
         
         
         ' Use .NET to calculate the counter value.
         Console.WriteLine((".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
         
         ' Calculate the counter value manually.
         Console.WriteLine(("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
      Next i
   End Sub 'CalculateResults
   
   
   
   
   
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   '    PERF_COUNTER_COUNTER
   '    Description  - This counter type shows the average number of operations completed
   '        during each second of the sample interval. Counters of this type
   '        measure time in ticks of the system clock. The F variable represents
   '        the number of ticks per second. The value of F is factored into the
   '        equation so that the result can be displayed in seconds.
   '
   '    Generic type - Difference
   '
   '    Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
   '        of operations performed during the last sample interval, the denominator
   '        (D) represents the number of ticks elapsed during the last sample
   '        interval, and F is the frequency of the ticks.
   '
   '         Average - (Nx - N0) / ((Dx - D0) / F) 
   '
   '       Example - System\ File Read Operations/sec 
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   Private Shared Function MyComputeCounterValue(s0 As CounterSample, s1 As CounterSample) As [Single]
      Dim numerator As [Single] = CType(s1.RawValue - s0.RawValue, [Single])
      Dim denomenator As [Single] = CType(s1.TimeStamp - s0.TimeStamp, [Single]) / CType(s1.SystemFrequency, [Single])
      Dim counterValue As [Single] = numerator / denomenator
      Return counterValue
   End Function 'MyComputeCounterValue
   
   
   ' Output information about the counter sample.
   Private Shared Sub OutputSample(s As CounterSample)
      Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
      Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
      Console.WriteLine(("   BaseValue        = " + s.BaseValue))
      Console.WriteLine(("   CounterFrequency = " + s.CounterFrequency))
      Console.WriteLine(("   CounterTimeStamp = " + s.CounterTimeStamp))
      Console.WriteLine(("   CounterType      = " + s.CounterType))
      Console.WriteLine(("   RawValue         = " + s.RawValue))
      Console.WriteLine(("   SystemFrequency  = " + s.SystemFrequency))
      Console.WriteLine(("   TimeStamp        = " + s.TimeStamp))
      Console.WriteLine(("   TimeStamp100nSec = " + s.TimeStamp100nSec))
      Console.WriteLine("++++++++++++++++++++++")
   End Sub 'OutputSample
End Class 'App 
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;

public class App 
{
    private static PerformanceCounter PC;

    public static void Main()
    {   
        ArrayList samplesList = new ArrayList();

        SetupCategory();
        CreateCounters();
        CollectSamples(samplesList);
        CalculateResults(samplesList);
    }

    private static bool SetupCategory()
    {
        
        if ( !PerformanceCounterCategory.Exists("RateOfCountsPerSecond32SampleCategory") ) 
        {


            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData rateOfCounts32 = new CounterCreationData();
            rateOfCounts32.CounterType = PerformanceCounterType.RateOfCountsPerSecond32;
            rateOfCounts32.CounterName = "RateOfCountsPerSecond32Sample";
            CCDC.Add(rateOfCounts32);
            
             // Create the category.
            PerformanceCounterCategory.Create("RateOfCountsPerSecond32SampleCategory", 
                "Demonstrates usage of the RateOfCountsPerSecond32 performance counter type.", 
                CCDC);
            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - RateOfCountsPerSecond32SampleCategory");
            return(false);
        }
    }

    private static void CreateCounters()
    {
        // Create the counter.
        PC = new PerformanceCounter("RateOfCountsPerSecond32SampleCategory", 
            "RateOfCountsPerSecond32Sample", 
            false);

        PC.RawValue=0;
        
    }

    private static void CollectSamples(ArrayList samplesList)
    {
    
        Random r = new Random( DateTime.Now.Millisecond );

        // Initialize the performance counter.
        PC.NextSample();

        // Loop for the samples.
        for (int j = 0; j < 100; j++) 
        {
            
            int value = r.Next(1, 10);
            PC.IncrementBy(value);
            Console.Write(j + " = " + value);

            if ((j % 10) == 9) 
            {
                Console.WriteLine(";       NextValue() = " + PC.NextValue().ToString());
                OutputSample(PC.NextSample());
                samplesList.Add( PC.NextSample() );
            }
            else
                Console.WriteLine();
            
            System.Threading.Thread.Sleep(50);
        }
    }

    private static void CalculateResults(ArrayList samplesList)
    {
        for(int i = 0; i < (samplesList.Count - 1); i++)
        {
            // Output the sample.
            OutputSample( (CounterSample)samplesList[i] );
            OutputSample( (CounterSample)samplesList[i+1] );


            // Use .NET to calculate the counter value.
            Console.WriteLine(".NET computed counter value = " + 
                CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );

            // Calculate the counter value manually.
            Console.WriteLine("My computed counter value = " + 
                MyComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );


        }
    }


    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    //  PERF_COUNTER_COUNTER
    //  Description  - This counter type shows the average number of operations completed
    //      during each second of the sample interval. Counters of this type
    //      measure time in ticks of the system clock. The F variable represents
    //      the number of ticks per second. The value of F is factored into the
    //      equation so that the result can be displayed in seconds.
    //
    //  Generic type - Difference
    //
    //  Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
    //      of operations performed during the last sample interval, the denominator
    //      (D) represents the number of ticks elapsed during the last sample
    //      interval, and F is the frequency of the ticks.
    //
    //       Average - (Nx - N0) / ((Dx - D0) / F) 
    //
    //       Example - System\ File Read Operations/sec 
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
    {
        Single numerator = (Single)(s1.RawValue - s0.RawValue);
        Single denomenator = (Single)(s1.TimeStamp - s0.TimeStamp) / (Single)s1.SystemFrequency;
        Single counterValue = numerator / denomenator;
        return(counterValue);
    }
    
    // Output information about the counter sample.
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("\r\n+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.BaseValue);
        Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
        Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
        Console.WriteLine("   CounterType      = " + s.CounterType);
        Console.WriteLine("   RawValue         = " + s.RawValue);
        Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
        Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
        Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
        Console.WriteLine("++++++++++++++++++++++");
    }

}
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
using namespace System::Diagnostics;

//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
//    PERF_COUNTER_COUNTER
//    Description     - This counter type shows the average number of operations completed
//        during each second of the sample interval. Counters of this type
//        measure time in ticks of the system clock. The F variable represents
//        the number of ticks per second. The value of F is factored into the
//        equation so that the result can be displayed in seconds.
//
//    Generic type - Difference
//
//    Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
//        of operations performed during the last sample interval, the denominator
//        (D) represents the number of ticks elapsed during the last sample
//        interval, and F is the frequency of the ticks.
//
//         Average - (Nx - N0) / ((Dx - D0) / F) 
//
//       Example - System\ File Read Operations/sec 
//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
float MyComputeCounterValue( CounterSample s0, CounterSample s1 )
{
   float numerator = (float)(s1.RawValue - s0.RawValue);
   float denomenator = (float)(s1.TimeStamp - s0.TimeStamp) / (float)s1.SystemFrequency;
   float counterValue = numerator / denomenator;
   return counterValue;
}


// Output information about the counter sample.
void OutputSample( CounterSample s )
{
   Console::WriteLine( "\r\n+++++++++++" );
   Console::WriteLine( "Sample values - \r\n" );
   Console::WriteLine( "   BaseValue        = {0}", s.BaseValue );
   Console::WriteLine( "   CounterFrequency = {0}", s.CounterFrequency );
   Console::WriteLine( "   CounterTimeStamp = {0}", s.CounterTimeStamp );
   Console::WriteLine( "   CounterType      = {0}", s.CounterType );
   Console::WriteLine( "   RawValue         = {0}", s.RawValue );
   Console::WriteLine( "   SystemFrequency  = {0}", s.SystemFrequency );
   Console::WriteLine( "   TimeStamp        = {0}", s.TimeStamp );
   Console::WriteLine( "   TimeStamp100nSec = {0}", s.TimeStamp100nSec );
   Console::WriteLine( "++++++++++++++++++++++" );
}

bool SetupCategory()
{
   if (  !PerformanceCounterCategory::Exists( "RateOfCountsPerSecond32SampleCategory" ) )
   {
      CounterCreationDataCollection^ CCDC = gcnew CounterCreationDataCollection;

      // Add the counter.
      CounterCreationData^ rateOfCounts32 = gcnew CounterCreationData;
      rateOfCounts32->CounterType = PerformanceCounterType::RateOfCountsPerSecond32;
      rateOfCounts32->CounterName = "RateOfCountsPerSecond32Sample";
      CCDC->Add( rateOfCounts32 );

      // Create the category.
      PerformanceCounterCategory::Create( "RateOfCountsPerSecond32SampleCategory", "Demonstrates usage of the RateOfCountsPerSecond32 performance counter type.", CCDC );
      return true;
   }
   else
   {
      Console::WriteLine( "Category exists - RateOfCountsPerSecond32SampleCategory" );
      return false;
   }
}

void CreateCounters( PerformanceCounter^% PC )
{
   // Create the counter.
   PC = gcnew PerformanceCounter( "RateOfCountsPerSecond32SampleCategory","RateOfCountsPerSecond32Sample",false );
   PC->RawValue = 0;
}

void CollectSamples( ArrayList^ samplesList, PerformanceCounter^ PC )
{
   Random^ r = gcnew Random( DateTime::Now.Millisecond );

   // Initialize the performance counter.
   PC->NextSample();

   // Loop for the samples.
   for ( int j = 0; j < 100; j++ )
   {
      int value = r->Next( 1, 10 );
      PC->IncrementBy( value );
      Console::Write( "{0} = {1}", j, value );
      if ( (j % 10) == 9 )
      {
         Console::WriteLine( ";       NextValue() = {0}", PC->NextValue() );
         OutputSample( PC->NextSample() );
         samplesList->Add( PC->NextSample() );
      }
      else
            Console::WriteLine();
      System::Threading::Thread::Sleep( 50 );
   }
}

void CalculateResults( ArrayList^ samplesList )
{
   for ( int i = 0; i < (samplesList->Count - 1); i++ )
   {
      // Output the sample.
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i ]) );
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) );

      // Use .NET to calculate the counter value.
      Console::WriteLine( ".NET computed counter value = {0}", CounterSampleCalculator::ComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );

      // Calculate the counter value manually.
      Console::WriteLine( "My computed counter value = {0}", MyComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );
   }
}

int main()
{
   ArrayList^ samplesList = gcnew ArrayList;
   PerformanceCounter^ PC;
   SetupCategory();
   CreateCounters( PC );
   CollectSamples( samplesList, PC );
   CalculateResults( samplesList );
}

RateOfCountsPerSecond64

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics

 _

Public Class App
   Private Shared PC As PerformanceCounter
   
   
   Public Shared Sub Main()
      Dim samplesList As New ArrayList()
      
      SetupCategory()
      CreateCounters()
      CollectSamples(samplesList)
      CalculateResults(samplesList)
   End Sub 'Main
   
   
   Private Shared Function SetupCategory() As Boolean
      
      
      If Not PerformanceCounterCategory.Exists("RateOfCountsPerSecond64SampleCategory") Then
         
         
         Dim CCDC As New CounterCreationDataCollection()
         
         ' Add the counter.
         Dim rateOfCounts64 As New CounterCreationData()
         rateOfCounts64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64
         rateOfCounts64.CounterName = "RateOfCountsPerSecond64Sample"
         CCDC.Add(rateOfCounts64)
         
         ' Create the category.
         PerformanceCounterCategory.Create("RateOfCountsPerSecond64SampleCategory", "Demonstrates usage of the RateOfCountsPerSecond64 performance counter type.", CCDC)
         Return True
      Else
         Console.WriteLine("Category exists - RateOfCountsPerSecond64SampleCategory")
         Return False
      End If
   End Function 'SetupCategory
   
   
   Private Shared Sub CreateCounters()
      ' Create the counter.
      PC = New PerformanceCounter("RateOfCountsPerSecond64SampleCategory", "RateOfCountsPerSecond64Sample", False)
      
      PC.RawValue = 0
   End Sub 'CreateCounters
    
   
   Private Shared Sub CollectSamples(samplesList As ArrayList)
      
      Dim r As New Random(DateTime.Now.Millisecond)
      
      ' Initialize the performance counter.
      PC.NextSample()
      
      ' Loop for the samples.
      Dim j As Integer
      For j = 0 To 99
         
         Dim value As Integer = r.Next(1, 10)
         PC.IncrementBy(value)
         Console.Write((j + " = " + value))
         
         If j Mod 10 = 9 Then
            Console.WriteLine((";       NextValue() = " + PC.NextValue().ToString()))
            OutputSample(PC.NextSample())
            samplesList.Add(PC.NextSample())
         Else
            Console.WriteLine()
         End If 
         System.Threading.Thread.Sleep(50)
      Next j
   End Sub 'CollectSamples
    
   
   Private Shared Sub CalculateResults(samplesList As ArrayList)
      Dim i As Integer
      For i = 0 To (samplesList.Count - 1) - 1
         ' Output the sample.
         OutputSample(CType(samplesList(i), CounterSample))
         OutputSample(CType(samplesList((i + 1)), CounterSample))
         
         
         ' Use .NET to calculate the counter value.
         Console.WriteLine((".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
         
         ' Calculate the counter value manually.
         Console.WriteLine(("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample), CType(samplesList((i + 1)), CounterSample))))
      Next i
   End Sub 'CalculateResults
   
   
   
   
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   '    PERF_COUNTER_COUNTER
   '    Description  - This counter type shows the average number of operations completed
   '        during each second of the sample interval. Counters of this type
   '        measure time in ticks of the system clock. The F variable represents
   '        the number of ticks per second. The value of F is factored into the
   '        equation so that the result can be displayed in seconds.
   '
   '    Generic type - Difference
   '
   '    Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
   '        of operations performed during the last sample interval, the denominator
   '        (D) represents the number of ticks elapsed during the last sample
   '        interval, and F is the frequency of the ticks.
   '
   '    Average - (Nx - N0) / ((Dx - D0) / F) 
   '
   '  Example - System\ File Read Operations/sec 
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   Private Shared Function MyComputeCounterValue(s0 As CounterSample, s1 As CounterSample) As [Single]
      Dim numerator As [Single] = CType(s1.RawValue - s0.RawValue, [Single])
      Dim denomenator As [Single] = CType(s1.TimeStamp - s0.TimeStamp, [Single]) / CType(s1.SystemFrequency, [Single])
      Dim counterValue As [Single] = numerator / denomenator
      Return counterValue
   End Function 'MyComputeCounterValue
   
   
   Private Shared Sub OutputSample(s As CounterSample)
      Console.WriteLine(ControlChars.Lf + ControlChars.Cr + "+++++++++++")
      Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
      Console.WriteLine(("   BaseValue        = " + s.BaseValue))
      Console.WriteLine(("   CounterFrequency = " + s.CounterFrequency))
      Console.WriteLine(("   CounterTimeStamp = " + s.CounterTimeStamp))
      Console.WriteLine(("   CounterType      = " + s.CounterType))
      Console.WriteLine(("   RawValue         = " + s.RawValue))
      Console.WriteLine(("   SystemFrequency  = " + s.SystemFrequency))
      Console.WriteLine(("   TimeStamp        = " + s.TimeStamp))
      Console.WriteLine(("   TimeStamp100nSec = " + s.TimeStamp100nSec))
      Console.WriteLine("++++++++++++++++++++++")
   End Sub 'OutputSample
End Class 'App
using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;

public class App 
{
    private static PerformanceCounter PC;

    public static void Main()
    {   
        ArrayList samplesList = new ArrayList();

        SetupCategory();
        CreateCounters();
        CollectSamples(samplesList);
        CalculateResults(samplesList);
    }

    private static bool SetupCategory()
    {


        if ( !PerformanceCounterCategory.Exists("RateOfCountsPerSecond64SampleCategory") ) 
        {


            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData rateOfCounts64 = new CounterCreationData();
            rateOfCounts64.CounterType = PerformanceCounterType.RateOfCountsPerSecond64;
            rateOfCounts64.CounterName = "RateOfCountsPerSecond64Sample";
            CCDC.Add(rateOfCounts64);
            
            // Create the category.
            PerformanceCounterCategory.Create("RateOfCountsPerSecond64SampleCategory", 
                "Demonstrates usage of the RateOfCountsPerSecond64 performance counter type.", 
                CCDC);
            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - RateOfCountsPerSecond64SampleCategory");
            return(false);
        }
    }

    private static void CreateCounters()
    {
        // Create the counter.
        PC = new PerformanceCounter("RateOfCountsPerSecond64SampleCategory", 
            "RateOfCountsPerSecond64Sample", 
            false);

        PC.RawValue=0;
        
    }

    private static void CollectSamples(ArrayList samplesList)
    {

        Random r = new Random( DateTime.Now.Millisecond );

        // Initialize the performance counter.
        PC.NextSample();

        // Loop for the samples.
        for (int j = 0; j < 100; j++) 
        {
            
            int value = r.Next(1, 10);
            PC.IncrementBy(value);
            Console.Write(j + " = " + value);

            if ((j % 10) == 9) 
            {
                Console.WriteLine(";       NextValue() = " + PC.NextValue().ToString());
                OutputSample(PC.NextSample());
                samplesList.Add( PC.NextSample() );
            }
            else
                Console.WriteLine();

            System.Threading.Thread.Sleep(50);
        }

    }

    private static void CalculateResults(ArrayList samplesList)
    {
        for(int i = 0; i < (samplesList.Count - 1); i++)
        {
            // Output the sample.
            OutputSample( (CounterSample)samplesList[i] );
            OutputSample( (CounterSample)samplesList[i+1] );


            // Use .NET to calculate the counter value.
            Console.WriteLine(".NET computed counter value = " + 
                CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );

            // Calculate the counter value manually.
            Console.WriteLine("My computed counter value = " + 
                MyComputeCounterValue((CounterSample)samplesList[i],
                (CounterSample)samplesList[i+1]) );


        }
    }

    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    //  PERF_COUNTER_COUNTER
    //  Description  - This counter type shows the average number of operations completed
    //      during each second of the sample interval. Counters of this type
    //      measure time in ticks of the system clock. The F variable represents
    //      the number of ticks per second. The value of F is factored into the
    //      equation so that the result can be displayed in seconds.
    //
    //  Generic type - Difference
    //
    //  Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
    //      of operations performed during the last sample interval, the denominator
    //      (D) represents the number of ticks elapsed during the last sample
    //      interval, and F is the frequency of the ticks.
    //
    //  Average - (Nx - N0) / ((Dx - D0) / F) 
    //
    //  Example - System\ File Read Operations/sec 
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    private static Single MyComputeCounterValue(CounterSample s0, CounterSample s1)
    {
        Single numerator = (Single)(s1.RawValue - s0.RawValue);
        Single denomenator = (Single)(s1.TimeStamp - s0.TimeStamp) / (Single)s1.SystemFrequency;
        Single counterValue = numerator / denomenator;
        return(counterValue);
    }
    
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("\r\n+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.BaseValue);
        Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
        Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
        Console.WriteLine("   CounterType      = " + s.CounterType);
        Console.WriteLine("   RawValue         = " + s.RawValue);
        Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
        Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
        Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
        Console.WriteLine("++++++++++++++++++++++");
    }
}
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
using namespace System::Diagnostics;

//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
//    PERF_COUNTER_COUNTER
//    Description     - This counter type shows the average number of operations completed
//        during each second of the sample interval. Counters of this type
//        measure time in ticks of the system clock. The F variable represents
//        the number of ticks per second. The value of F is factored into the
//        equation so that the result can be displayed in seconds.
//
//    Generic type - Difference
//
//    Formula - (N1 - N0) / ( (D1 - D0) / F), where the numerator (N) represents the number
//        of operations performed during the last sample interval, the denominator
//        (D) represents the number of ticks elapsed during the last sample
//        interval, and F is the frequency of the ticks.
//
//    Average - (Nx - N0) / ((Dx - D0) / F) 
//
//  Example - System\ File Read Operations/sec 
//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
float MyComputeCounterValue( CounterSample s0, CounterSample s1 )
{
   float numerator = (float)(s1.RawValue - s0.RawValue);
   float denomenator = (float)(s1.TimeStamp - s0.TimeStamp) / (float)s1.SystemFrequency;
   float counterValue = numerator / denomenator;
   return counterValue;
}

void OutputSample( CounterSample s )
{
   Console::WriteLine( "\r\n+++++++++++" );
   Console::WriteLine( "Sample values - \r\n" );
   Console::WriteLine( "   BaseValue        = {0}", s.BaseValue );
   Console::WriteLine( "   CounterFrequency = {0}", s.CounterFrequency );
   Console::WriteLine( "   CounterTimeStamp = {0}", s.CounterTimeStamp );
   Console::WriteLine( "   CounterType      = {0}", s.CounterType );
   Console::WriteLine( "   RawValue         = {0}", s.RawValue );
   Console::WriteLine( "   SystemFrequency  = {0}", s.SystemFrequency );
   Console::WriteLine( "   TimeStamp        = {0}", s.TimeStamp );
   Console::WriteLine( "   TimeStamp100nSec = {0}", s.TimeStamp100nSec );
   Console::WriteLine( "++++++++++++++++++++++" );
}

bool SetupCategory()
{
   if (  !PerformanceCounterCategory::Exists( "RateOfCountsPerSecond64SampleCategory" ) )
   {
      CounterCreationDataCollection^ CCDC = gcnew CounterCreationDataCollection;

      // Add the counter.
      CounterCreationData^ rateOfCounts64 = gcnew CounterCreationData;
      rateOfCounts64->CounterType = PerformanceCounterType::RateOfCountsPerSecond64;
      rateOfCounts64->CounterName = "RateOfCountsPerSecond64Sample";
      CCDC->Add( rateOfCounts64 );

      // Create the category.
      PerformanceCounterCategory::Create( "RateOfCountsPerSecond64SampleCategory", "Demonstrates usage of the RateOfCountsPerSecond64 performance counter type.", CCDC );
      return true;
   }
   else
   {
      Console::WriteLine( "Category exists - RateOfCountsPerSecond64SampleCategory" );
      return false;
   }
}

void CreateCounters( PerformanceCounter^% PC )
{
   // Create the counter.
   PC = gcnew PerformanceCounter( "RateOfCountsPerSecond64SampleCategory","RateOfCountsPerSecond64Sample",false );
   PC->RawValue = 0;
}

void CollectSamples( ArrayList^ samplesList, PerformanceCounter^ PC )
{
   Random^ r = gcnew Random( DateTime::Now.Millisecond );

   // Initialize the performance counter.
   PC->NextSample();

   // Loop for the samples.
   for ( int j = 0; j < 100; j++ )
   {
      int value = r->Next( 1, 10 );
      PC->IncrementBy( value );
      Console::Write( "{0} = {1}", j, value );
      if ( (j % 10) == 9 )
      {
         Console::WriteLine( ";       NextValue() = {0}", PC->NextValue() );
         OutputSample( PC->NextSample() );
         samplesList->Add( PC->NextSample() );
      }
      else
            Console::WriteLine();
      System::Threading::Thread::Sleep( 50 );
   }
}

void CalculateResults( ArrayList^ samplesList )
{
   for ( int i = 0; i < (samplesList->Count - 1); i++ )
   {
      // Output the sample.
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i ]) );
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) );

      // Use .NET to calculate the counter value.
      Console::WriteLine( ".NET computed counter value = {0}", CounterSampleCalculator::ComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );

      // Calculate the counter value manually.
      Console::WriteLine( "My computed counter value = {0}", MyComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]),  *safe_cast<CounterSample^>(samplesList[ i + 1 ]) ) );
   }
}

int main()
{
   ArrayList^ samplesList = gcnew ArrayList;
   PerformanceCounter^ PC;
   SetupCategory();
   CreateCounters( PC );
   CollectSamples( samplesList, PC );
   CalculateResults( samplesList );
}

RawFraction

Imports System
Imports System.Collections
Imports System.Collections.Specialized
Imports System.Diagnostics

 _


Public Class App
   Private Shared PC As PerformanceCounter
   Private Shared BPC As PerformanceCounter
   
   
   Public Shared Sub Main()
      Dim samplesList As New ArrayList()
      
      SetupCategory()
      CreateCounters()
      CollectSamples(samplesList)
      CalculateResults(samplesList)
   End Sub 'Main
   
   
   Private Shared Function SetupCategory() As Boolean
      
      
      If Not PerformanceCounterCategory.Exists("RawFractionSampleCategory") Then
         
         
         Dim CCDC As New CounterCreationDataCollection()
         
         ' Add the counter.
         Dim rf As New CounterCreationData()
         rf.CounterType = PerformanceCounterType.RawFraction
         rf.CounterName = "RawFractionSample"
         CCDC.Add(rf)
         
         ' Add the base counter.
         Dim rfBase As New CounterCreationData()
         rfBase.CounterType = PerformanceCounterType.RawBase
         rfBase.CounterName = "RawFractionSampleBase"
         CCDC.Add(rfBase)
         
         ' Create the category.
         PerformanceCounterCategory.Create("RawFractionSampleCategory", "Demonstrates usage of the RawFraction performance counter type.", CCDC)
         
         Return True
      Else
         Console.WriteLine("Category exists - RawFractionSampleCategory")
         Return False
      End If
   End Function 'SetupCategory
   
   
   Private Shared Sub CreateCounters()
      ' Create the counters.
      PC = New PerformanceCounter("RawFractionSampleCategory", "RawFractionSample", False)
      
      BPC = New PerformanceCounter("RawFractionSampleCategory", "RawFractionSampleBase", False)
      
      PC.RawValue = 0
      BPC.RawValue = 0
   End Sub 'CreateCounters
   
   
   Private Shared Sub CollectSamples(samplesList As ArrayList)
      
      Dim r As New Random(DateTime.Now.Millisecond)
      
      ' Initialize the performance counter.
      PC.NextSample()
      
      ' Loop for the samples.
      Dim j As Integer
      For j = 0 To 99
         Dim value As Integer = r.Next(1, 10)
         Console.Write((j + " = " + value))
         
         ' Increment the base every time, because the counter measures the number 
         ' of high hits (raw fraction value) against all the hits (base value).
         BPC.Increment()
         
         ' Get the % of samples that are 9 or 10 out of all the samples taken.
         If value >= 9 Then
            PC.Increment()
         End If 
         ' Copy out the next value every ten times around the loop.
         If j Mod 10 = 9 Then
            Console.WriteLine((";       NextValue() = " + PC.NextValue().ToString()))
            OutputSample(PC.NextSample())
            samplesList.Add(PC.NextSample())
         Else
            Console.WriteLine()
         End If 
         System.Threading.Thread.Sleep(50)
      Next j
   End Sub 'CollectSamples
    
   
   
   Private Shared Sub CalculateResults(samplesList As ArrayList)
      Dim i As Integer
      For i = 0 To samplesList.Count - 1
         ' Output the sample.
         OutputSample(CType(samplesList(i), CounterSample))
         
         ' Use .NET to calculate the counter value.
         Console.WriteLine((".NET computed counter value = " + CounterSampleCalculator.ComputeCounterValue(CType(samplesList(i), CounterSample))))
         
         ' Calculate the counter value manually.
         Console.WriteLine(("My computed counter value = " + MyComputeCounterValue(CType(samplesList(i), CounterSample))))
      Next i
   End Sub 'CalculateResults
    
   
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   ' Formula from MSDN -
   '      Description - This counter type shows the ratio of a subset to its set as a percentage.
   '            For example, it compares the number of bytes in use on a disk to the
   '            total number of bytes on the disk. Counters of this type display the 
   '            current percentage only, not an average over time.
   '
   ' Generic type - Instantaneous, Percentage 
   '        Formula - (N0 / D0), where D represents a measured attribute and N represents one
   '            component of that attribute.
   '
   '        Average - SUM (N / D) /x 
   '        Example - Paging File\% Usage Peak
   '++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
   Private Shared Function MyComputeCounterValue(rfSample As CounterSample) As [Single]
      Dim numerator As [Single] = CType(rfSample.RawValue, [Single])
      Dim denomenator As [Single] = CType(rfSample.BaseValue, [Single])
      Dim counterValue As [Single] = numerator / denomenator * 100
      Return counterValue
   End Function 'MyComputeCounterValue
   
   
   ' Output information about the counter sample.
   Private Shared Sub OutputSample(s As CounterSample)
      Console.WriteLine("+++++++++++")
      Console.WriteLine("Sample values - " + ControlChars.Lf + ControlChars.Cr)
      Console.WriteLine(("   BaseValue        = " + s.BaseValue))
      Console.WriteLine(("   CounterFrequency = " + s.CounterFrequency))
      Console.WriteLine(("   CounterTimeStamp = " + s.CounterTimeStamp))
      Console.WriteLine(("   CounterType      = " + s.CounterType))
      Console.WriteLine(("   RawValue         = " + s.RawValue))
      Console.WriteLine(("   SystemFrequency  = " + s.SystemFrequency))
      Console.WriteLine(("   TimeStamp        = " + s.TimeStamp))
      Console.WriteLine(("   TimeStamp100nSec = " + s.TimeStamp100nSec))
      Console.WriteLine("++++++++++++++++++++++")
   End Sub 'OutputSample
End Class 'App 


using System;
using System.Collections;
using System.Collections.Specialized;
using System.Diagnostics;


public class App 
{
    private static PerformanceCounter PC;
    private static PerformanceCounter BPC;

    public static void Main()
    {   
        ArrayList samplesList = new ArrayList();

        SetupCategory();
        CreateCounters();
        CollectSamples(samplesList);
        CalculateResults(samplesList);
    }

    private static bool SetupCategory()
    {


        if ( !PerformanceCounterCategory.Exists("RawFractionSampleCategory") ) 
        {


            CounterCreationDataCollection CCDC = new CounterCreationDataCollection();

            // Add the counter.
            CounterCreationData rf = new CounterCreationData();
            rf.CounterType = PerformanceCounterType.RawFraction;
            rf.CounterName = "RawFractionSample";
            CCDC.Add(rf);
        
            // Add the base counter.
            CounterCreationData rfBase = new CounterCreationData();
            rfBase.CounterType = PerformanceCounterType.RawBase;
            rfBase.CounterName = "RawFractionSampleBase";
            CCDC.Add(rfBase);

            // Create the category.
            PerformanceCounterCategory.Create("RawFractionSampleCategory", 
                "Demonstrates usage of the RawFraction performance counter type.", 
                CCDC);

            return(true);
        }
        else
        {
            Console.WriteLine("Category exists - RawFractionSampleCategory");
            return(false);
        }
    }

    private static void CreateCounters()
    {
        // Create the counters.
        PC = new PerformanceCounter("RawFractionSampleCategory", 
            "RawFractionSample", 
            false);
        
        BPC = new PerformanceCounter("RawFractionSampleCategory", 
            "RawFractionSampleBase", 
            false);
        
        PC.RawValue=0;
        BPC.RawValue=0;
    }

    private static void CollectSamples(ArrayList samplesList)
    {
    
        Random r = new Random( DateTime.Now.Millisecond );

        // Initialize the performance counter.
        PC.NextSample();

        // Loop for the samples.
        for (int j = 0; j < 100; j++) 
        {
            int value = r.Next(1, 10);
            Console.Write(j + " = " + value);

            // Increment the base every time, because the counter measures the number 
            // of high hits (raw fraction value) against all the hits (base value).
            BPC.Increment();

            // Get the % of samples that are 9 or 10 out of all the samples taken.
            if (value >= 9)
                PC.Increment();

            // Copy out the next value every ten times around the loop.
            if ((j % 10) == 9) 
            {
                Console.WriteLine(";       NextValue() = " + PC.NextValue().ToString());
                OutputSample(PC.NextSample());
                samplesList.Add( PC.NextSample() );
            }
            else
                Console.WriteLine();
        
            System.Threading.Thread.Sleep(50);
        }

    }


    private static void CalculateResults(ArrayList samplesList)
    {
        for(int i = 0; i < samplesList.Count; i++)
        {
            // Output the sample.
            OutputSample( (CounterSample)samplesList[i] );

            // Use .NET to calculate the counter value.
            Console.WriteLine(".NET computed counter value = " + 
                CounterSampleCalculator.ComputeCounterValue((CounterSample)samplesList[i]));

            // Calculate the counter value manually.
            Console.WriteLine("My computed counter value = " + 
                MyComputeCounterValue((CounterSample)samplesList[i]));

        }
    }

    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    // Formula from MSDN -
    //      Description - This counter type shows the ratio of a subset to its set as a percentage.
    //          For example, it compares the number of bytes in use on a disk to the
    //          total number of bytes on the disk. Counters of this type display the 
    //          current percentage only, not an average over time.
    //
    // Generic type - Instantaneous, Percentage 
    //      Formula - (N0 / D0), where D represents a measured attribute and N represents one
    //          component of that attribute.
    //
    //      Average - SUM (N / D) /x 
    //      Example - Paging File\% Usage Peak
    //++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
    private static Single MyComputeCounterValue(CounterSample rfSample)
    {
        Single numerator = (Single)rfSample.RawValue;
        Single denomenator = (Single)rfSample.BaseValue;
        Single counterValue = (numerator / denomenator) * 100;
        return(counterValue);
    }

    // Output information about the counter sample.
    private static void OutputSample(CounterSample s)
    {
        Console.WriteLine("+++++++++++");
        Console.WriteLine("Sample values - \r\n");
        Console.WriteLine("   BaseValue        = " + s.BaseValue);
        Console.WriteLine("   CounterFrequency = " + s.CounterFrequency);
        Console.WriteLine("   CounterTimeStamp = " + s.CounterTimeStamp);
        Console.WriteLine("   CounterType      = " + s.CounterType);
        Console.WriteLine("   RawValue         = " + s.RawValue);
        Console.WriteLine("   SystemFrequency  = " + s.SystemFrequency);
        Console.WriteLine("   TimeStamp        = " + s.TimeStamp);
        Console.WriteLine("   TimeStamp100nSec = " + s.TimeStamp100nSec);
        Console.WriteLine("++++++++++++++++++++++");
    }



}
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::Collections::Specialized;
using namespace System::Diagnostics;

//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
// Formula from MSDN -
//      Description - This counter type shows the ratio of a subset to its set as a percentage.
//            For example, it compares the number of bytes in use on a disk to the
//            total number of bytes on the disk. Counters of this type display the 
//            current percentage only, not an average over time.
//
// Generic type - Instantaneous, Percentage 
//        Formula - (N0 / D0), where D represents a measured attribute and N represents one
//            component of that attribute.
//
//        Average - SUM (N / D) /x 
//        Example - Paging File\% Usage Peak
//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++//++++++++
float MyComputeCounterValue( CounterSample rfSample )
{
   float numerator = (float)rfSample.RawValue;
   float denomenator = (float)rfSample.BaseValue;
   float counterValue = (numerator / denomenator) * 100;
   return counterValue;
}


// Output information about the counter sample.
void OutputSample( CounterSample s )
{
   Console::WriteLine( "+++++++++++" );
   Console::WriteLine( "Sample values - \r\n" );
   Console::WriteLine( "   BaseValue        = {0}", s.BaseValue );
   Console::WriteLine( "   CounterFrequency = {0}", s.CounterFrequency );
   Console::WriteLine( "   CounterTimeStamp = {0}", s.CounterTimeStamp );
   Console::WriteLine( "   CounterType      = {0}", s.CounterType );
   Console::WriteLine( "   RawValue         = {0}", s.RawValue );
   Console::WriteLine( "   SystemFrequency  = {0}", s.SystemFrequency );
   Console::WriteLine( "   TimeStamp        = {0}", s.TimeStamp );
   Console::WriteLine( "   TimeStamp100nSec = {0}", s.TimeStamp100nSec );
   Console::WriteLine( "++++++++++++++++++++++" );
}

bool SetupCategory()
{
   if (  !PerformanceCounterCategory::Exists( "RawFractionSampleCategory" ) )
   {
      CounterCreationDataCollection^ CCDC = gcnew CounterCreationDataCollection;
      
      // Add the counter.
      CounterCreationData^ rf = gcnew CounterCreationData;
      rf->CounterType = PerformanceCounterType::RawFraction;
      rf->CounterName = "RawFractionSample";
      CCDC->Add( rf );
      
      // Add the base counter.
      CounterCreationData^ rfBase = gcnew CounterCreationData;
      rfBase->CounterType = PerformanceCounterType::RawBase;
      rfBase->CounterName = "RawFractionSampleBase";
      CCDC->Add( rfBase );
      
      // Create the category.
      PerformanceCounterCategory::Create( "RawFractionSampleCategory", "Demonstrates usage of the RawFraction performance counter type.", CCDC );
      return true;
   }
   else
   {
      Console::WriteLine( "Category exists - RawFractionSampleCategory" );
      return false;
   }
}

void CreateCounters( PerformanceCounter^% PC, PerformanceCounter^% BPC )
{
   
   // Create the counters.
   PC = gcnew PerformanceCounter( "RawFractionSampleCategory","RawFractionSample",false );
   BPC = gcnew PerformanceCounter( "RawFractionSampleCategory","RawFractionSampleBase",false );
   PC->RawValue = 0;
   BPC->RawValue = 0;
}

void CollectSamples( ArrayList^ samplesList, PerformanceCounter^ PC, PerformanceCounter^ BPC )
{
   Random^ r = gcnew Random( DateTime::Now.Millisecond );
   
   // Initialize the performance counter.
   PC->NextSample();
   
   // Loop for the samples.
   for ( int j = 0; j < 100; j++ )
   {
      int value = r->Next( 1, 10 );
      Console::Write( "{0} = {1}", j, value );
      
      // Increment the base every time, because the counter measures the number 
      // of high hits (raw fraction value) against all the hits (base value).
      BPC->Increment();
      
      // Get the % of samples that are 9 or 10 out of all the samples taken.
      if ( value >= 9 )
            PC->Increment();
      
      // Copy out the next value every ten times around the loop.
      if ( (j % 10) == 9 )
      {
         Console::WriteLine( ";       NextValue() = {0}", PC->NextValue() );
         OutputSample( PC->NextSample() );
         samplesList->Add( PC->NextSample() );
      }
      else
            Console::WriteLine();
      System::Threading::Thread::Sleep( 50 );

   }
}

void CalculateResults( ArrayList^ samplesList )
{
   for ( int i = 0; i < samplesList->Count; i++ )
   {
      
      // Output the sample.
      OutputSample(  *safe_cast<CounterSample^>(samplesList[ i ]) );
      
      // Use .NET to calculate the counter value.
      Console::WriteLine( ".NET computed counter value = {0}", CounterSampleCalculator::ComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]) ) );
      
      // Calculate the counter value manually.
      Console::WriteLine( "My computed counter value = {0}", MyComputeCounterValue(  *safe_cast<CounterSample^>(samplesList[ i ]) ) );

   }
}

int main()
{
   ArrayList^ samplesList = gcnew ArrayList;
   PerformanceCounter^ PC;
   PerformanceCounter^ BPC;
   SetupCategory();
   CreateCounters( PC, BPC );
   CollectSamples( samplesList, PC, BPC );
   CalculateResults( samplesList );
}

Plattformen

Windows 98, Windows 2000 SP4, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

System.Diagnostics-Namespace
PerformanceCounter-Klasse