Esempio n. 1
0
        public static unsafe bool PassesActivityFilter(ActivityFilter filterList, Guid *childActivityID, bool triggeringEvent, EventSource source, int eventId)
        {
            bool flag = false;

            if (triggeringEvent)
            {
                for (ActivityFilter activityFilter = filterList; activityFilter != null; activityFilter = activityFilter.m_next)
                {
                    if (eventId == activityFilter.m_eventId && source.Guid == activityFilter.m_providerGuid)
                    {
                        int comparand;
                        int num1;
                        do
                        {
                            comparand = activityFilter.m_curSampleCount;
                            num1      = comparand > 1 ? comparand - 1 : activityFilter.m_samplingFreq;
                        }while (Interlocked.CompareExchange(ref activityFilter.m_curSampleCount, num1, comparand) != comparand);
                        if (comparand <= 1)
                        {
                            Guid threadActivityId = EventSource.InternalCurrentThreadActivityId;
                            Tuple <Guid, int> tuple;
                            if (!activityFilter.m_rootActiveActivities.TryGetValue(threadActivityId, out tuple))
                            {
                                flag = true;
                                activityFilter.m_activeActivities[threadActivityId]     = Environment.TickCount;
                                activityFilter.m_rootActiveActivities[threadActivityId] = Tuple.Create <Guid, int>(source.Guid, eventId);
                                break;
                            }
                            break;
                        }
                        Guid threadActivityId1 = EventSource.InternalCurrentThreadActivityId;
                        Tuple <Guid, int> tuple1;
                        if (activityFilter.m_rootActiveActivities.TryGetValue(threadActivityId1, out tuple1) && tuple1.Item1 == source.Guid && tuple1.Item2 == eventId)
                        {
                            int num2;
                            activityFilter.m_activeActivities.TryRemove(threadActivityId1, out num2);
                            break;
                        }
                        break;
                    }
                }
            }
            ConcurrentDictionary <Guid, int> activeActivities = ActivityFilter.GetActiveActivities(filterList);

            if (activeActivities != null)
            {
                if (!flag)
                {
                    flag = !activeActivities.IsEmpty && activeActivities.ContainsKey(EventSource.InternalCurrentThreadActivityId);
                }
                if (flag && (IntPtr)childActivityID != IntPtr.Zero && (int)source.m_eventData[eventId].Descriptor.Opcode == 9)
                {
                    ActivityFilter.FlowActivityIfNeeded(filterList, (Guid *)null, childActivityID);
                }
            }
            return(flag);
        }
Esempio n. 2
0
 private static bool EnableFilter(ref ActivityFilter filterList, EventSource source, int perEventSourceSessionId, int eventId, int samplingFreq)
 {
     filterList = new ActivityFilter(source, perEventSourceSessionId, eventId, samplingFreq, filterList);
     if (0 <= eventId && eventId < source.m_eventData.Length)
     {
         ++source.m_eventData[eventId].TriggersActivityTracking;
     }
     return(true);
 }
Esempio n. 3
0
        public static void UpdateFilter(ref ActivityFilter filterList, EventSource source, int perEventSourceSessionId, string startEvents)
        {
            ActivityFilter.DisableFilter(ref filterList, source);
            if (string.IsNullOrEmpty(startEvents))
            {
                return;
            }
            string str1 = startEvents;

            char[] chArray = new char[1] {
                ' '
            };
            foreach (string str2 in str1.Split(chArray))
            {
                int result1 = 1;
                int result2 = -1;
                int length  = str2.IndexOf(':');
                if (length < 0)
                {
                    source.ReportOutOfBandMessage("ERROR: Invalid ActivitySamplingStartEvent specification: " + str2, false);
                }
                else
                {
                    string s = str2.Substring(length + 1);
                    if (!int.TryParse(s, out result1))
                    {
                        source.ReportOutOfBandMessage("ERROR: Invalid sampling frequency specification: " + s, false);
                    }
                    else
                    {
                        string str3 = str2.Substring(0, length);
                        if (!int.TryParse(str3, out result2))
                        {
                            result2 = -1;
                            for (int index = 0; index < source.m_eventData.Length; ++index)
                            {
                                EventSource.EventMetadata[] eventMetadataArray = source.m_eventData;
                                if (eventMetadataArray[index].Name != null && eventMetadataArray[index].Name.Length == str3.Length && string.Compare(eventMetadataArray[index].Name, str3, StringComparison.OrdinalIgnoreCase) == 0)
                                {
                                    result2 = eventMetadataArray[index].Descriptor.EventId;
                                    break;
                                }
                            }
                        }
                        if (result2 < 0 || result2 >= source.m_eventData.Length)
                        {
                            source.ReportOutOfBandMessage("ERROR: Invalid eventId specification: " + str3, false);
                        }
                        else
                        {
                            ActivityFilter.EnableFilter(ref filterList, source, perEventSourceSessionId, result2, result1);
                        }
                    }
                }
            }
        }
