Example #1
0
        internal static void AddEventCounter(EventSource eventSource, EventCounter eventCounter)
        {
            int eventSourceIndex = EventListenerHelper.EventSourceIndex(eventSource);

            EventCounterGroup.EnsureEventSourceIndexAvailable(eventSourceIndex);
            EventCounterGroup eventCounterGroup = GetEventCounterGroup(eventSource);

            eventCounterGroup.Add(eventCounter);
        }
Example #2
0
        private static EventCounterGroup GetEventCounterGroup(EventSource eventSource)
        {
            int eventSourceIndex     = EventListenerHelper.EventSourceIndex(eventSource);
            EventCounterGroup result = EventCounterGroup.s_eventCounterGroups[eventSourceIndex];

            if (result == null)
            {
                result = new EventCounterGroup(eventSource, eventSourceIndex);
                EventCounterGroup.s_eventCounterGroups[eventSourceIndex] = result;
            }

            return(result);
        }
Example #3
0
 private static void EnsureEventSourceIndexAvailable(int eventSourceIndex)
 {
     if (EventCounterGroup.s_eventCounterGroups == null)
     {
         EventCounterGroup.s_eventCounterGroups = new EventCounterGroup[eventSourceIndex + 1];
     }
     else if (eventSourceIndex >= EventCounterGroup.s_eventCounterGroups.Length)
     {
         EventCounterGroup[] newEventCounterGroups = new EventCounterGroup[eventSourceIndex + 1];
         Array.Copy(EventCounterGroup.s_eventCounterGroups, 0, newEventCounterGroups, 0, EventCounterGroup.s_eventCounterGroups.Length);
         EventCounterGroup.s_eventCounterGroups = newEventCounterGroups;
     }
 }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventCounter"/> class.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="eventSource">The event source.</param>
        public EventCounter(string name, EventSource eventSource)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (eventSource == null)
            {
                throw new ArgumentNullException(nameof(eventSource));
            }

            InitializeBuffer();
            _name = name;
            EventCounterGroup.AddEventCounter(eventSource, this);
        }
Example #5
0
 internal static EventCounterGroup GetEventCounterGroup(EventSource eventSource)
 {
     lock (s_eventCounterGroupsLock)
     {
         int eventSourceIndex = EventListener.EventSourceIndex(eventSource);
         EnsureEventSourceIndexAvailable(eventSourceIndex);
         WeakReference <EventCounterGroup> weakRef = EventCounterGroup.s_eventCounterGroups[eventSourceIndex];
         EventCounterGroup ret = null;
         if (weakRef == null || !weakRef.TryGetTarget(out ret))
         {
             ret = new EventCounterGroup(eventSource);
             EventCounterGroup.s_eventCounterGroups[eventSourceIndex] = new WeakReference <EventCounterGroup>(ret);
         }
         return(ret);
     }
 }
Example #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EventCounter"/> class.
        /// EVentCounters live as long as the EventSource that they are attached to unless they are
        /// explicitly Disposed.
        /// </summary>
        /// <param name="name">The name.</param>
        /// <param name="eventSource">The event source.</param>
        public EventCounter(string name, EventSource eventSource)
        {
            if (name == null)
            {
                throw new ArgumentNullException(nameof(name));
            }

            if (eventSource == null)
            {
                throw new ArgumentNullException(nameof(eventSource));
            }

            InitializeBuffer();
            _name  = name;
            _group = EventCounterGroup.GetEventCounterGroup(eventSource);
            _group.Add(this);
            _min = float.PositiveInfinity;
            _max = float.NegativeInfinity;
        }