コード例 #1
0
 private bool RemoveSession(int sessionId, out ProfilerSession session)
 {
     lock (this.sessionsLock)
     {
         if (this.monitoredSessions.Remove(sessionId, out session))
         {
             //remove all viewers for this session
             List <string> viewerIds;
             if (sessionViewers.Remove(sessionId, out viewerIds))
             {
                 foreach (String viewerId in viewerIds)
                 {
                     this.allViewers.Remove(viewerId);
                 }
                 return(true);
             }
             else
             {
                 session = null;
                 return(false);
             }
         }
         else
         {
             session = null;
             return(false);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Handle request to start a profiling session
        /// </summary>
        internal async Task HandleStartProfilingRequest(StartProfilingParams parameters, RequestContext <StartProfilingResult> requestContext)
        {
            try
            {
                var            result = new StartProfilingResult();
                ConnectionInfo connInfo;
                ConnectionServiceInstance.TryFindConnection(
                    parameters.OwnerUri,
                    out connInfo);

                if (connInfo != null)
                {
                    ProfilerSession session = StartSession(parameters.OwnerUri, connInfo);
                    result.SessionId = session.SessionId;
                    result.Succeeded = true;
                }
                else
                {
                    result.Succeeded    = false;
                    result.ErrorMessage = SR.ProfilerConnectionNotFound;
                }

                await requestContext.SendResult(result);
            }
            catch (Exception e)
            {
                await requestContext.SendError(e);
            }
        }
コード例 #3
0
 /// <summary>
 /// Process a session for new XEvents if it meets the polling criteria
 /// </summary>
 private void ProcessSession(ProfilerSession session)
 {
     if (session.TryEnterPolling())
     {
         Task.Factory.StartNew(() =>
         {
             var events = PollSession(session);
             if (events.Count > 0)
             {
                 SendEventsToListeners(session.SessionId, events);
             }
         });
     }
 }
コード例 #4
0
        /// <summary>
        /// Start monitoring the provided session
        /// </summary>
        public bool StartMonitoringSession(string viewerId, IXEventSession session)
        {
            lock (this.sessionsLock)
            {
                // start the monitoring thread
                if (this.processorThread == null)
                {
                    this.processorThread = Task.Factory.StartNew(ProcessSessions);
                }

                // create new profiling session if needed
                if (!this.monitoredSessions.ContainsKey(session.Id))
                {
                    var profilerSession = new ProfilerSession();
                    profilerSession.XEventSession = session;

                    this.monitoredSessions.Add(session.Id, profilerSession);
                }

                // create a new viewer, or configure existing viewer
                Viewer viewer;
                if (!this.allViewers.TryGetValue(viewerId, out viewer))
                {
                    viewer = new Viewer(viewerId, true, session.Id);
                    allViewers.Add(viewerId, viewer);
                }
                else
                {
                    viewer.active      = true;
                    viewer.xeSessionId = session.Id;
                }

                // add viewer to XEvent session viewers
                List <string> viewers;
                if (this.sessionViewers.TryGetValue(session.Id, out viewers))
                {
                    viewers.Add(viewerId);
                }
                else
                {
                    viewers = new List <string> {
                        viewerId
                    };
                    sessionViewers.Add(session.Id, viewers);
                }
            }

            return(true);
        }
コード例 #5
0
        /// <summary>
        /// Starts a new profiler session for the provided connection
        /// </summary>
        internal ProfilerSession StartSession(string sessionId, ConnectionInfo connInfo)
        {
            // create a new XEvent session and Profiler session
            var xeSession       = this.XEventSessionFactory.CreateXEventSession(connInfo);
            var profilerSession = new ProfilerSession()
            {
                SessionId     = sessionId,
                XEventSession = xeSession
            };

            // start monitoring the profiler session
            monitor.StartMonitoringSession(profilerSession);

            return(profilerSession);
        }
コード例 #6
0
 /// <summary>
 /// Stop monitoring the session watched by viewerId
 /// </summary>
 public bool StopMonitoringSession(string viewerId, out ProfilerSession session)
 {
     lock (this.sessionsLock)
     {
         Viewer v;
         if (this.allViewers.TryGetValue(viewerId, out v))
         {
             return(RemoveSession(v.xeSessionId, out session));
         }
         else
         {
             session = null;
             return(false);
         }
     }
 }
コード例 #7
0
        /// <summary>
        /// Start monitoring the provided sessions
        /// </summary>
        public bool StartMonitoringSession(ProfilerSession session)
        {
            lock (this.sessionsLock)
            {
                // start the monitoring thread
                if (this.processorThread == null)
                {
                    this.processorThread = Task.Factory.StartNew(ProcessSessions);;
                }

                if (!this.monitoredSessions.ContainsKey(session.SessionId))
                {
                    this.monitoredSessions.Add(session.SessionId, session);
                }
            }

            return(true);
        }
コード例 #8
0
        private List <ProfilerEvent> PollSession(ProfilerSession session)
        {
            var events = new List <ProfilerEvent>();

            try
            {
                if (session == null || session.XEventSession == null)
                {
                    return(events);
                }

                var targetXml = session.XEventSession.GetTargetXml();

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(targetXml);

                var nodes = xmlDoc.DocumentElement.GetElementsByTagName("event");
                foreach (XmlNode node in nodes)
                {
                    var profilerEvent = ParseProfilerEvent(node);
                    if (profilerEvent != null)
                    {
                        events.Add(profilerEvent);
                    }
                }
            }
            catch (XEventException)
            {
                SendStoppedSessionInfoToListeners(session.XEventSession.Id);
                ProfilerSession tempSession;
                RemoveSession(session.XEventSession.Id, out tempSession);
            }
            catch (Exception ex)
            {
                Logger.Write(TraceEventType.Warning, "Failed to poll session. error: " + ex.Message);
            }
            finally
            {
                session.IsPolling = false;
            }

            session.FilterOldEvents(events);
            return(session.FilterProfilerEvents(events));
        }
コード例 #9
0
        private List <ProfilerEvent> PollSession(ProfilerSession session)
        {
            var events = new List <ProfilerEvent>();

            try
            {
                if (session == null || session.XEventSession == null)
                {
                    return(events);
                }

                var targetXml = session.XEventSession.GetTargetXml();

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.LoadXml(targetXml);

                var nodes = xmlDoc.DocumentElement.GetElementsByTagName("event");
                foreach (XmlNode node in nodes)
                {
                    var profilerEvent = ParseProfilerEvent(node);
                    if (profilerEvent != null)
                    {
                        events.Add(profilerEvent);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Write(LogLevel.Warning, "Failed to pool session. error: " + ex.Message);
            }
            finally
            {
                session.IsPolling = false;
            }

            return(session.FilterProfilerEvents(
                       session.FilterOldEvents(events)
                       ));
        }
コード例 #10
0
 /// <summary>
 /// Process a session for new XEvents if it meets the polling criteria
 /// </summary>
 private void ProcessSession(ProfilerSession session)
 {
     if (session.TryEnterPolling())
     {
         Task.Factory.StartNew(() =>
         {
             var events      = PollSession(session);
             bool eventsLost = session.EventsLost;
             if (events.Count > 0 || eventsLost)
             {
                 // notify all viewers for the polled session
                 List <string> viewerIds = this.sessionViewers[session.XEventSession.Id];
                 foreach (string viewerId in viewerIds)
                 {
                     if (allViewers[viewerId].active)
                     {
                         SendEventsToListeners(viewerId, events, eventsLost);
                     }
                 }
             }
         });
     }
 }