Пример #1
0
        public Task <ActionResult> GetDump(int?pid, [FromQuery] DumpType type = DumpType.WithHeap)
        {
            return(this.InvokeService(async() =>
            {
                int pidValue = await _diagnosticServices.ResolveProcessAsync(pid, HttpContext.RequestAborted);
                Stream result = await _diagnosticServices.GetDump(pidValue, type, HttpContext.RequestAborted);

                string dumpFileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
                                      FormattableString.Invariant($"dump_{GetFileNameTimeStampUtcNow()}.dmp") :
                                      FormattableString.Invariant($"core_{GetFileNameTimeStampUtcNow()}");

                //Compression is done automatically by the response
                //Chunking is done because the result has no content-length
                return File(result, "application/octet-stream", dumpFileName);
            }));
        }
        protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            return(Task.Run(async() =>
            {
                while (!stoppingToken.IsCancellationRequested)
                {
                    stoppingToken.ThrowIfCancellationRequested();

                    try
                    {
                        //TODO In multi-process scenarios, how do we decide which process to choose?
                        //One possibility is to enable metrics after a request to begin polling for metrics
                        int pid = await _services.ResolveProcessAsync(pid: null, stoppingToken);
                        var client = new DiagnosticsClient(pid);
                        await _pipeProcessor.Process(client, pid, Timeout.InfiniteTimeSpan, stoppingToken);
                    }
                    catch (Exception e) when(!(e is OperationCanceledException))
                    {
                        //Most likely we failed to resolve the pid. Attempt to do this again.
                        await Task.Delay(5000);
                    }
                }
            }, stoppingToken));
        }