public async Task <IStreamWithCleanup> StartTrace(IProcessInfo pi, MonitoringSourceConfiguration configuration, TimeSpan duration, CancellationToken token) { DiagnosticsMonitor monitor = new DiagnosticsMonitor(configuration); Stream stream = await monitor.ProcessEvents(pi.Client, duration, token); return(new StreamWithCleanup(monitor, stream)); }
public async Task <IStreamWithCleanup> StartTrace(int pid, TraceProfile profile, TimeSpan duration, int metricsIntervalSeconds, CancellationToken token) { IList <MonitoringSourceConfiguration> configurations = new List <MonitoringSourceConfiguration>(); if (profile.HasFlag(TraceProfile.Cpu)) { configurations.Add(new CpuProfileConfiguration()); } if (profile.HasFlag(TraceProfile.Http)) { configurations.Add(new HttpRequestSourceConfiguration()); } if (profile.HasFlag(TraceProfile.Logs)) { configurations.Add(new LoggingSourceConfiguration()); } if (profile.HasFlag(TraceProfile.Metrics)) { configurations.Add(new MetricSourceConfiguration(metricsIntervalSeconds)); } AggregateSourceConfiguration aggregateConfiguration = new AggregateSourceConfiguration(configurations.ToArray()); DiagnosticsMonitor monitor = new DiagnosticsMonitor(aggregateConfiguration); Stream stream = await monitor.ProcessEvents(pid, duration, token); return(new StreamWithCleanup(monitor, stream)); }
public async Task <IStreamWithCleanup> StartCpuTrace(int pid, TimeSpan duration, CancellationToken cancellationToken) { DiagnosticsMonitor monitor = new DiagnosticsMonitor(new CpuProfileConfiguration()); Stream stream = await monitor.ProcessEvents(pid, duration, cancellationToken); return(new StreamWithCleanup(monitor, stream)); }
public async Task Process(int pid, TimeSpan duration, CancellationToken token) { await await Task.Factory.StartNew(async() => { EventPipeEventSource source = null; DiagnosticsMonitor monitor = null; try { MonitoringSourceConfiguration config = null; if (_mode == PipeMode.Logs) { config = new LoggingSourceConfiguration(); } if (_mode == PipeMode.Metrics) { config = new MetricSourceConfiguration(); } monitor = new DiagnosticsMonitor(config); Stream sessionStream = await monitor.ProcessEvents(pid, duration, token); source = new EventPipeEventSource(sessionStream); if (_mode == PipeMode.Metrics) { // Metrics HandleEventCounters(source); } if (_mode == PipeMode.Logs) { // Logging HandleLoggingEvents(source); } source.Process(); } catch (DiagnosticsClientException ex) { throw new InvalidOperationException("Failed to start the event pipe session", ex); } finally { source?.Dispose(); if (monitor != null) { await monitor.DisposeAsync(); } } }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
public async Task Process(int pid, TimeSpan duration, CancellationToken token) { await await Task.Factory.StartNew(async() => { EventPipeEventSource source = null; DiagnosticsMonitor monitor = null; Task handleEventsTask = Task.CompletedTask; try { MonitoringSourceConfiguration config = null; if (_mode == PipeMode.Logs) { config = new LoggingSourceConfiguration(); } if (_mode == PipeMode.Metrics) { config = new MetricSourceConfiguration(_metricIntervalSeconds); } if (_mode == PipeMode.GCDump) { config = new GCDumpSourceConfiguration(); } monitor = new DiagnosticsMonitor(config); Stream sessionStream = await monitor.ProcessEvents(pid, duration, token); source = new EventPipeEventSource(sessionStream); // Allows the event handling routines to stop processing before the duration expires. Func <Task> stopFunc = () => Task.Run(() => { monitor.StopProcessing(); }); if (_mode == PipeMode.Metrics) { // Metrics HandleEventCounters(source); } if (_mode == PipeMode.Logs) { // Logging HandleLoggingEvents(source); } if (_mode == PipeMode.GCDump) { // GC handleEventsTask = HandleGCEvents(source, pid, stopFunc, token); } source.Process(); token.ThrowIfCancellationRequested(); } catch (DiagnosticsClientException ex) { throw new InvalidOperationException("Failed to start the event pipe session", ex); } finally { source?.Dispose(); if (monitor != null) { await monitor.DisposeAsync(); } } // Await the task returned by the event handling method AFTER the EventPipeEventSource is disposed. // The EventPipeEventSource will only raise the Completed event when it is disposed. So if this task // is waiting for the Completed event to be raised, it will never complete until after EventPipeEventSource // is diposed. await handleEventsTask; }, token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }