public static float ComputeCounterValue(CounterSample oldSample, CounterSample newSample) { int counterType = (int)newSample.CounterType; if (oldSample.SystemFrequency == 0L) { if ((((counterType != 0x20020400) && (counterType != 0x10000)) && ((counterType != 0) && (counterType != 0x10100))) && ((counterType != 0x100) && (counterType != 0x42030500))) { return(0f); } } else if (oldSample.CounterType != newSample.CounterType) { throw new InvalidOperationException(SR.GetString("MismatchedCounterTypes")); } if (counterType == 0x30240500) { return(GetElapsedTime(oldSample, newSample)); } Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER newPdhValue = new Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER(); Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER oldPdhValue = new Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER(); FillInValues(oldSample, newSample, oldPdhValue, newPdhValue); LoadPerfCounterDll(); Microsoft.Win32.NativeMethods.PDH_FMT_COUNTERVALUE pFmtValue = new Microsoft.Win32.NativeMethods.PDH_FMT_COUNTERVALUE(); long systemFrequency = newSample.SystemFrequency; int error = Microsoft.Win32.SafeNativeMethods.FormatFromRawValue((uint)counterType, 0x9200, ref systemFrequency, newPdhValue, oldPdhValue, pFmtValue); switch (error) { case 0: return((float)pFmtValue.data); case -2147481640: case -2147481642: case -2147481643: return(0f); } throw new Win32Exception(error, SR.GetString("PerfCounterPdhError", new object[] { error.ToString("x", CultureInfo.InvariantCulture) })); }
public static float ComputeCounterValue(CounterSample oldSample, CounterSample newSample) { int counterType = (int) newSample.CounterType; if (oldSample.SystemFrequency == 0L) { if ((((counterType != 0x20020400) && (counterType != 0x10000)) && ((counterType != 0) && (counterType != 0x10100))) && ((counterType != 0x100) && (counterType != 0x42030500))) { return 0f; } } else if (oldSample.CounterType != newSample.CounterType) { throw new InvalidOperationException(SR.GetString("MismatchedCounterTypes")); } if (counterType == 0x30240500) { return GetElapsedTime(oldSample, newSample); } Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER newPdhValue = new Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER(); Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER oldPdhValue = new Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER(); FillInValues(oldSample, newSample, oldPdhValue, newPdhValue); LoadPerfCounterDll(); Microsoft.Win32.NativeMethods.PDH_FMT_COUNTERVALUE pFmtValue = new Microsoft.Win32.NativeMethods.PDH_FMT_COUNTERVALUE(); long systemFrequency = newSample.SystemFrequency; int error = Microsoft.Win32.SafeNativeMethods.FormatFromRawValue((uint) counterType, 0x9200, ref systemFrequency, newPdhValue, oldPdhValue, pFmtValue); switch (error) { case 0: return (float) pFmtValue.data; case -2147481640: case -2147481642: case -2147481643: return 0f; } throw new Win32Exception(error, SR.GetString("PerfCounterPdhError", new object[] { error.ToString("x", CultureInfo.InvariantCulture) })); }
public static extern int FormatFromRawValue(uint dwCounterType, uint dwFormat, ref long pTimeBase, Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER pRawValue1, Microsoft.Win32.NativeMethods.PDH_RAW_COUNTER pRawValue2, Microsoft.Win32.NativeMethods.PDH_FMT_COUNTERVALUE pFmtValue);