/// <summary>
        /// Verifies that an event stream does provide events.
        /// </summary>
        private Task VerifyEventStreamProvidesEventsAsync(IpcEndpointInfo info, EventPipeSession session, int sessionNumber)
        {
            Assert.NotNull(session);
            Assert.NotNull(session.EventStream);

            return(Task.Run(async() =>
            {
                _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session #{sessionNumber} - Creating event source.");

                // This blocks for a while due to this bug: https://github.com/microsoft/perfview/issues/1172
                using var eventSource = new EventPipeEventSource(session.EventStream);

                _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session #{sessionNumber} - Setup event handlers.");

                // Create task completion source that is completed when any events are provided; cancel it if cancellation is requested
                var receivedEventsSource = new TaskCompletionSource <object>(TaskCreationOptions.RunContinuationsAsynchronously);

                using var cancellation = new CancellationTokenSource(TimeSpan.FromMinutes(1));
                using var _ = cancellation.Token.Register(() =>
                {
                    if (receivedEventsSource.TrySetCanceled())
                    {
                        _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session #{sessionNumber} - Cancelled event processing.");
                    }
                });

                // Create continuation task that stops the session (which immediately stops event processing).
                Task stoppedProcessingTask = receivedEventsSource.Task
                                             .ContinueWith(_ =>
                {
                    _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session #{sessionNumber} - Stopping session.");
                    session.Stop();
                });

                // Signal task source when an event is received.
                Action <TraceEvent> allEventsHandler = _ =>
                {
                    if (receivedEventsSource.TrySetResult(null))
                    {
                        _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session #{sessionNumber} - Received an event and set result on completion source.");
                    }
                };

                _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session #{sessionNumber} - Start processing events.");
                eventSource.Dynamic.All += allEventsHandler;
                eventSource.Process();
                eventSource.Dynamic.All -= allEventsHandler;
                _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session #{sessionNumber} - Stopped processing events.");

                // Wait on the task source to verify if it ran to completion or was cancelled.
                await receivedEventsSource.Task;

                _outputHelper.WriteLine($"{info.RuntimeInstanceCookie}: Session #{sessionNumber} - Waiting for session to stop.");
                await stoppedProcessingTask;
            }));
        }
Esempio n. 2
0
        private static EventPipeSession CreateSessionFromResponse(IpcEndpoint endpoint, ref IpcResponse?response, string operationName)
        {
            try
            {
                DiagnosticsClient.ValidateResponseMessage(response.Value.Message, operationName);

                long sessionId = BitConverter.ToInt64(response.Value.Message.Payload, 0);

                var session = new EventPipeSession(endpoint, response.Value, sessionId);
                response = null;
                return(session);
            }
            finally
            {
                response?.Dispose();
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Start tracing the application and return an EventPipeSession object
 /// </summary>
 /// <param name="providers">An IEnumerable containing the list of Providers to turn on.</param>
 /// <param name="requestRundown">If true, request rundown events from the runtime</param>
 /// <param name="circularBufferMB">The size of the runtime's buffer for collecting events in MB</param>
 /// <param name="token">The token to monitor for cancellation requests.</param>
 /// <returns>
 /// An EventPipeSession object representing the EventPipe session that just started.
 /// </returns>
 internal Task <EventPipeSession> StartEventPipeSessionAsync(IEnumerable <EventPipeProvider> providers, bool requestRundown, int circularBufferMB, CancellationToken token)
 {
     return(EventPipeSession.StartAsync(_endpoint, providers, requestRundown, circularBufferMB, token));
 }
Esempio n. 4
0
 /// <summary>
 /// Start tracing the application and return an EventPipeSession object
 /// </summary>
 /// <param name="provider">An EventPipeProvider to turn on.</param>
 /// <param name="requestRundown">If true, request rundown events from the runtime</param>
 /// <param name="circularBufferMB">The size of the runtime's buffer for collecting events in MB</param>
 /// <returns>
 /// An EventPipeSession object representing the EventPipe session that just started.
 /// </returns>
 public EventPipeSession StartEventPipeSession(EventPipeProvider provider, bool requestRundown = true, int circularBufferMB = 256)
 {
     return(EventPipeSession.Start(_endpoint, new[] { provider }, requestRundown, circularBufferMB));
 }
Esempio n. 5
0
 /// <summary>
 /// Start tracing the application and return an EventPipeSession object
 /// </summary>
 /// <param name="providers">An IEnumerable containing the list of Providers to turn on.</param>
 /// <param name="requestRundown">If true, request rundown events from the runtime</param>
 /// <param name="circularBufferMB">The size of the runtime's buffer for collecting events in MB</param>
 /// <returns>
 /// An EventPipeSession object representing the EventPipe session that just started.
 /// </returns>
 public EventPipeSession StartEventPipeSession(IEnumerable <EventPipeProvider> providers, bool requestRundown = true, int circularBufferMB = 256)
 {
     return(EventPipeSession.Start(_endpoint, providers, requestRundown, circularBufferMB));
 }
Esempio n. 6
0
 /// <summary>
 /// Start tracing the application and return an EventPipeSession object
 /// </summary>
 /// <param name="provider">An EventPipeProvider to turn on.</param>
 /// <param name="requestRundown">If true, request rundown events from the runtime</param>
 /// <param name="circularBufferMB">The size of the runtime's buffer for collecting events in MB</param>
 /// <param name="token">The token to monitor for cancellation requests.</param>
 /// <returns>
 /// An EventPipeSession object representing the EventPipe session that just started.
 /// </returns>
 internal Task <EventPipeSession> StartEventPipeSessionAsync(EventPipeProvider provider, bool requestRundown, int circularBufferMB, CancellationToken token)
 {
     return(EventPipeSession.StartAsync(_endpoint, new[] { provider }, requestRundown, circularBufferMB, token));
 }