Exemplo n.º 1
0
        internal static EventPipeSession Start(IpcEndpoint endpoint, IEnumerable <EventPipeProvider> providers, bool requestRundown, int circularBufferMB)
        {
            IpcMessage  requestMessage = CreateStartMessage(providers, requestRundown, circularBufferMB);
            IpcResponse?response       = IpcClient.SendMessageGetContinuation(endpoint, requestMessage);

            return(CreateSessionFromResponse(endpoint, ref response, nameof(Start)));
        }
Exemplo n.º 2
0
        internal static async Task <EventPipeSession> StartAsync(IpcEndpoint endpoint, IEnumerable <EventPipeProvider> providers, bool requestRundown, int circularBufferMB, CancellationToken cancellationToken)
        {
            IpcMessage  requestMessage = CreateStartMessage(providers, requestRundown, circularBufferMB);
            IpcResponse?response       = await IpcClient.SendMessageGetContinuationAsync(endpoint, requestMessage, cancellationToken).ConfigureAwait(false);

            return(CreateSessionFromResponse(endpoint, ref response, nameof(StartAsync)));
        }
Exemplo n.º 3
0
        private bool disposedValue = false; // To detect redundant calls

        internal EventPipeSession(IpcEndpoint endpoint, IEnumerable <EventPipeProvider> providers, bool requestRundown, int circularBufferMB)
        {
            _endpoint         = endpoint;
            _providers        = providers;
            _requestRundown   = requestRundown;
            _circularBufferMB = circularBufferMB;

            var config  = new EventPipeSessionConfiguration(circularBufferMB, EventPipeSerializationFormat.NetTrace, providers, requestRundown);
            var message = new IpcMessage(DiagnosticsServerCommandSet.EventPipe, (byte)EventPipeCommandId.CollectTracing2, config.SerializeV2());

            EventStream = IpcClient.SendMessage(endpoint, message, out var response);
            switch ((DiagnosticsServerResponseId)response.Header.CommandId)
            {
            case DiagnosticsServerResponseId.OK:
                _sessionId = BitConverter.ToInt64(response.Payload, 0);
                break;

            case DiagnosticsServerResponseId.Error:
                var hr = BitConverter.ToInt32(response.Payload, 0);
                throw new ServerErrorException($"EventPipe session start failed (HRESULT: 0x{hr:X8})");

            default:
                throw new ServerErrorException($"EventPipe session start failed - Server responded with unknown command");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends a single DiagnosticsIpc Message to the dotnet process with PID processId
        /// and returns the Stream for reuse in Optional Continuations.
        /// </summary>
        /// <param name="endpoint">An endpoint that provides a diagnostics connection to a runtime instance.</param>
        /// <param name="message">The DiagnosticsIpc Message to be sent</param>
        /// <param name="response">out var for response message</param>
        /// <returns>The response DiagnosticsIpc Message from the dotnet process</returns>
        public static Stream SendMessage(IpcEndpoint endpoint, IpcMessage message, out IpcMessage response)
        {
            var stream = endpoint.Connect(ConnectTimeout);

            Write(stream, message);
            response = Read(stream);
            return(stream);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Sends a single DiagnosticsIpc Message to the dotnet process with PID processId.
 /// </summary>
 /// <param name="endpoint">An endpoint that provides a diagnostics connection to a runtime instance.</param>
 /// <param name="message">The DiagnosticsIpc Message to be sent</param>
 /// <returns>The response DiagnosticsIpc Message from the dotnet process</returns>
 public static IpcMessage SendMessage(IpcEndpoint endpoint, IpcMessage message)
 {
     using (var stream = endpoint.Connect(ConnectTimeout))
     {
         Write(stream, message);
         return(Read(stream));
     }
 }
Exemplo n.º 6
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();
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Sends a single DiagnosticsIpc Message to the dotnet process associated with the <paramref name="endpoint"/>.
        /// </summary>
        /// <param name="endpoint">An endpoint that provides a diagnostics connection to a runtime instance.</param>
        /// <param name="message">The DiagnosticsIpc Message to be sent</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>An <see cref="IpcResponse"/> containing the response message and continuation stream.</returns>
        public static async Task <IpcResponse> SendMessageGetContinuationAsync(IpcEndpoint endpoint, IpcMessage message, CancellationToken cancellationToken)
        {
            Stream stream = null;

            try
            {
                stream = await endpoint.ConnectAsync(cancellationToken).ConfigureAwait(false);

                await WriteAsync(stream, message, cancellationToken).ConfigureAwait(false);

                IpcMessage response = await ReadAsync(stream, cancellationToken).ConfigureAwait(false);

                return(new IpcResponse(response, Release(ref stream)));
            }
            finally
            {
                stream?.Dispose();
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Sends a single DiagnosticsIpc Message to the dotnet process associated with the <paramref name="endpoint"/>.
        /// </summary>
        /// <param name="endpoint">An endpoint that provides a diagnostics connection to a runtime instance.</param>
        /// <param name="message">The DiagnosticsIpc Message to be sent</param>
        /// <returns>An <see cref="IpcResponse"/> containing the response message and continuation stream.</returns>
        public static IpcResponse SendMessageGetContinuation(IpcEndpoint endpoint, IpcMessage message)
        {
            Stream stream = null;

            try
            {
                stream = endpoint.Connect(ConnectTimeout);

                Write(stream, message);

                IpcMessage response = Read(stream);

                return(new IpcResponse(response, Release(ref stream)));
            }
            finally
            {
                stream?.Dispose();
            }
        }
Exemplo n.º 9
0
 private EventPipeSession(IpcEndpoint endpoint, IpcResponse response, long sessionId)
 {
     _endpoint  = endpoint;
     _response  = response;
     _sessionId = sessionId;
 }
Exemplo n.º 10
0
        /// <summary>
        /// Sends a single DiagnosticsIpc Message to the dotnet process associated with the <paramref name="endpoint"/>.
        /// </summary>
        /// <param name="endpoint">An endpoint that provides a diagnostics connection to a runtime instance.</param>
        /// <param name="message">The DiagnosticsIpc Message to be sent</param>
        /// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
        /// <returns>An <see cref="IpcMessage"/> that is the response message.</returns>
        public static async Task <IpcMessage> SendMessageAsync(IpcEndpoint endpoint, IpcMessage message, CancellationToken cancellationToken)
        {
            using IpcResponse response = await SendMessageGetContinuationAsync(endpoint, message, cancellationToken).ConfigureAwait(false);

            return(response.Message);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Sends a single DiagnosticsIpc Message to the dotnet process associated with the <paramref name="endpoint"/>.
 /// </summary>
 /// <param name="endpoint">An endpoint that provides a diagnostics connection to a runtime instance.</param>
 /// <param name="message">The DiagnosticsIpc Message to be sent</param>
 /// <returns>An <see cref="IpcMessage"/> that is the response message.</returns>
 public static IpcMessage SendMessage(IpcEndpoint endpoint, IpcMessage message)
 {
     using IpcResponse response = SendMessageGetContinuation(endpoint, message);
     return(response.Message);
 }
Exemplo n.º 12
0
 internal IpcEndpointInfo(IpcEndpoint endpoint, int processId, Guid runtimeInstanceCookie)
 {
     Endpoint              = endpoint;
     ProcessId             = processId;
     RuntimeInstanceCookie = runtimeInstanceCookie;
 }
Exemplo n.º 13
0
 internal DiagnosticsClient(IpcEndpoint endpoint)
 {
     _endpoint = endpoint;
 }
Exemplo n.º 14
0
 // Raf: made it public
 public DiagnosticsClient(IpcEndpoint endpoint)
 {
     _endpoint = endpoint;
 }