internal CounterSetInstanceCounterDataSet(CounterSetInstance thisInst) { _instance = thisInst; _counters = new Dictionary <int, CounterData>(); unsafe { if (_instance._counterSet._provider == null) { throw new ArgumentException(SR.Format(SR.Perflib_Argument_ProviderNotFound, _instance._counterSet._providerGuid), "ProviderGuid"); } if (_instance._counterSet._provider._hProvider.IsInvalid) { throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_NoActiveProvider, _instance._counterSet._providerGuid)); } _dataBlock = (byte *)Marshal.AllocHGlobal(_instance._counterSet._idToCounter.Count * sizeof(long)); if (_dataBlock == null) { throw new InsufficientMemoryException(SR.Format(SR.Perflib_InsufficientMemory_InstanceCounterBlock, _instance._counterSet._counterSet, _instance._instName)); } int CounterOffset = 0; foreach (KeyValuePair <int, CounterType> CounterDef in _instance._counterSet._idToCounter) { CounterData thisCounterData = new CounterData((long *)(_dataBlock + CounterOffset * sizeof(long))); _counters.Add(CounterDef.Key, thisCounterData); // ArgumentNullException - CounterName is NULL // ArgumentException - CounterName already exists. uint Status = Interop.PerfCounter.PerfSetCounterRefValue( _instance._counterSet._provider._hProvider, _instance._nativeInst, (uint)CounterDef.Key, (void *)(_dataBlock + CounterOffset * sizeof(long))); if (Status != (uint)Interop.Errors.ERROR_SUCCESS) { Dispose(true); // ERROR_INVALID_PARAMETER or ERROR_NOT_FOUND switch (Status) { case (uint)Interop.Errors.ERROR_NOT_FOUND: throw new InvalidOperationException(SR.Format(SR.Perflib_InvalidOperation_CounterRefValue, _instance._counterSet._counterSet, CounterDef.Key, _instance._instName)); default: throw new Win32Exception((int)Status); } } CounterOffset++; } } }
internal CounterSetInstanceCounterDataSet(CounterSetInstance thisInst) { m_instance = thisInst; m_counters = new Dictionary <Int32, CounterData>(); unsafe { if (m_instance.m_counterSet.m_provider == null) { throw new ArgumentException(SR.GetString(SR.Perflib_Argument_ProviderNotFound, m_instance.m_counterSet.m_providerGuid), "ProviderGuid"); } if (m_instance.m_counterSet.m_provider.m_hProvider.IsInvalid) { throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_NoActiveProvider, m_instance.m_counterSet.m_providerGuid)); } m_dataBlock = (byte *)Marshal.AllocHGlobal(m_instance.m_counterSet.m_idToCounter.Count * sizeof(Int64)); if (m_dataBlock == null) { throw new InsufficientMemoryException(SR.GetString(SR.Perflib_InsufficientMemory_InstanceCounterBlock, m_instance.m_counterSet.m_counterSet, m_instance.m_instName)); } Int32 CounterOffset = 0; foreach (KeyValuePair <Int32, CounterType> CounterDef in m_instance.m_counterSet.m_idToCounter) { CounterData thisCounterData = new CounterData((Int64 *)(m_dataBlock + CounterOffset * sizeof(Int64))); m_counters.Add(CounterDef.Key, thisCounterData); // ArgumentNullException - CounterName is NULL // ArgumentException - CounterName already exists. uint Status = UnsafeNativeMethods.PerfSetCounterRefValue( m_instance.m_counterSet.m_provider.m_hProvider, m_instance.m_nativeInst, (uint)CounterDef.Key, (void *)(m_dataBlock + CounterOffset * sizeof(Int64))); if (Status != (uint)UnsafeNativeMethods.ERROR_SUCCESS) { Dispose(true); // ERROR_INVALID_PARAMETER or ERROR_NOT_FOUND switch (Status) { case (uint)UnsafeNativeMethods.ERROR_NOT_FOUND: throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_CounterRefValue, m_instance.m_counterSet.m_counterSet, CounterDef.Key, m_instance.m_instName)); default: throw new Win32Exception((int)Status); } } CounterOffset++; } } }
internal unsafe CounterSetInstanceCounterDataSet(CounterSetInstance thisInst) { this.m_instance = thisInst; this.m_counters = new Dictionary <int, CounterData>(); if (this.m_instance.m_counterSet.m_provider == null) { throw new ArgumentException(System.SR.GetString("Perflib_Argument_ProviderNotFound", new object[] { this.m_instance.m_counterSet.m_providerGuid }), "ProviderGuid"); } if (this.m_instance.m_counterSet.m_provider.m_hProvider.IsInvalid) { throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_NoActiveProvider", new object[] { this.m_instance.m_counterSet.m_providerGuid })); } this.m_dataBlock = (byte *)Marshal.AllocHGlobal((int)(this.m_instance.m_counterSet.m_idToCounter.Count * 8)); if (this.m_dataBlock == null) { throw new InsufficientMemoryException(System.SR.GetString("Perflib_InsufficientMemory_InstanceCounterBlock", new object[] { this.m_instance.m_counterSet.m_counterSet, this.m_instance.m_instName })); } int num = 0; foreach (KeyValuePair <int, CounterType> pair in this.m_instance.m_counterSet.m_idToCounter) { CounterData data = new CounterData((long)(this.m_dataBlock + (num * 8))); this.m_counters.Add(pair.Key, data); int num2 = Microsoft.Win32.UnsafeNativeMethods.PerfSetCounterRefValue(this.m_instance.m_counterSet.m_provider.m_hProvider, this.m_instance.m_nativeInst, pair.Key, (void *)(this.m_dataBlock + (num * 8))); if (num2 != 0) { this.Dispose(true); switch (num2) { case 0x490: throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_CounterRefValue", new object[] { this.m_instance.m_counterSet.m_counterSet, pair.Key, this.m_instance.m_instName })); } throw new Win32Exception((int)num2); } num++; } }
internal unsafe CounterSetInstanceCounterDataSet(CounterSetInstance thisInst) { this.m_instance = thisInst; this.m_counters = new Dictionary<int, CounterData>(); if (this.m_instance.m_counterSet.m_provider == null) { throw new ArgumentException(System.SR.GetString("Perflib_Argument_ProviderNotFound", new object[] { this.m_instance.m_counterSet.m_providerGuid }), "ProviderGuid"); } if (this.m_instance.m_counterSet.m_provider.m_hProvider.IsInvalid) { throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_NoActiveProvider", new object[] { this.m_instance.m_counterSet.m_providerGuid })); } this.m_dataBlock = (byte*) Marshal.AllocHGlobal((int) (this.m_instance.m_counterSet.m_idToCounter.Count * 8)); if (this.m_dataBlock == null) { throw new InsufficientMemoryException(System.SR.GetString("Perflib_InsufficientMemory_InstanceCounterBlock", new object[] { this.m_instance.m_counterSet.m_counterSet, this.m_instance.m_instName })); } int num = 0; foreach (KeyValuePair<int, CounterType> pair in this.m_instance.m_counterSet.m_idToCounter) { CounterData data = new CounterData((long)(this.m_dataBlock + (num * 8))); this.m_counters.Add(pair.Key, data); int num2 = Microsoft.Win32.UnsafeNativeMethods.PerfSetCounterRefValue(this.m_instance.m_counterSet.m_provider.m_hProvider, this.m_instance.m_nativeInst, pair.Key, (void*) (this.m_dataBlock + (num * 8))); if (num2 != 0) { this.Dispose(true); switch (num2) { case 0x490: throw new InvalidOperationException(System.SR.GetString("Perflib_InvalidOperation_CounterRefValue", new object[] { this.m_instance.m_counterSet.m_counterSet, pair.Key, this.m_instance.m_instName })); } throw new Win32Exception((int) num2); } num++; } }
internal CounterSetInstanceCounterDataSet(CounterSetInstance thisInst) { m_instance = thisInst; m_counters = new Dictionary<Int32, CounterData>(); unsafe { if (m_instance.m_counterSet.m_provider == null) { throw new ArgumentException(SR.GetString(SR.Perflib_Argument_ProviderNotFound, m_instance.m_counterSet.m_providerGuid), "ProviderGuid"); } if (m_instance.m_counterSet.m_provider.m_hProvider.IsInvalid) { throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_NoActiveProvider, m_instance.m_counterSet.m_providerGuid)); } m_dataBlock = (byte *) Marshal.AllocHGlobal(m_instance.m_counterSet.m_idToCounter.Count * sizeof(Int64)); if (m_dataBlock == null) { throw new InsufficientMemoryException(SR.GetString(SR.Perflib_InsufficientMemory_InstanceCounterBlock, m_instance.m_counterSet.m_counterSet, m_instance.m_instName)); } Int32 CounterOffset = 0; foreach (KeyValuePair<Int32, CounterType> CounterDef in m_instance.m_counterSet.m_idToCounter) { CounterData thisCounterData = new CounterData((Int64 *) (m_dataBlock + CounterOffset * sizeof(Int64))); m_counters.Add(CounterDef.Key, thisCounterData); // ArgumentNullException - CounterName is NULL // ArgumentException - CounterName already exists. uint Status = UnsafeNativeMethods.PerfSetCounterRefValue( m_instance.m_counterSet.m_provider.m_hProvider, m_instance.m_nativeInst, (uint) CounterDef.Key, (void *) (m_dataBlock + CounterOffset * sizeof(Int64))); if (Status != (uint) UnsafeNativeMethods.ERROR_SUCCESS) { Dispose(true); // ERROR_INVALID_PARAMETER or ERROR_NOT_FOUND switch (Status) { case (uint) UnsafeNativeMethods.ERROR_NOT_FOUND: throw new InvalidOperationException(SR.GetString(SR.Perflib_InvalidOperation_CounterRefValue, m_instance.m_counterSet.m_counterSet, CounterDef.Key, m_instance.m_instName)); default: throw new Win32Exception((int) Status); } } CounterOffset ++; } } }
private void UpdateCounterByValue(CounterData TargetCounterData, long stepAmount) { Debug.Assert(TargetCounterData != null); if (stepAmount == -1) { TargetCounterData.Decrement(); } else if (stepAmount == 1) { TargetCounterData.Increment(); } else { TargetCounterData.IncrementBy(stepAmount); } }
private void UpdateCounterByValue(CounterData TargetCounterData, long stepAmount) { if (stepAmount == -1L) { TargetCounterData.Decrement(); } else if (stepAmount == 1L) { TargetCounterData.Increment(); } else { TargetCounterData.IncrementBy(stepAmount); } }