/// <summary>
        /// Verify  the profiler service XEvent session factory
        /// </summary>
        //[Fact]
        public void TestCreateXEventSession()
        {
            var             liveConnection  = LiveConnectionHelper.InitLiveConnectionInfo("master");
            ProfilerService profilerService = new ProfilerService();
            IXEventSession  xeSession       = profilerService.CreateXEventSession(liveConnection.ConnectionInfo);

            Assert.NotNull(xeSession);
            Assert.NotNull(xeSession.GetTargetXml());
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handle request to start a profiling session
        /// </summary>
        internal async Task HandleCreateXEventSessionRequest(CreateXEventSessionParams parameters, RequestContext <CreateXEventSessionResult> requestContext)
        {
            await Task.Run(async() =>
            {
                try
                {
                    ConnectionInfo connInfo;
                    ConnectionServiceInstance.TryFindConnection(
                        parameters.OwnerUri,
                        out connInfo);
                    if (connInfo == null)
                    {
                        throw new Exception(SR.ProfilerConnectionNotFound);
                    }
                    else if (parameters.SessionName == null)
                    {
                        throw new ArgumentNullException("SessionName");
                    }
                    else if (parameters.Template == null)
                    {
                        throw new ArgumentNullException("Template");
                    }
                    else
                    {
                        IXEventSession xeSession = null;

                        // first check whether the session with the given name already exists.
                        // if so skip the creation part. An exception will be thrown if no session with given name can be found,
                        // and it can be ignored.
                        try
                        {
                            xeSession = this.XEventSessionFactory.GetXEventSession(parameters.SessionName, connInfo);
                        }
                        catch { }

                        if (xeSession == null)
                        {
                            // create a new XEvent session and Profiler session
                            xeSession = this.XEventSessionFactory.CreateXEventSession(parameters.Template.CreateStatement, parameters.SessionName, connInfo);
                        }

                        // start monitoring the profiler session
                        monitor.StartMonitoringSession(parameters.OwnerUri, xeSession);

                        var result = new CreateXEventSessionResult();
                        await requestContext.SendResult(result);

                        SessionCreatedNotification(parameters.OwnerUri, parameters.SessionName, parameters.Template.Name);
                    }
                }
                catch (Exception e)
                {
                    await requestContext.SendError(new Exception(SR.CreateSessionFailed(e.Message)));
                }
            });
        }
Exemplo n.º 3
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);
        }