Exemplo n.º 1
0
        public bool Start(Action <TraceEvent> trigger, Action <EventPipeEventSource> onSubscribe, Func <TraceEvent, bool> filter = null)
        {
            if (IsStarted || Providers.Count == 0)
            {
                return(false);
            }

            this.Trigger = trigger;
            this.Filter  = filter;

            Task.Run(() =>
            {
                if (!StartSession())
                {
                    Console.WriteLine($"Could not start the session - aborting");
                    // TODO: better exit
                    return;
                }

                // resuming remote process
                _client.ResumeRuntime();

                _source = new EventPipeEventSource(_session.EventStream);
                onSubscribe(_source);

                _source.Dynamic.All += Dynamic_All;
                _source.Process();
            });

            IsStarted = true;
            return(true);
        }
        private async Task ResumeAndQueueEndpointInfo(IpcEndpointInfo info, CancellationToken token)
        {
            try
            {
                // Send ResumeRuntime message for runtime instances that connect to the server. This will allow
                // those instances that are configured to pause on start to resume after the diagnostics
                // connection has been made. Instances that are not configured to pause on startup will ignore
                // the command and return success.
                var client = new DiagnosticsClient(info.Endpoint);
                try
                {
                    client.ResumeRuntime();
                }
                catch (ServerErrorException)
                {
                    // The runtime likely doesn't understand the ResumeRuntime command.
                }

                EndpointInfo endpointInfo = EndpointInfo.FromIpcEndpointInfo(info);

                await _endpointInfosSemaphore.WaitAsync(token).ConfigureAwait(false);

                try
                {
                    _endpointInfos.Add(endpointInfo);

                    OnAddedEndpointInfo(endpointInfo);
                }
                finally
                {
                    _endpointInfosSemaphore.Release();
                }
            }
            catch (Exception)
            {
                _server?.RemoveConnection(info.RuntimeInstanceCookie);

                throw;
            }
        }
Exemplo n.º 3
0
        private async Task <int> Start()
        {
            string providerString = BuildProviderString();

            if (providerString.Length == 0)
            {
                return(1);
            }

            _renderer.Initialize();

            Task monitorTask = new Task(() => {
                try
                {
                    _session = _diagnosticsClient.StartEventPipeSession(Trace.Extensions.ToProviders(providerString), false, 10);
                    if (shouldResumeRuntime)
                    {
                        _diagnosticsClient.ResumeRuntime();
                    }
                    var source          = new EventPipeEventSource(_session.EventStream);
                    source.Dynamic.All += DynamicAllMonitor;
                    _renderer.EventPipeSourceConnected();
                    source.Process();
                }
                catch (DiagnosticsClientException ex)
                {
                    Console.WriteLine($"Failed to start the counter session: {ex.ToString()}");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"[ERROR] {ex.ToString()}");
                }
                finally
                {
                    shouldExit.Set();
                }
            });

            monitorTask.Start();

            while (!shouldExit.WaitOne(250))
            {
                while (true)
                {
                    if (shouldExit.WaitOne(250))
                    {
                        StopMonitor();
                        return(0);
                    }
                    if (Console.KeyAvailable)
                    {
                        break;
                    }
                }
                ConsoleKey cmd = Console.ReadKey(true).Key;
                if (cmd == ConsoleKey.Q)
                {
                    StopMonitor();
                    break;
                }
                else if (cmd == ConsoleKey.P)
                {
                    pauseCmdSet = true;
                }
                else if (cmd == ConsoleKey.R)
                {
                    pauseCmdSet = false;
                }
            }
            return(await Task.FromResult(0));
        }
Exemplo n.º 4
0
        private Task <int> Start()
        {
            EventPipeProvider[] providers = GetEventPipeProviders();
            _renderer.Initialize();

            Task monitorTask = new Task(() => {
                try
                {
                    _session = _diagnosticsClient.StartEventPipeSession(providers, false, 10);
                    if (_resumeRuntime)
                    {
                        try
                        {
                            _diagnosticsClient.ResumeRuntime();
                        }
                        catch (UnsupportedCommandException)
                        {
                            // Noop if the command is unknown since the target process is most likely a 3.1 app.
                        }
                    }
                    var source          = new EventPipeEventSource(_session.EventStream);
                    source.Dynamic.All += DynamicAllMonitor;
                    _renderer.EventPipeSourceConnected();
                    source.Process();
                }
                catch (DiagnosticsClientException ex)
                {
                    Console.WriteLine($"Failed to start the counter session: {ex.ToString()}");
                }
                catch (Exception ex)
                {
                    Debug.WriteLine($"[ERROR] {ex.ToString()}");
                }
                finally
                {
                    _shouldExit.TrySetResult(ReturnCode.Ok);
                }
            });

            monitorTask.Start();

            while (!_shouldExit.Task.Wait(250))
            {
                HandleBufferedEvents();
                if (Console.KeyAvailable)
                {
                    ConsoleKey cmd = Console.ReadKey(true).Key;
                    if (cmd == ConsoleKey.Q)
                    {
                        break;
                    }
                    else if (cmd == ConsoleKey.P)
                    {
                        _pauseCmdSet = true;
                    }
                    else if (cmd == ConsoleKey.R)
                    {
                        _pauseCmdSet = false;
                    }
                }
            }

            StopMonitor();
            return(_shouldExit.Task);
        }