/// <summary> /// Создать дескриптор счётчика /// </summary> /// <param name="type">Тип счётчика</param> /// <param name="counterName">Имя счётчика</param> /// <param name="counterDescription">Описание счётчика</param> /// <param name="info">Информацию по функционированию</param> /// <returns>Созданный дескриптор</returns> public static WinCounterDescriptor CreateCounterDescriptor(CounterTypes type, string counterName, string counterDescription, WinCountersWorkingInfo info) { switch (type) { case CounterTypes.NumberOfItems: return(WinNumberOfItemsCounter.CreateDescriptor(counterName, counterDescription, info)); case CounterTypes.Delta: return(WinDeltaCounter.CreateDescriptor(counterName, counterDescription, info)); case CounterTypes.AverageTime: return(WinAverageTimeCounter.CreateDescriptor(counterName, counterDescription, info)); case CounterTypes.AverageCount: return(WinAverageCountCounter.CreateDescriptor(counterName, counterDescription, info)); case CounterTypes.OperationsPerSecond: return(WinOperationsPerSecondCounter.CreateDescriptor(counterName, counterDescription, info)); case CounterTypes.ElapsedTime: return(WinElapsedTimeCounter.CreateDescriptor(counterName, counterDescription, info)); case CounterTypes.MomentTime: return(WinMomentTimeCounter.CreateDescriptor(counterName, counterDescription, info)); default: throw new InvalidOperationException("Unknown CounterTypes value: " + type.ToString()); } }
/// <summary> /// Создать счётчик определённого типа /// </summary> /// <param name="type">Тип счётчика</param> /// <param name="counterName">Имя счётчика</param> /// <param name="counterDescription">Описание счётчика</param> /// <returns>Счётчик</returns> public override Counter CreateCounter(CounterTypes type, string counterName, string counterDescription) { if (counterName == null) { throw new ArgumentNullException("counterName"); } if (counterDescription == null) { throw new ArgumentNullException("counterDescription"); } if (_counters.ContainsKey(counterName)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } Counter res = null; switch (type) { case CounterTypes.NumberOfItems: res = new InternalNumberOfItemsCounter(counterName, counterDescription); break; case CounterTypes.Delta: res = new InternalDeltaCounter(counterName, counterDescription); break; case CounterTypes.AverageTime: res = new InternalAverageTimeCounter(counterName, counterDescription); break; case CounterTypes.AverageCount: res = new InternalAverageCountCounter(counterName, counterDescription); break; case CounterTypes.OperationsPerSecond: res = new InternalOperationsPerSecondCounter(counterName, counterDescription); break; case CounterTypes.ElapsedTime: res = new InternalElapsedTimeCounter(counterName, counterDescription); break; case CounterTypes.MomentTime: res = new InternalMomentTimeCounter(counterName, counterDescription); break; default: throw new InvalidOperationException("Unknown CounterTypes value: " + type.ToString()); } if (!_counters.TryAdd(counterName, res)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } _isCountersChanged = true; return(res); }
/// <summary> /// Получение счетчика определенного типа. Всегда создаёт новый. /// </summary> /// <param name="counterName">Имя счетчика</param> /// <param name="expectedCounterType">Тип счётчика</param> /// <returns>Счётчик</returns> public override Counter GetCounter(string counterName, CounterTypes expectedCounterType) { if (counterName == null) { throw new ArgumentNullException("counterName"); } switch (expectedCounterType) { case CounterTypes.NumberOfItems: return(new NullNumberOfItemsCounter(counterName, counterName)); case CounterTypes.Delta: return(new NullDeltaCounter(counterName, counterName)); case CounterTypes.AverageTime: return(new NullAverageTimeCounter(counterName, counterName)); case CounterTypes.AverageCount: return(new NullAverageCountCounter(counterName, counterName)); case CounterTypes.OperationsPerSecond: return(new NullOperationPerSecondCounter(counterName, counterName)); case CounterTypes.ElapsedTime: return(new NullElapsedTimeCounter(counterName, counterName)); case CounterTypes.MomentTime: return(new NullMomentTimeCounter(counterName, counterName)); default: throw new InvalidOperationException("Unknown CounterTypes value: " + expectedCounterType.ToString()); } }
/// <summary> /// Создать счётчик определённого типа /// </summary> /// <param name="type">Тип счётчика</param> /// <param name="counterName">Имя счётчика</param> /// <param name="counterDescription">Описание счётчика</param> /// <returns>Счётчик</returns> public override Counter CreateCounter(CounterTypes type, string counterName, string counterDescription) { if (counterName == null) { throw new ArgumentNullException("counterName"); } if (counterDescription == null) { throw new ArgumentNullException("counterDescription"); } if (_counters.ContainsKey(counterName)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } Counter res = null; switch (type) { case CounterTypes.NumberOfItems: res = new CompositeNumberOfItemsCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateNumberOfItemsCounter(counterName, counterDescription))); break; case CounterTypes.Delta: res = new CompositeDeltaCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateDeltaCounter(counterName, counterDescription))); break; case CounterTypes.AverageTime: res = new CompositeAverageTimeCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateAverageTimeCounter(counterName, counterDescription))); break; case CounterTypes.AverageCount: res = new CompositeAverageCountCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateAverageCountCounter(counterName, counterDescription))); break; case CounterTypes.OperationsPerSecond: res = new CompositeOperationsPerSecondCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateOperationsPerSecondCounter(counterName, counterDescription))); break; case CounterTypes.ElapsedTime: res = new CompositeElapsedTimeCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateElapsedTimeCounter(counterName, counterDescription))); break; case CounterTypes.MomentTime: res = new CompositeMomentTimeCounter(counterName, counterDescription, _wrappedCategories.Select(wc => wc.CreateMomentTimeCounter(counterName, counterDescription))); break; default: throw new InvalidOperationException("Unknown CounterTypes value: " + type.ToString()); } if (!_counters.TryAdd(counterName, res)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } return(res); }
/// <summary> /// Создать счётчик определённого типа /// </summary> /// <param name="type">Тип счётчика</param> /// <param name="counterName">Имя счетчика</param> /// <param name="counterDescription">Описание счетчика</param> public override void CreateCounter(CounterTypes type, string counterName, string counterDescription) { if (counterName == null) { throw new ArgumentNullException("counterName"); } if (counterDescription == null) { throw new ArgumentNullException("counterDescription"); } if (_instances.Count != 0) { throw new PerformanceCounterCreationException( string.Format("Can't create counter in multiInstanceCategory ({0}) when it has created instances", this.Name)); } if (_counters.ContainsKey(counterName)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } CompositeCounterDescriptor res = null; switch (type) { case CounterTypes.NumberOfItems: res = CompositeNumberOfItemsCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.Delta: res = CompositeDeltaCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.AverageTime: res = CompositeAverageTimeCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.AverageCount: res = CompositeAverageCountCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.OperationsPerSecond: res = CompositeOperationsPerSecondCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.ElapsedTime: res = CompositeElapsedTimeCounter.CreateDescriptor(counterName, counterDescription); break; case CounterTypes.MomentTime: res = CompositeMomentTimeCounter.CreateDescriptor(counterName, counterDescription); break; default: throw new InvalidOperationException("Unknown CounterTypes value: " + type.ToString()); } if (!_counters.TryAdd(counterName, res)) { throw new DuplicateCounterNameException("Counter with the same name is already existed. Name: " + counterName); } foreach (var wrappedCat in _wrappedCategories) { wrappedCat.CreateCounter(type, counterName, counterDescription); } }
/// <summary> /// Преобразовать тип счётчика из внутреннего в Windows /// </summary> /// <param name="srcType">Исходный тип счётчика</param> /// <param name="prefer64BitCounter">Предпочитать ли 64-ёх битные счётчики</param> /// <returns>Преобразованный тип счётчика</returns> public static PerformanceCounterType ConvertCounterType(CounterTypes srcType, bool prefer64BitCounter) { switch (srcType) { case CounterTypes.NumberOfItems: if (prefer64BitCounter) { return(PerformanceCounterType.NumberOfItems64); } else { return(PerformanceCounterType.NumberOfItems32); } case CounterTypes.OperationsPerSecond: if (prefer64BitCounter) { return(PerformanceCounterType.RateOfCountsPerSecond64); } else { return(PerformanceCounterType.RateOfCountsPerSecond32); } //case CounterTypes.CountPerTimeInterval: // break; case CounterTypes.AverageCount: return(PerformanceCounterType.AverageCount64); case CounterTypes.AverageTime: return(PerformanceCounterType.AverageTimer32); case CounterTypes.MomentTime: if (prefer64BitCounter) { return(PerformanceCounterType.NumberOfItems64); } else { return(PerformanceCounterType.NumberOfItems32); } //case CounterTypes.RawFraction: // break; //case CounterTypes.CounterMultiTimer: // break; //case CounterTypes.SampleCounter: // break; //case CounterTypes.SampleFraction: // break; case CounterTypes.Delta: if (prefer64BitCounter) { return(PerformanceCounterType.CounterDelta64); } else { return(PerformanceCounterType.CounterDelta32); } case CounterTypes.ElapsedTime: return(PerformanceCounterType.ElapsedTime); default: throw new InvalidOperationException("Unknown CounterTypes value: " + srcType.ToString()); } }