public async Task <Stream> DumpAsync(IEndpointInfo endpointInfo, Models.DumpType mode, CancellationToken token) { if (endpointInfo == null) { throw new ArgumentNullException(nameof(endpointInfo)); } string dumpTempFolder = _storageOptions.CurrentValue.DumpTempFolder; // Ensure folder exists before issue command. if (!Directory.Exists(dumpTempFolder)) { Directory.CreateDirectory(dumpTempFolder); } string dumpFilePath = Path.Combine(dumpTempFolder, FormattableString.Invariant($"{Guid.NewGuid()}_{endpointInfo.ProcessId}")); DumpType dumpType = MapDumpType(mode); IDisposable operationRegistration = null; // Only track operation status for endpoints from a listening server because: // 1) Each process only ever has a single instance of an IEndpointInfo // 2) Only the listening server will query the dump service for the operation status of an endpoint. if (IsListenMode) { // This is a quick fix to prevent the polling algorithm in the ServerEndpointInfoSource // from removing IEndpointInfo instances when they don't respond in a timely manner to // a dump operation causing the runtime to temporarily be unresponsive. Long term, this // concept should be folded into RequestLimitTracker with registered endpoint information // and allowing to query the status of an endpoint for a given artifact. operationRegistration = _operationTrackerService.Register(endpointInfo); } try { if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Get the process Process process = Process.GetProcessById(endpointInfo.ProcessId); await Dumper.CollectDumpAsync(process, dumpFilePath, dumpType); } else { var client = new DiagnosticsClient(endpointInfo.Endpoint); await client.WriteDumpAsync(dumpType, dumpFilePath, logDumpGeneration : false, token); } } finally { operationRegistration?.Dispose(); } return(new AutoDeleteFileStream(dumpFilePath)); }
public async Task <Stream> GetDump(IProcessInfo pi, DumpType mode, CancellationToken token) { string dumpFilePath = Path.Combine(Path.GetTempPath(), FormattableString.Invariant($"{Guid.NewGuid()}_{pi.ProcessId}")); NETCore.Client.DumpType dumpType = MapDumpType(mode); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { // Get the process Process process = Process.GetProcessById(pi.ProcessId); await Dumper.CollectDumpAsync(process, dumpFilePath, dumpType); } else { await Task.Run(() => { pi.Client.WriteDump(dumpType, dumpFilePath); }); } return(new AutoDeleteFileStream(dumpFilePath)); }