public ChoPerformanceCounter NewInstanceCounter(string instanceName) { ChoGuard.ArgumentNotNullOrEmpty(instanceName, "InstanceName"); ChoPerformanceCounter instancePerformanceCounter = new ChoPerformanceCounter(CategoryName, CounterName, CounterType, instanceName, ReadOnly); _instancePerformanceCounters.Add(instancePerformanceCounter); return(instancePerformanceCounter); }
public ChoPerformanceCounter(string categoryName, string counterName, PerformanceCounterType counterType, string instanceName, string machineName, bool readOnly, PerformanceCounterInstanceLifetime instanceLifetime) { if (instanceName == ChoPerformanceCounter.DefaultInstanceName) { _performanceCounter = new PerformanceCounter(categoryName, counterName); _performanceCounter.MachineName = machineName; } else { _performanceCounter = new PerformanceCounter(categoryName, counterName, instanceName, machineName); } _performanceCounter.ReadOnly = readOnly; _performanceCounter.InstanceLifetime = instanceLifetime; // create base counter if needed switch (counterType) { case PerformanceCounterType.AverageCount64: case PerformanceCounterType.AverageTimer32: case PerformanceCounterType.RawFraction: case PerformanceCounterType.CounterMultiTimer: case PerformanceCounterType.CounterMultiTimerInverse: case PerformanceCounterType.CounterMultiTimer100Ns: case PerformanceCounterType.CounterMultiTimer100NsInverse: case PerformanceCounterType.SampleCounter: case PerformanceCounterType.SampleFraction: { if (instanceName == ChoPerformanceCounter.DefaultInstanceName) { _performanceCounterBase = new PerformanceCounter(categoryName, ChoPerformanceCounter.GetBaseCounterName(counterName)); _performanceCounterBase.MachineName = machineName; } else { _performanceCounterBase = new PerformanceCounter(categoryName, ChoPerformanceCounter.GetBaseCounterName(counterName), instanceName, machineName); } _performanceCounterBase.ReadOnly = ReadOnly; _performanceCounterBase.InstanceLifetime = instanceLifetime; break; } default: break; } _metaDataInfo = new ChoPCMetaDataInfo(CounterName, instanceName) { TurnOn = true }; ChoPCMetaDataManager.Me.SetWatcher(this); }
/// <summary> /// Adds a RawFraction performance counter to the category collection. /// </summary> /// <remarks> /// Also adds the required base counter. /// </remarks> /// <param name="name">Performance counter name.</param> /// <param name="help">Performance counter help text.</param> public bool AddFractionCounter(string name, string help) { // add average counter bool retValue = AddCounter(name, PerformanceCounterType.RawFraction, help); // add the corresponding base counter if (retValue) { AddCounter(ChoPerformanceCounter.GetBaseCounterName(name), PerformanceCounterType.RawBase, null); } return(retValue); }
internal CounterCreationData[] CreateCounters() { List <CounterCreationData> counters = new List <CounterCreationData>(); if (MachineName.IsNullOrEmpty() || String.Compare(MachineName, Environment.MachineName, true) == 0) { counters.Add(new CounterCreationData(CounterName, CounterHelp, CounterType)); // create base counter if needed switch (CounterType) { case PerformanceCounterType.AverageCount64: case PerformanceCounterType.AverageTimer32: counters.Add(new CounterCreationData(ChoPerformanceCounter.GetBaseCounterName(CounterName), String.Empty, PerformanceCounterType.AverageBase)); break; case PerformanceCounterType.RawFraction: counters.Add(new CounterCreationData(ChoPerformanceCounter.GetBaseCounterName(CounterName), String.Empty, PerformanceCounterType.RawBase)); break; case PerformanceCounterType.CounterMultiTimer: case PerformanceCounterType.CounterMultiTimerInverse: case PerformanceCounterType.CounterMultiTimer100Ns: case PerformanceCounterType.CounterMultiTimer100NsInverse: counters.Add(new CounterCreationData(ChoPerformanceCounter.GetBaseCounterName(CounterName), String.Empty, PerformanceCounterType.CounterMultiBase)); break; case PerformanceCounterType.SampleCounter: case PerformanceCounterType.SampleFraction: counters.Add(new CounterCreationData(ChoPerformanceCounter.GetBaseCounterName(CounterName), String.Empty, PerformanceCounterType.SampleBase)); break; default: break; } } return(counters.ToArray()); }