13 private static volatile bool perfCounterDllLoaded;
22 if (oldSample.UnsignedRawValue >= (ulong)newSample.
CounterTimeStamp || num <= 0f)
26 float num2 = (float)(
double)(ulong)(newSample.
CounterTimeStamp - (
long)oldSample.UnsignedRawValue);
51 if (counterType != 537003008 && counterType != 65536 && counterType != 0 && counterType != 65792 && counterType != 256 && counterType != 1107494144)
60 if (counterType == 807666944)
62 return GetElapsedTime(oldSample, newSample);
64 Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER pDH_RAW_COUNTER =
new Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER();
65 Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER pDH_RAW_COUNTER2 =
new Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER();
66 FillInValues(oldSample, newSample, pDH_RAW_COUNTER2, pDH_RAW_COUNTER);
68 Microsoft.Win32.NativeMethods.PDH_FMT_COUNTERVALUE pDH_FMT_COUNTERVALUE =
new Microsoft.Win32.NativeMethods.PDH_FMT_COUNTERVALUE();
70 int num = Microsoft.Win32.SafeNativeMethods.FormatFromRawValue((uint)counterType, 37376u, ref pTimeBase, pDH_RAW_COUNTER, pDH_RAW_COUNTER2, pDH_FMT_COUNTERVALUE);
80 return (
float)pDH_FMT_COUNTERVALUE.data;
84 private static void FillInValues(
CounterSample oldSample,
CounterSample newSample, Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER oldPdhValue, Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER newPdhValue)
94 newPdhValue.FirstValue = newSample.
RawValue;
95 newPdhValue.SecondValue = newSample.
TimeStamp;
96 oldPdhValue.FirstValue = oldSample.
RawValue;
97 oldPdhValue.SecondValue = oldSample.
TimeStamp;
100 newPdhValue.FirstValue = newSample.
RawValue;
102 oldPdhValue.FirstValue = oldSample.
RawValue;
111 newPdhValue.FirstValue = newSample.
RawValue;
112 newPdhValue.SecondValue = newSample.
TimeStamp;
113 oldPdhValue.FirstValue = oldSample.
RawValue;
114 oldPdhValue.SecondValue = oldSample.
TimeStamp;
115 if (counterType == 574686464 || counterType == 591463680)
123 if ((counterType & 0x2000000) == 33554432)
125 newPdhValue.MultiCount = (int)newSample.
BaseValue;
126 oldPdhValue.MultiCount = (
int)oldSample.
BaseValue;
135 newPdhValue.FirstValue = newSample.
RawValue;
136 newPdhValue.SecondValue = 0
L;
137 oldPdhValue.FirstValue = oldSample.
RawValue;
138 oldPdhValue.SecondValue = 0
L;
144 newPdhValue.FirstValue = newSample.
RawValue;
146 oldPdhValue.FirstValue = oldSample.
RawValue;
148 if ((counterType & 0x2000000) == 33554432)
150 newPdhValue.MultiCount = (int)newSample.
BaseValue;
151 oldPdhValue.MultiCount = (
int)oldSample.
BaseValue;
162 newPdhValue.FirstValue = newSample.
RawValue;
163 newPdhValue.SecondValue = newSample.
BaseValue;
164 oldPdhValue.FirstValue = oldSample.
RawValue;
165 oldPdhValue.SecondValue = oldSample.
BaseValue;
168 newPdhValue.FirstValue = 0
L;
169 newPdhValue.SecondValue = 0
L;
170 oldPdhValue.FirstValue = 0
L;
171 oldPdhValue.SecondValue = 0
L;
176 private static void LoadPerfCounterDll()
178 if (!perfCounterDllLoaded)
182 string libFilename =
Path.
Combine(runtimeDirectory,
"perfcounter.dll");
183 if (Microsoft.Win32.SafeNativeMethods.LoadLibrary(libFilename) == IntPtr.Zero)
187 perfCounterDllLoaded =
true;
long BaseValue
Gets an optional, base raw value for the counter.
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
long TimeStamp
Gets the raw time stamp.
long RawValue
Gets the raw value of the counter.
static string Combine(string path1, string path2)
Combines two strings into a path.
long CounterTimeStamp
Gets the counter's time stamp.
static float ComputeCounterValue(CounterSample newSample)
Computes the calculated value of a single raw counter sample.
Provides a collection of static methods that return information about the common language runtime env...
static string GetRuntimeDirectory()
Returns the directory where the common language runtime is installed.
Provides a set of utility functions for interpreting performance counter data.
Defines a structure that holds the raw data for a performance counter.
static float ComputeCounterValue(CounterSample oldSample, CounterSample newSample)
Computes the calculated value of two raw counter samples.
Throws an exception for a Win32 error code.
PerformanceCounterType CounterType
Gets the performance counter type.
static CounterSample Empty
Defines an empty, uninitialized performance counter sample of type NumberOfItems32.
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
long TimeStamp100nSec
Gets the raw, high-fidelity time stamp.
long CounterFrequency
Gets the raw counter frequency.
PermissionState
Specifies whether a permission should have all or no access to resources at creation.
long SystemFrequency
Gets the raw system frequency.
The exception that is thrown when a method call is invalid for the object's current state.
void Assert()
Declares that the calling code can access the resource protected by a permission demand through the c...
Provides information about a specific culture (called a locale for unmanaged code development)....
Controls the ability to access files and folders. This class cannot be inherited.
static int GetLastWin32Error()
Returns the error code returned by the last unmanaged function that was called using platform invoke ...
Performs operations on T:System.String instances that contain file or directory path information....