private static EventPipeSession GetSession(int pid, bool rundown, int bufferSize) { DiagnosticsClient client = new DiagnosticsClient(pid); while (!client.CheckTransport()) { Console.WriteLine("still unable to talk"); Thread.Sleep(50); } return(client.StartEventPipeSession( new EventPipeProvider("MySource", EventLevel.Verbose), requestRundown: rundown, circularBufferMB: bufferSize)); }
public int ResolveProcess(int?pid) { if (pid.HasValue) { return(pid.Value); } // Short-circuit for when running in a Docker container. if (RuntimeInfo.IsInDockerContainer) { var client = new DiagnosticsClient(DockerEntrypointProcessId); if (client.CheckTransport()) { return(DockerEntrypointProcessId); } } // Only return a process ID if there is exactly one discoverable process. int[] pids = GetProcesses().ToArray(); switch (pids.Length) { case 0: throw new ArgumentException("Unable to discover a target process."); case 1: return(pids[0]); default: #if DEBUG Process process = pids.Select(pid => Process.GetProcessById(pid)).FirstOrDefault(p => string.Equals(p.ProcessName, "iisexpress", StringComparison.OrdinalIgnoreCase)); if (process != null) { return(process.Id); } #endif throw new ArgumentException("Unable to select a single target process because multiple target processes have been discovered."); } }