Ejemplo n.º 1
0
        private async Task <ActionResult <T> > InvokeForProcess <T>(Func <IProcessInfo, Task <ActionResult <T> > > func, ProcessFilter?filter, string artifactType = null)
        {
            IDisposable artifactTypeRegistration = null;

            if (!string.IsNullOrEmpty(artifactType))
            {
                KeyValueLogScope artifactTypeScope = new KeyValueLogScope();
                artifactTypeScope.AddArtifactType(artifactType);
                artifactTypeRegistration = _logger.BeginScope(artifactTypeScope);
            }

            try
            {
                return(await this.InvokeService(async() =>
                {
                    IProcessInfo processInfo = await _diagnosticServices.GetProcessAsync(filter, HttpContext.RequestAborted);

                    KeyValueLogScope processInfoScope = new KeyValueLogScope();
                    processInfoScope.AddEndpointInfo(processInfo.EndpointInfo);
                    using var _ = _logger.BeginScope(processInfoScope);

                    _logger.LogDebug("Resolved target process.");

                    return await func(processInfo);
                }, _logger));
            }
            finally
            {
                artifactTypeRegistration?.Dispose();
            }
        }
Ejemplo n.º 2
0
        public Task <ActionResult> GetDump(
            ProcessFilter?processFilter,
            [FromQuery] DumpType type         = DumpType.WithHeap,
            [FromQuery] string egressProvider = null)
        {
            return(InvokeForProcess(async processInfo =>
            {
                string dumpFileName = RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
                                      FormattableString.Invariant($"dump_{GetFileNameTimeStampUtcNow()}.dmp") :
                                      FormattableString.Invariant($"core_{GetFileNameTimeStampUtcNow()}");

                if (string.IsNullOrEmpty(egressProvider))
                {
                    Stream dumpStream = await _diagnosticServices.GetDump(processInfo, type, HttpContext.RequestAborted);

                    //Compression is done automatically by the response
                    //Chunking is done because the result has no content-length
                    return File(dumpStream, ContentTypes.ApplicationOctectStream, dumpFileName);
                }
                else
                {
                    KeyValueLogScope scope = new KeyValueLogScope();
                    scope.AddArtifactType(ArtifactType_Dump);
                    scope.AddEndpointInfo(processInfo.EndpointInfo);

                    return new EgressStreamResult(
                        token => _diagnosticServices.GetDump(processInfo, type, token),
                        egressProvider,
                        dumpFileName,
                        processInfo.EndpointInfo,
                        ContentTypes.ApplicationOctectStream,
                        scope);
                }
            }, processFilter, ArtifactType_Dump));
        }
Ejemplo n.º 3
0
        private ActionResult Result(
            string artifactType,
            string providerName,
            Func <Stream, CancellationToken, Task> action,
            string fileName,
            string contentType,
            IEndpointInfo endpointInfo,
            bool asAttachment = true)
        {
            KeyValueLogScope scope = new KeyValueLogScope();

            scope.AddArtifactType(artifactType);
            scope.AddEndpointInfo(endpointInfo);

            if (string.IsNullOrEmpty(providerName))
            {
                return(new OutputStreamResult(
                           action,
                           contentType,
                           asAttachment ? fileName : null,
                           scope));
            }
            else
            {
                return(new EgressStreamResult(
                           action,
                           providerName,
                           fileName,
                           endpointInfo,
                           contentType,
                           scope));
            }
        }