Esempio n. 4
0
 // Token: 0x06003431 RID: 13361 RVA: 0x000CA160 File Offset: 0x000C8360
 public static void UpdateKwdTriggers(ActivityFilter activityFilter, Guid sourceGuid, EventSource source, EventKeywords sessKeywords)
 {
     for (ActivityFilter activityFilter2 = activityFilter; activityFilter2 != null; activityFilter2 = activityFilter2.m_next)
     {
         if (sourceGuid == activityFilter2.m_providerGuid && (source.m_eventData[activityFilter2.m_eventId].TriggersActivityTracking > 0 || source.m_eventData[activityFilter2.m_eventId].Descriptor.Opcode == 9))
         {
             source.m_keywordTriggers |= (source.m_eventData[activityFilter2.m_eventId].Descriptor.Keywords & (long)sessKeywords);
         }
     }
 }
Esempio n. 5
0
 // Token: 0x06003436 RID: 13366 RVA: 0x000CA324 File Offset: 0x000C8524
 private static Action <Guid> GetActivityDyingDelegate(ActivityFilter filterList)
 {
     return(delegate(Guid oldActivity)
     {
         int num;
         filterList.m_activeActivities.TryRemove(oldActivity, out num);
         Tuple <Guid, int> tuple;
         filterList.m_rootActiveActivities.TryRemove(oldActivity, out tuple);
     });
 }
Esempio n. 6
0
 // Token: 0x0600342D RID: 13357 RVA: 0x000C9F3C File Offset: 0x000C813C
 public static ActivityFilter GetFilter(ActivityFilter filterList, EventSource source)
 {
     for (ActivityFilter activityFilter = filterList; activityFilter != null; activityFilter = activityFilter.m_next)
     {
         if (activityFilter.m_providerGuid == source.Guid && activityFilter.m_samplingFreq != -1)
         {
             return(activityFilter);
         }
     }
     return(null);
 }
Esempio n. 7
0
 // Token: 0x06003439 RID: 13369 RVA: 0x000CA3F4 File Offset: 0x000C85F4
 private static ConcurrentDictionary <Guid, int> GetActiveActivities(ActivityFilter filterList)
 {
     for (ActivityFilter activityFilter = filterList; activityFilter != null; activityFilter = activityFilter.m_next)
     {
         if (activityFilter.m_activeActivities != null)
         {
             return(activityFilter.m_activeActivities);
         }
     }
     return(null);
 }
Esempio n. 8
0
 // Token: 0x0600342C RID: 13356 RVA: 0x000C9DD0 File Offset: 0x000C7FD0
 public static void UpdateFilter(ref ActivityFilter filterList, EventSource source, int perEventSourceSessionId, string startEvents)
 {
     ActivityFilter.DisableFilter(ref filterList, source);
     if (!string.IsNullOrEmpty(startEvents))
     {
         foreach (string text in startEvents.Split(new char[]
         {
             ' '
         }))
         {
             int samplingFreq = 1;
             int num          = -1;
             int num2         = text.IndexOf(':');
             if (num2 < 0)
             {
                 source.ReportOutOfBandMessage("ERROR: Invalid ActivitySamplingStartEvent specification: " + text, false);
             }
             else
             {
                 string text2 = text.Substring(num2 + 1);
                 if (!int.TryParse(text2, out samplingFreq))
                 {
                     source.ReportOutOfBandMessage("ERROR: Invalid sampling frequency specification: " + text2, false);
                 }
                 else
                 {
                     text = text.Substring(0, num2);
                     if (!int.TryParse(text, out num))
                     {
                         num = -1;
                         for (int j = 0; j < source.m_eventData.Length; j++)
                         {
                             EventSource.EventMetadata[] eventData = source.m_eventData;
                             if (eventData[j].Name != null && eventData[j].Name.Length == text.Length && string.Compare(eventData[j].Name, text, StringComparison.OrdinalIgnoreCase) == 0)
                             {
                                 num = eventData[j].Descriptor.EventId;
                                 break;
                             }
                         }
                     }
                     if (num < 0 || num >= source.m_eventData.Length)
                     {
                         source.ReportOutOfBandMessage("ERROR: Invalid eventId specification: " + text, false);
                     }
                     else
                     {
                         ActivityFilter.EnableFilter(ref filterList, source, perEventSourceSessionId, num, samplingFreq);
                     }
                 }
             }
         }
     }
 }
