Esempio n. 1
0
        private static PerformanceCounterType GetCounterType(System.Diagnostics.PerformanceCounterType type)
        {
            switch (type)
            {
            case System.Diagnostics.PerformanceCounterType.NumberOfItems32:
            case System.Diagnostics.PerformanceCounterType.NumberOfItems64:
            case System.Diagnostics.PerformanceCounterType.NumberOfItemsHEX32:
            case System.Diagnostics.PerformanceCounterType.NumberOfItemsHEX64:
                return(PerformanceCounterType.CountOfItems);

            case System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond32:
            case System.Diagnostics.PerformanceCounterType.RateOfCountsPerSecond64:
                return(PerformanceCounterType.CountPerSecond);

            case System.Diagnostics.PerformanceCounterType.CountPerTimeInterval32:
            case System.Diagnostics.PerformanceCounterType.CountPerTimeInterval64:
                return(PerformanceCounterType.CountOfItems);

            case System.Diagnostics.PerformanceCounterType.RawFraction:
            case System.Diagnostics.PerformanceCounterType.SampleFraction:
            case System.Diagnostics.PerformanceCounterType.CounterTimerInverse:
            case System.Diagnostics.PerformanceCounterType.Timer100Ns:
            case System.Diagnostics.PerformanceCounterType.Timer100NsInverse:
                return(PerformanceCounterType.PercentValue);

            case System.Diagnostics.PerformanceCounterType.AverageTimer32:
            case System.Diagnostics.PerformanceCounterType.AverageBase:
            case System.Diagnostics.PerformanceCounterType.AverageCount64:
            case System.Diagnostics.PerformanceCounterType.RawBase:
            case System.Diagnostics.PerformanceCounterType.SampleBase:
            case System.Diagnostics.PerformanceCounterType.SampleCounter:
                return(PerformanceCounterType.CountOfItems);

            case System.Diagnostics.PerformanceCounterType.ElapsedTime:
                return(PerformanceCounterType.ElapsedTime);

            case System.Diagnostics.PerformanceCounterType.CounterDelta32:
            case System.Diagnostics.PerformanceCounterType.CounterDelta64:
                return(PerformanceCounterType.DeltaValue);

            default:
                return(PerformanceCounterType.Unknown);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Construct a helper class to manage Perfmon counters for Connect
 /// </summary>
 /// <param name="category">The category for this counter</param>
 /// <param name="name">This counters name</param>
 /// <param name="counterHelp">This counters help string</param>
 /// <param name="type">This counters type</param>
 /// <param name="instance"></param>
 public PerformanceCounter(string category, string name, string counterHelp,
     PerformanceCounterType type, String instance)
 {
     _category = category;
     _name = name;
     _counterHelp = counterHelp;
     _type = type;
     _counterInstanceType = String.IsNullOrEmpty(instance) == false ? CounterInstanceType.Static : CounterInstanceType.Dynamic;
     _instance = instance;
 }
Esempio n. 3
0
 /// <summary>
 /// manage our performance monitors deserialization behavior
 /// </summary>
 /// <param name="info">Stores all the data to de/serialize this class</param>
 /// <param name="context">Describes source and destination of this serialized object</param>
 protected PerformanceCounter(SerializationInfo info, StreamingContext context)
 {
     _ticks = info.GetInt64("_ticks");
     _relativeCount = info.GetInt32("RelativeCount");
     _count = info.GetInt32("Count");
     _instance = info.GetString("Instance");
     _type = (PerformanceCounterType)info.GetValue("Type", typeof(System.Diagnostics.PerformanceCounterType));
     _name = info.GetString("Name");
     _counterHelp = info.GetString("CounterHelp");
     _category = info.GetString("Category");
 }
        private static void createCounterIfNotExist(string categoryName, string counterName, string counterHelp, System.Diagnostics.PerformanceCounterType type, System.Diagnostics.CounterCreationDataCollection counterDatas)
        {
            if (!System.Diagnostics.PerformanceCounterCategory.Exists(categoryName) ||
                !System.Diagnostics.PerformanceCounterCategory.CounterExists(counterName, categoryName))
            {
                System.Diagnostics.CounterCreationData counter =
                    new System.Diagnostics.CounterCreationData();
                counter.CounterName = counterName;
                counter.CounterHelp = counterHelp;
                counter.CounterType = type;

                counterDatas.Add(counter);
            }
        }