// Token: 0x0600343A RID: 13370 RVA: 0x000CA420 File Offset: 0x000C8620
        public static EtwSession GetEtwSession(int etwSessionId, bool bCreateIfNeeded = false)
        {
            if (etwSessionId < 0)
            {
                return(null);
            }
            EtwSession etwSession;

            foreach (WeakReference <EtwSession> weakReference in EtwSession.s_etwSessions)
            {
                if (weakReference.TryGetTarget(out etwSession) && etwSession.m_etwSessionId == etwSessionId)
                {
                    return(etwSession);
                }
            }
            if (!bCreateIfNeeded)
            {
                return(null);
            }
            if (EtwSession.s_etwSessions == null)
            {
                EtwSession.s_etwSessions = new List <WeakReference <EtwSession> >();
            }
            etwSession = new EtwSession(etwSessionId);
            EtwSession.s_etwSessions.Add(new WeakReference <EtwSession>(etwSession));
            if (EtwSession.s_etwSessions.Count > 16)
            {
                EtwSession.TrimGlobalList();
            }
            return(etwSession);
        }
Beispiel #2
0
        public static EtwSession GetEtwSession(int etwSessionId, bool bCreateIfNeeded = false)
        {
            if (etwSessionId < 0)
            {
                return((EtwSession)null);
            }
            foreach (WeakReference <EtwSession> sEtwSession in EtwSession.s_etwSessions)
            {
                EtwSession target;
                if (sEtwSession.TryGetTarget(out target) && target.m_etwSessionId == etwSessionId)
                {
                    return(target);
                }
            }
            if (!bCreateIfNeeded)
            {
                return((EtwSession)null);
            }
            if (EtwSession.s_etwSessions == null)
            {
                EtwSession.s_etwSessions = new List <WeakReference <EtwSession> >();
            }
            EtwSession target1 = new EtwSession(etwSessionId);

            EtwSession.s_etwSessions.Add(new WeakReference <EtwSession>(target1));
            if (EtwSession.s_etwSessions.Count > 16)
            {
                EtwSession.TrimGlobalList();
            }
            return(target1);
        }
 // Token: 0x0600343B RID: 13371 RVA: 0x000CA4CC File Offset: 0x000C86CC
 public static void RemoveEtwSession(EtwSession etwSession)
 {
     if (EtwSession.s_etwSessions == null || etwSession == null)
     {
         return;
     }
     EtwSession.s_etwSessions.RemoveAll(delegate(WeakReference <EtwSession> wrEtwSession)
     {
         EtwSession etwSession2;
         return(wrEtwSession.TryGetTarget(out etwSession2) && etwSession2.m_etwSessionId == etwSession.m_etwSessionId);
     });
     if (EtwSession.s_etwSessions.Count > 16)
     {
         EtwSession.TrimGlobalList();
     }
 }
Beispiel #4
0
 public static void RemoveEtwSession(EtwSession etwSession)
 {
     if (EtwSession.s_etwSessions == null || etwSession == null)
     {
         return;
     }
     EtwSession.s_etwSessions.RemoveAll((Predicate <WeakReference <EtwSession> >)(wrEtwSession =>
     {
         EtwSession target;
         if (wrEtwSession.TryGetTarget(out target))
         {
             return(target.m_etwSessionId == etwSession.m_etwSessionId);
         }
         return(false);
     }));
     if (EtwSession.s_etwSessions.Count <= 16)
     {
         return;
     }
     EtwSession.TrimGlobalList();
 }
Beispiel #5
0
        private void Initialize(Guid eventSourceGuid, string eventSourceName)
        {
            if (eventSourceGuid == Guid.Empty)
            {
                throw new ArgumentException(Environment.GetResourceString("EventSource_NeedGuid"));
            }

            if (eventSourceName == null)
            {
                throw new ArgumentException(Environment.GetResourceString("EventSource_NeedName"));
            }

            m_name = eventSourceName;
            m_guid = eventSourceGuid;
#if FEATURE_ACTIVITYSAMPLING
            m_curLiveSessions = new SessionMask(0);
            m_etwSessionIdMap = new EtwSession[SessionMask.MAX];
#endif // FEATURE_ACTIVITYSAMPLING

#if FEATURE_MANAGED_ETW
            m_provider = new OverideEventProvider(this);

            try
            {
                m_provider.Register(eventSourceGuid);
            }
            catch (ArgumentException)
            {
                // Failed to register.  Don't crash the app, just don't write events to ETW.
                m_provider = null;
            }
#endif
            // Add the eventSource to the global (weak) list.  This also sets m_id, which is the
            // index in the list. 
            EventListener.AddEventSource(this);

            // We are logically completely initialized at this point.  
            m_completelyInited = true;

            // report any possible errors
            ReportOutOfBandMessage(null, true);

#if FEATURE_ACTIVITYSAMPLING
            // we cue sending sampling info here based on whether we had to defer sending
            // the manifest
            // note: we do *not* send sampling info to any EventListeners because
            // the following common code pattern would cause an AV:
            // class MyEventSource: EventSource
            // {
            //    public static EventSource Log; 
            // }
            // class MyEventListener: EventListener
            // {
            //    protected override void OnEventWritten(...)
            //    { MyEventSource.Log.anything; } <-- AV, as the static Log was not set yet
            // }
            if (m_eventSourceEnabled && m_deferedSendManifest)
                ReportActivitySamplingInfo(null, m_curLiveSessions);
#endif // FEATURE_ACTIVITYSAMPLING

            // If we are active and we have not sent our manifest, do so now.  
            if (m_eventSourceEnabled && m_deferedSendManifest)
                SendManifest(m_rawManifest);
        }
Beispiel #6
0
        public static void RemoveEtwSession(EtwSession etwSession)
        {
            Contract.Assert(etwSession != null);
            if (s_etwSessions == null)
                return;

            s_etwSessions.RemoveAll((wrEtwSession) => 
                {
                    EtwSession session;
                    return wrEtwSession.TryGetTarget(out session) && 
                           (session.m_etwSessionId == etwSession.m_etwSessionId);
                });

            if (s_etwSessions.Count > s_thrSessionCount)
                TrimGlobalList();
        }
Beispiel #7
0
        public static EtwSession GetEtwSession(int etwSessionId, bool bCreateIfNeeded = false)
        {
            if (etwSessionId < 0)
                return null;

            EtwSession etwSession;
            foreach(var wrEtwSession in s_etwSessions)
            {
                if (wrEtwSession.TryGetTarget(out etwSession) && etwSession.m_etwSessionId == etwSessionId)
                    return etwSession;
            }

            if (!bCreateIfNeeded)
                return null;

            if (s_etwSessions == null)
                s_etwSessions = new List<WeakReference<EtwSession>>();

            etwSession = new EtwSession(etwSessionId);
            s_etwSessions.Add(new WeakReference<EtwSession>(etwSession));
            if (s_etwSessions.Count > s_thrSessionCount)
                TrimGlobalList();

            return etwSession;

        }