Esempio n. 9
0
        public unsafe static void FlowActivityIfNeeded(ActivityFilter filterList, Guid *currentActivityId, Guid *childActivityID)
        {
            ConcurrentDictionary <Guid, int> activeActivities = ActivityFilter.GetActiveActivities(filterList);

            if (currentActivityId != null && !activeActivities.ContainsKey(*currentActivityId))
            {
                return;
            }
            if (activeActivities.Count > 100000)
            {
                ActivityFilter.TrimActiveActivityStore(activeActivities);
                activeActivities[EventSource.InternalCurrentThreadActivityId] = Environment.TickCount;
            }
            activeActivities[*childActivityID] = Environment.TickCount;
        }
Esempio n. 10
0
 // Token: 0x06003435 RID: 13365 RVA: 0x000CA2D4 File Offset: 0x000C84D4
 private static void EnsureActivityCleanupDelegate(ActivityFilter filterList)
 {
     if (filterList == null)
     {
         return;
     }
     for (ActivityFilter activityFilter = filterList; activityFilter != null; activityFilter = activityFilter.m_next)
     {
         if (activityFilter.m_myActivityDelegate != null)
         {
             return;
         }
     }
     filterList.m_myActivityDelegate = ActivityFilter.GetActivityDyingDelegate(filterList);
     EventSource.s_activityDying     = (Action <Guid>)Delegate.Combine(EventSource.s_activityDying, filterList.m_myActivityDelegate);
 }
Esempio n. 11
0
        // Token: 0x0600342B RID: 13355 RVA: 0x000C9CD0 File Offset: 0x000C7ED0
        public static void DisableFilter(ref ActivityFilter filterList, EventSource source)
        {
            if (filterList == null)
            {
                return;
            }
            ActivityFilter activityFilter = filterList;
            ActivityFilter next           = activityFilter.m_next;

            while (next != null)
            {
                if (next.m_providerGuid == source.Guid)
                {
                    if (next.m_eventId >= 0 && next.m_eventId < source.m_eventData.Length)
                    {
                        EventSource.EventMetadata[] eventData = source.m_eventData;
                        int eventId = next.m_eventId;
                        eventData[eventId].TriggersActivityTracking = eventData[eventId].TriggersActivityTracking - 1;
                    }
                    activityFilter.m_next = next.m_next;
                    next.Dispose();
                    next = activityFilter.m_next;
                }
                else
                {
                    activityFilter = next;
                    next           = activityFilter.m_next;
                }
            }
            if (filterList.m_providerGuid == source.Guid)
            {
                if (filterList.m_eventId >= 0 && filterList.m_eventId < source.m_eventData.Length)
                {
                    EventSource.EventMetadata[] eventData2 = source.m_eventData;
                    int eventId2 = filterList.m_eventId;
                    eventData2[eventId2].TriggersActivityTracking = eventData2[eventId2].TriggersActivityTracking - 1;
                }
                ActivityFilter activityFilter2 = filterList;
                filterList = activityFilter2.m_next;
                activityFilter2.Dispose();
            }
            if (filterList != null)
            {
                ActivityFilter.EnsureActivityCleanupDelegate(filterList);
            }
        }
