/// <summary> /// Counter manipulation method that takes pre-cached numeric key. /// <exception cref="ArgumentException">if previously cached key can't be found </exception> /// </summary> /// <param name="counterKey">numeric key that we map to category/instance/counter names </param> /// <param name="incrementAmount">the amount we wish to increment</param> public static void IncrementBy(int counterKey, long incrementAmount) { PerformanceCounterKey complexKey = GetPerformanceCounterKey(counterKey); System.Diagnostics.Debug.WriteLine("WindowsPerformanceFacade IncrementBy: '" + complexKey.CategoryName + ", " + complexKey.InstanceName + ", " + complexKey.CounterName + ", " + incrementAmount); liason.IncrementBy(complexKey.CategoryName, complexKey.InstanceName, complexKey.CounterName, incrementAmount); }
/// <summary> /// returns a numeric key for this counter path /// <exception cref="ArgumentException">if a categoryName or counterName is not provided</exception> /// </summary> /// <param name="categoryName">Performance category name</param> /// <param name="instanceName">Performance category instance name (optional)</param> /// <param name="counterName">Performance counter name</param> /// <returns>numer identifier that can be used as an id/key later</returns> public static int GetPerformanceCounterId(string categoryName, string instanceName, string counterName) { PerformanceCounterKey key = new PerformanceCounterKey(categoryName, instanceName, counterName); if (!keyToNames.ContainsKey(key.KeyCode)) { keyToNames.TryAdd(key.KeyCode, key); } return(key.KeyCode); }
/// <summary> /// Counter manipulation method that takes pre-cached numeric key. /// This is many times faster than incrementBy(1) /// <exception cref="ArgumentException">if previously cached key can't be found </exception> /// </summary> /// <param name="counterKey">numeric key that we map to category/instance/counter names </param> public static void Increment(int counterKey) { PerformanceCounterKey complexKey = GetPerformanceCounterKey(counterKey); liason.Increment(complexKey.CategoryName, complexKey.InstanceName, complexKey.CounterName); }
/// <summary> /// Gets the raw value of this counter /// </summary> /// <exception cref="ArgumentException">if a category counter or name is not provided</exception> /// </summary> /// <param name="counterKey">numeric key that we map to category/instance/counter names </param> public static long GetRawValue(int counterKey) { PerformanceCounterKey complexKey = GetPerformanceCounterKey(counterKey); return(liason.GetRawValue(complexKey.CategoryName, complexKey.InstanceName, complexKey.CounterName)); }
/// <summary> /// Sets the raw value of this counter /// </summary> /// <exception cref="System.InvalidOperationException">if this counter is ReadOnly</exception> /// <exception cref="ArgumentException">if previously cached key can't be found </exception> /// </summary> /// <param name="counterKey">numeric key that we map to category/instance/counter names </param> /// <param name="value">the new raw value for this counter</param> public static void SetRawValue(int counterKey, long value) { PerformanceCounterKey complexKey = GetPerformanceCounterKey(counterKey); liason.SetRawValue(complexKey.CategoryName, complexKey.InstanceName, complexKey.CounterName, value); }
/// <summary> /// Increments the counter by some specified amount (and its possible base by 1) /// <para></para> /// <exception cref="ArgumentException">if a category counter or name is not provided</exception> /// <para></para> /// <exception cref="System.InvalidOperationException">if this counter is ReadOnly or there is no associated base</exception> /// <param name="counterKey">numeric key that we map to category/instance/counter names </param> /// <param name="incrementAmount">increment amount</param> /// <param name="incrementBaseAmount">increment base counter amount</param> public static void IncrementBy(int counterKey, long incrementAmount, long incrementBaseAmount) { PerformanceCounterKey complexKey = GetPerformanceCounterKey(counterKey); liason.IncrementBy(complexKey.CategoryName, complexKey.InstanceName, complexKey.CounterName, incrementAmount, incrementBaseAmount); }