Beispiel #1
0
        private static T CreateCounters <T>(string instance)
        {
            T result = Activator.CreateInstance <T>();

            try {
                IICPerformanceCountersAttribute categoryAttr = AttributeHelper.
                                                               GetAttribute <IICPerformanceCountersAttribute>(typeof(T));

                List <IICPerformanceCounter> counters = new List <IICPerformanceCounter>();

                FieldInfo[] fields = typeof(T).GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);

                foreach (FieldInfo fieldInfo in fields)
                {
                    IICPerformanceCounterAttribute counterAttr = AttributeHelper.
                                                                 GetAttribute <IICPerformanceCounterAttribute>(fieldInfo);

                    IICPerformanceCounter perfCounter = new IICPerformanceCounter();

                    perfCounter._rawAttr = counterAttr;
                    counters.Add(perfCounter);

                    fieldInfo.SetValue(result, perfCounter);
                }

                IICPerformanceCounterMananger.CreateCounters(instance, categoryAttr, counters);
            } catch (Exception ex) {
                SystemLog.Warn(LogEventID.PerformanceCounterFailed, ex, "PerformanceCounter<{0}>({1}) Create Failed.", typeof(T).Name, instance);
            }
            return(result);
        }
 public IICPerformanceCounter CreateCounter(string counterName, PerformanceCounterType counterType)
 {
     IICPerformanceCounter counter = new IICPerformanceCounter();
     counter._rawAttr = new IICPerformanceCounterAttribute(counterName, counterType);
     _counters.Add(counter);
     return counter;
 }
Beispiel #3
0
        public IICPerformanceCounter CreateCounter(string counterName, PerformanceCounterType counterType)
        {
            IICPerformanceCounter counter = new IICPerformanceCounter();

            counter._rawAttr = new IICPerformanceCounterAttribute(counterName, counterType);
            _counters.Add(counter);
            return(counter);
        }
Beispiel #4
0
        public static void EvoluteCounter(IICPerformanceCounter counter)
        {
            bool setBase = true;
            PerformanceCounterType baseCounterType = PerformanceCounterType.RawBase;

            switch (counter._rawAttr.CounterType)
            {
            case PerformanceCounterType.AverageCount64:
            case PerformanceCounterType.AverageTimer32:
                baseCounterType = PerformanceCounterType.AverageBase;
                break;

            case PerformanceCounterType.CounterMultiTimer:
            case PerformanceCounterType.CounterMultiTimer100Ns:
            case PerformanceCounterType.CounterMultiTimer100NsInverse:
            case PerformanceCounterType.CounterMultiTimerInverse:
                baseCounterType = PerformanceCounterType.CounterMultiBase;
                break;

            case PerformanceCounterType.RawFraction:
                baseCounterType = PerformanceCounterType.RawBase;
                break;

            case PerformanceCounterType.SampleCounter:
            case PerformanceCounterType.SampleFraction:
                baseCounterType = PerformanceCounterType.SampleBase;
                break;

            default:
                setBase = false;
                break;
            }

            if (setBase)
            {
                counter._baseAttr = new IICPerformanceCounterAttribute(
                    counter._rawAttr.CounterName + " Base",
                    baseCounterType,
                    counter._rawAttr.CounterHelp + " Base");
            }
        }
        public static void EvoluteCounter(IICPerformanceCounter counter)
        {
            bool setBase = true;
            PerformanceCounterType baseCounterType = PerformanceCounterType.RawBase;

            switch (counter._rawAttr.CounterType) {
                case PerformanceCounterType.AverageCount64:
                case PerformanceCounterType.AverageTimer32:
                    baseCounterType = PerformanceCounterType.AverageBase;
                    break;
                case PerformanceCounterType.CounterMultiTimer:
                case PerformanceCounterType.CounterMultiTimer100Ns:
                case PerformanceCounterType.CounterMultiTimer100NsInverse:
                case PerformanceCounterType.CounterMultiTimerInverse:
                    baseCounterType = PerformanceCounterType.CounterMultiBase;
                    break;
                case PerformanceCounterType.RawFraction:
                    baseCounterType = PerformanceCounterType.RawBase;
                    break;
                case PerformanceCounterType.SampleCounter:
                case PerformanceCounterType.SampleFraction:
                    baseCounterType = PerformanceCounterType.SampleBase;
                    break;
                default:
                    setBase = false;
                    break;
            }

            if (setBase) {
                counter._baseAttr = new IICPerformanceCounterAttribute(
                    counter._rawAttr.CounterName + " Base",
                    baseCounterType,
                    counter._rawAttr.CounterHelp + " Base");
            }
        }