Esempio n. 12
0
        public static void DisableFilter(ref ActivityFilter filterList, EventSource source)
        {
            if (filterList == null)
            {
                return;
            }
            ActivityFilter activityFilter1 = filterList;
            ActivityFilter activityFilter2 = activityFilter1.m_next;

            while (activityFilter2 != null)
            {
                if (activityFilter2.m_providerGuid == source.Guid)
                {
                    if (activityFilter2.m_eventId >= 0 && activityFilter2.m_eventId < source.m_eventData.Length)
                    {
                        --source.m_eventData[activityFilter2.m_eventId].TriggersActivityTracking;
                    }
                    activityFilter1.m_next = activityFilter2.m_next;
                    activityFilter2.Dispose();
                    activityFilter2 = activityFilter1.m_next;
                }
                else
                {
                    activityFilter1 = activityFilter2;
                    activityFilter2 = activityFilter1.m_next;
                }
            }
            if (filterList.m_providerGuid == source.Guid)
            {
                if (filterList.m_eventId >= 0 && filterList.m_eventId < source.m_eventData.Length)
                {
                    --source.m_eventData[filterList.m_eventId].TriggersActivityTracking;
                }
                ActivityFilter activityFilter3 = filterList;
                filterList = activityFilter3.m_next;
                activityFilter3.Dispose();
            }
            if (filterList == null)
            {
                return;
            }
            ActivityFilter.EnsureActivityCleanupDelegate(filterList);
        }
Esempio n. 13
0
        // Token: 0x06003434 RID: 13364 RVA: 0x000CA234 File Offset: 0x000C8434
        private ActivityFilter(EventSource source, int perEventSourceSessionId, int eventId, int samplingFreq, ActivityFilter existingFilter = null)
        {
            this.m_providerGuid            = source.Guid;
            this.m_perEventSourceSessionId = perEventSourceSessionId;
            this.m_eventId      = eventId;
            this.m_samplingFreq = samplingFreq;
            this.m_next         = existingFilter;
            ConcurrentDictionary <Guid, int> activeActivities;

            if (existingFilter == null || (activeActivities = ActivityFilter.GetActiveActivities(existingFilter)) == null)
            {
                this.m_activeActivities     = new ConcurrentDictionary <Guid, int>();
                this.m_rootActiveActivities = new ConcurrentDictionary <Guid, Tuple <Guid, int> >();
                this.m_myActivityDelegate   = ActivityFilter.GetActivityDyingDelegate(this);
                EventSource.s_activityDying = (Action <Guid>)Delegate.Combine(EventSource.s_activityDying, this.m_myActivityDelegate);
                return;
            }
            this.m_activeActivities     = activeActivities;
            this.m_rootActiveActivities = existingFilter.m_rootActiveActivities;
        }
Esempio n. 14
0
        public static bool IsCurrentActivityActive(ActivityFilter filterList)
        {
            var activeActivities = GetActiveActivities(filterList);
            if (activeActivities != null && 
                activeActivities.ContainsKey(EventSource.InternalCurrentThreadActivityId))
                return true;

            return false;
        }
Esempio n. 15
0
        public static bool IsCurrentActivityActive(ActivityFilter filterList)
        {
            ConcurrentDictionary <Guid, int> activeActivities = ActivityFilter.GetActiveActivities(filterList);

            return(activeActivities != null && activeActivities.ContainsKey(EventSource.InternalCurrentThreadActivityId));
        }
Esempio n. 16
0
        public unsafe static bool PassesActivityFilter(ActivityFilter filterList, Guid *childActivityID, bool triggeringEvent, EventSource source, int eventId)
        {
            bool flag = false;

            if (triggeringEvent)
            {
                ActivityFilter activityFilter = filterList;
                while (activityFilter != null)
                {
                    if (eventId == activityFilter.m_eventId && source.Guid == activityFilter.m_providerGuid)
                    {
                        int curSampleCount;
                        int value;
                        do
                        {
                            curSampleCount = activityFilter.m_curSampleCount;
                            if (curSampleCount <= 1)
                            {
                                value = activityFilter.m_samplingFreq;
                            }
                            else
                            {
                                value = curSampleCount - 1;
                            }
                        }while (Interlocked.CompareExchange(ref activityFilter.m_curSampleCount, value, curSampleCount) != curSampleCount);
                        if (curSampleCount <= 1)
                        {
                            Guid internalCurrentThreadActivityId = EventSource.InternalCurrentThreadActivityId;
                            Tuple <Guid, int> tuple;
                            if (!activityFilter.m_rootActiveActivities.TryGetValue(internalCurrentThreadActivityId, out tuple))
                            {
                                flag = true;
                                activityFilter.m_activeActivities[internalCurrentThreadActivityId]     = Environment.TickCount;
                                activityFilter.m_rootActiveActivities[internalCurrentThreadActivityId] = Tuple.Create <Guid, int>(source.Guid, eventId);
                                break;
                            }
                            break;
                        }
                        else
                        {
                            Guid internalCurrentThreadActivityId2 = EventSource.InternalCurrentThreadActivityId;
                            Tuple <Guid, int> tuple2;
                            if (activityFilter.m_rootActiveActivities.TryGetValue(internalCurrentThreadActivityId2, out tuple2) && tuple2.Item1 == source.Guid && tuple2.Item2 == eventId)
                            {
                                int num;
                                activityFilter.m_activeActivities.TryRemove(internalCurrentThreadActivityId2, out num);
                                break;
                            }
                            break;
                        }
                    }
                    else
                    {
                        activityFilter = activityFilter.m_next;
                    }
                }
            }
            ConcurrentDictionary <Guid, int> activeActivities = ActivityFilter.GetActiveActivities(filterList);

            if (activeActivities != null)
            {
                if (!flag)
                {
                    flag = (!activeActivities.IsEmpty && activeActivities.ContainsKey(EventSource.InternalCurrentThreadActivityId));
                }
                if (flag && childActivityID != null && source.m_eventData[eventId].Descriptor.Opcode == 9)
                {
                    ActivityFilter.FlowActivityIfNeeded(filterList, null, childActivityID);
                }
            }
            return(flag);
        }
Esempio n. 17
0
 /// <summary>
 /// Builds the delegate to be called when an activity is dying. This is responsible
 /// for performing whatever cleanup is needed for the ActivityFilter list passed in.
 /// This gets "added" to EventSource.s_activityDying and ends up being called from
 /// EventSource.SetCurrentThreadActivityId and ActivityFilter.PassesActivityFilter.
 /// </summary>
 /// <returns>The delegate to be called when an activity is dying</returns>
 private static Action<Guid> GetActivityDyingDelegate(ActivityFilter filterList)
 {
     return (Guid oldActivity) =>
     {
         int dummy; 
         filterList.m_activeActivities.TryRemove(oldActivity, out dummy);
         Tuple<Guid, int> dummyTuple;
         filterList.m_rootActiveActivities.TryRemove(oldActivity, out dummyTuple);
     };
 }
Esempio n. 18
0
 /// <summary>
 /// Returns the first ActivityFilter from 'filterList' corresponding to 'source'.
 /// </summary>
 public static ActivityFilter GetFilter(ActivityFilter filterList, EventSource source)
 {
     for (var af = filterList; af != null; af = af.m_next)
     {
         if (af.m_providerGuid == source.Guid && af.m_samplingFreq != -1)
             return af;
     }
     return null;
 }
Esempio n. 19
0
 /// <summary>
 /// </summary>
 public static void UpdateKwdTriggers(ActivityFilter activityFilter, Guid sourceGuid, EventSource source, EventKeywords sessKeywords)
 {
     for (var af = activityFilter; af != null; af = af.m_next)
     {
         if ((sourceGuid == af.m_providerGuid) && 
             (source.m_eventData[af.m_eventId].TriggersActivityTracking > 0 ||
             ((EventOpcode)source.m_eventData[af.m_eventId].Descriptor.Opcode == EventOpcode.Send)))
         {
             // we could be more precise here, if we tracked 'anykeywords' per session
             source.m_keywordTriggers |= (source.m_eventData[af.m_eventId].Descriptor.Keywords & (long)sessKeywords);
         }
     }
 }
Esempio n. 20
0
        /// <summary>
        /// Currently this has "override" semantics. We first disable all filters
        /// associated with 'source', and next we add new filters for each entry in the 
        /// string 'startEvents'. participateInSampling specifies whether non-startEvents 
        /// always trigger or only trigger when current activity is 'active'.
        /// </summary>
        public static void UpdateFilter(
                                    ref ActivityFilter filterList, 
                                    EventSource source, 
                                    int perEventSourceSessionId,
                                    string startEvents)
        {
            Contract.Assert(Monitor.IsEntered(EventListener.EventListenersLock));

            // first remove all filters associated with 'source'
            DisableFilter(ref filterList, source);

            if (!string.IsNullOrEmpty(startEvents))
            {
                // ActivitySamplingStartEvents is a space-separated list of Event:Frequency pairs.
                // The Event may be specified by name or by ID. Errors in parsing such a pair 
                // result in the error being reported to the listeners, and the pair being ignored.
                // E.g. "CustomActivityStart:1000 12:10" specifies that for event CustomActivityStart
                // we should initiate activity tracing once every 1000 events, *and* for event ID 12
                // we should initiate activity tracing once every 10 events.
                string[] activityFilterStrings = startEvents.Split(' ');

                for (int i = 0; i < activityFilterStrings.Length; ++i)
                {
                    string activityFilterString = activityFilterStrings[i];
                    int sampleFreq = 1;
                    int eventId = -1;
                    int colonIdx = activityFilterString.IndexOf(':');
                    if (colonIdx < 0)
                    {
                        source.ReportOutOfBandMessage("ERROR: Invalid ActivitySamplingStartEvent specification: " + 
                            activityFilterString, false);
                        // ignore failure...
                        continue;
                    }
                    string sFreq = activityFilterString.Substring(colonIdx + 1);
                    if (!int.TryParse(sFreq, out sampleFreq))
                    {
                        source.ReportOutOfBandMessage("ERROR: Invalid sampling frequency specification: " + sFreq, false);
                        continue;
                    }
                    activityFilterString = activityFilterString.Substring(0, colonIdx);
                    if (!int.TryParse(activityFilterString, out eventId))
                    {
                        // reset eventId
                        eventId = -1;
                        // see if it's an event name
                        for (int j = 0; j < source.m_eventData.Length; j++)
                        {
                            EventSource.EventMetadata[] ed = source.m_eventData;
                            if (ed[j].Name != null && ed[j].Name.Length == activityFilterString.Length &&
                                string.Compare(ed[j].Name, activityFilterString, StringComparison.OrdinalIgnoreCase) == 0)
                            {
                                eventId = ed[j].Descriptor.EventId;
                                break;
                            }
                        }
                    }
                    if (eventId < 0 || eventId >= source.m_eventData.Length)
                    {
                        source.ReportOutOfBandMessage("ERROR: Invalid eventId specification: " + activityFilterString, false);
                        continue;
                    }
                    EnableFilter(ref filterList, source, perEventSourceSessionId, eventId, sampleFreq);
                }
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Creates a new ActivityFilter that is triggered by 'eventId' from 'source' ever
        /// 'samplingFreq' times the event fires. You can have several of these forming a 
        /// linked list.
        /// </summary>
        private ActivityFilter(EventSource source, int perEventSourceSessionId, int eventId, int samplingFreq, ActivityFilter existingFilter = null)
        {
            m_providerGuid = source.Guid;
            m_perEventSourceSessionId = perEventSourceSessionId;
            m_eventId = eventId;
            m_samplingFreq = samplingFreq;
            m_next = existingFilter;

            Contract.Assert(existingFilter == null ||
                            (existingFilter.m_activeActivities == null) == (existingFilter.m_rootActiveActivities == null));

            // if this is the first filter we add for this session, we need to create a new 
            // table of activities. m_activeActivities is common across EventSources in the same
            // session
            ConcurrentDictionary<Guid, int> activeActivities = null;
            if (existingFilter == null || 
                (activeActivities = GetActiveActivities(existingFilter)) == null)
            {
                m_activeActivities = new ConcurrentDictionary<Guid, int>();
                m_rootActiveActivities = new ConcurrentDictionary<Guid, Tuple<Guid, int>>();

                // Add a delegate to the 'SetCurrentThreadToActivity callback so that I remove 'dead' activities
                m_myActivityDelegate = GetActivityDyingDelegate(this);
                EventSource.s_activityDying = (Action<Guid>)Delegate.Combine(EventSource.s_activityDying, m_myActivityDelegate);
            }
            else
            {
                m_activeActivities = activeActivities;
                m_rootActiveActivities = existingFilter.m_rootActiveActivities;
            }

        }
Esempio n. 22
0
 private static ConcurrentDictionary<Guid, int> GetActiveActivities(
                             ActivityFilter filterList)
 {
     for (ActivityFilter af = filterList; af != null; af = af.m_next)
     {
         if (af.m_activeActivities != null)
             return af.m_activeActivities;
     }
     return null;
 }
Esempio n. 23
0
        /// <summary>
        /// Enables activity filtering for the listener associated with 'filterList', triggering on
        /// the event 'eventID' from 'source' with a sampling frequency of 'samplingFreq'
        /// 
        /// if 'eventID' is out of range (e.g. negative), it means we are not triggering (but we are 
        /// activitySampling if something else triggered).  
        /// </summary>
        /// <returns>true if activity sampling is enabled the samplingFreq is non-zero </returns>
        private static bool EnableFilter(ref ActivityFilter filterList, EventSource source, int perEventSourceSessionId, int eventId, int samplingFreq)
        {
            Contract.Assert(Monitor.IsEntered(EventListener.EventListenersLock));
            Contract.Assert(samplingFreq > 0);
            Contract.Assert(eventId >= 0);

            filterList = new ActivityFilter(source, perEventSourceSessionId, eventId, samplingFreq, filterList);

            // Mark the 'quick Check' that indicates this is a trigger event.  
            // If eventId is out of range then this mark is not done which has the effect of ignoring 
            // the trigger.
            if (0 <= eventId && eventId < source.m_eventData.Length)
                ++source.m_eventData[eventId].TriggersActivityTracking;

            return true;
        }
Esempio n. 24
0
        unsafe public static bool PassesActivityFilter(
                                    ActivityFilter filterList, 
                                    Guid* childActivityID, 
                                    bool triggeringEvent, 
                                    EventSource source, 
                                    int eventId)
        {
            Contract.Assert(filterList != null && filterList.m_activeActivities != null);
            bool shouldBeLogged = false;
            if (triggeringEvent)
            {
                for (ActivityFilter af = filterList; af != null; af = af.m_next)
                {
                    if (eventId == af.m_eventId && source.Guid == af.m_providerGuid)
                    {
                        // Update the sampling count with wrap-around
                        int curSampleCount, newSampleCount;
                        do
                        {
                            curSampleCount = af.m_curSampleCount;
                            if (curSampleCount <= 1)
                                newSampleCount = af.m_samplingFreq;        // Wrap around, counting down to 1
                            else
                                newSampleCount = curSampleCount - 1;
                        }
                        while (Interlocked.CompareExchange(ref af.m_curSampleCount, newSampleCount, curSampleCount) != curSampleCount);
                        // If we hit zero, then start tracking the activity.  
                        if (curSampleCount <= 1)
                        {
                            Guid currentActivityId = EventSource.InternalCurrentThreadActivityId;
                            Tuple<Guid, int> startId;
                            // only add current activity if it's not already a root activity
                            if (!af.m_rootActiveActivities.TryGetValue(currentActivityId, out startId))
                            {
                                // EventSource.OutputDebugString(string.Format("  PassesAF - Triggering(session {0}, evt {1})", af.m_perEventSourceSessionId, eventId));
                                shouldBeLogged = true;
                                af.m_activeActivities[currentActivityId] = Environment.TickCount;
                                af.m_rootActiveActivities[currentActivityId] = Tuple.Create(source.Guid, eventId);
                            }
                        }
                        else
                        {
                            // a start event following a triggering start event
                            Guid currentActivityId = EventSource.InternalCurrentThreadActivityId;
                            Tuple<Guid, int> startId;
                            // only remove current activity if we added it
                            if (af.m_rootActiveActivities.TryGetValue(currentActivityId, out startId) &&
                                startId.Item1 == source.Guid && startId.Item2 == eventId)
                            {
                                // EventSource.OutputDebugString(string.Format("Activity dying: {0} -> StartEvent({1})", currentActivityId, eventId));
                                // remove activity only from current logging scope (af)
                                int dummy;
                                af.m_activeActivities.TryRemove(currentActivityId, out dummy);
                            }                            
                        }
                        break;
                    }
                }
            }

            var activeActivities = GetActiveActivities(filterList);
            if (activeActivities != null)
            {
                // if we hadn't already determined this should be logged, test further
                if (!shouldBeLogged)
                {
                    shouldBeLogged = !activeActivities.IsEmpty && 
                                     activeActivities.ContainsKey(EventSource.InternalCurrentThreadActivityId);
                }
                if (shouldBeLogged && childActivityID != null && 
                    ((EventOpcode)source.m_eventData[eventId].Descriptor.Opcode == EventOpcode.Send))
                {
                    FlowActivityIfNeeded(filterList, null, childActivityID);
                    // EventSource.OutputDebugString(string.Format("  PassesAF - activity {0}", *childActivityID));
                }
            }
            // EventSource.OutputDebugString(string.Format("  PassesAF - shouldBeLogged(evt {0}) = {1:x}", eventId, shouldBeLogged));
            return shouldBeLogged;
        }
Esempio n. 25
0
        unsafe public static void FlowActivityIfNeeded(ActivityFilter filterList, Guid *currentActivityId, Guid *childActivityID)
        {
            Contract.Assert(childActivityID != null);

            var activeActivities = GetActiveActivities(filterList);
            Contract.Assert(activeActivities != null);

            // take currentActivityId == null to mean we *know* the current activity is "active"
            if (currentActivityId != null && !activeActivities.ContainsKey(*currentActivityId))
                return;

            if (activeActivities.Count > MaxActivityTrackCount)
            {
                TrimActiveActivityStore(activeActivities);
                // make sure current activity is still in the set:
                activeActivities[EventSource.InternalCurrentThreadActivityId] = Environment.TickCount;
            }
            // add child activity to list of actives
            activeActivities[*childActivityID] = Environment.TickCount;
            
        }
Esempio n. 26
0
        /// <summary>
        /// Disable all activity filtering for the listener associated with 'filterList', 
        /// (in the session associated with it) that is triggered by any event in 'source'.
        /// </summary>
        public static void DisableFilter(ref ActivityFilter filterList, EventSource source)
        {
            Contract.Assert(Monitor.IsEntered(EventListener.EventListenersLock));

            if (filterList == null)
                return;

            ActivityFilter cur;
            // Remove it from anywhere in the list (except the first element, which has to 
            // be treated specially)
            ActivityFilter prev = filterList;
            cur = prev.m_next;
            while (cur != null)
            {
                if (cur.m_providerGuid == source.Guid)
                {
                    // update TriggersActivityTracking bit
                    if (cur.m_eventId >= 0 && cur.m_eventId < source.m_eventData.Length)
                        --source.m_eventData[cur.m_eventId].TriggersActivityTracking;

                    // Remove it from the linked list.
                    prev.m_next = cur.m_next;
                    // dispose of the removed node
                    cur.Dispose();
                    // update cursor
                    cur = prev.m_next;
                }
                else
                {
                    // update cursors
                    prev = cur;
                    cur = prev.m_next;
                }
            }

            // Sadly we have to treat the first element specially in linked list removal in C#
            if (filterList.m_providerGuid == source.Guid)
            {
                // update TriggersActivityTracking bit
                if (filterList.m_eventId >= 0 && filterList.m_eventId < source.m_eventData.Length)
                    --source.m_eventData[filterList.m_eventId].TriggersActivityTracking;

                // We are the first element in the list.   
                var first = filterList;
                filterList = first.m_next;
                // dispose of the removed node
                first.Dispose();
            }
            // the above might have removed the one ActivityFilter in the session that contains the 
            // cleanup delegate; re-create the delegate if needed
            if (filterList != null)
            {
                EnsureActivityCleanupDelegate(filterList);
            }
        }
Esempio n. 27
0
        /// <summary>
        /// Ensure there's at least one ActivityFilter in the 'filterList' that contains an
        /// activity-removing delegate for the listener/session associated with 'filterList'.
        /// </summary>
        private static void EnsureActivityCleanupDelegate(ActivityFilter filterList)
        {
            if (filterList == null)
                return;

            for (ActivityFilter af = filterList; af != null; af = af.m_next)
            {
                if (af.m_myActivityDelegate != null)
                    return;
            }

            // we didn't find a delegate
            filterList.m_myActivityDelegate = GetActivityDyingDelegate(filterList);
            EventSource.s_activityDying = (Action<Guid>)Delegate.Combine(EventSource.s_activityDying, filterList.m_myActivityDelegate);
        }