public void Invoke_CreatesDump() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { var loggerFactory = TestHelpers.GetLoggerFactory(); var logger1 = loggerFactory.CreateLogger <WindowsHeapDumper>(); var logger2 = loggerFactory.CreateLogger <HeapDumpEndpoint>(); var dumper = new WindowsHeapDumper(new HeapDumpEndpointOptions(), logger: logger1); var ep = new HeapDumpEndpoint(new HeapDumpEndpointOptions(), dumper, logger2); var result = ep.Invoke(); Assert.NotNull(result); Assert.True(File.Exists(result)); File.Delete(result); } else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) { if (typeof(object).Assembly.GetType("System.Index") != null) { var loggerFactory = TestHelpers.GetLoggerFactory(); var logger1 = loggerFactory.CreateLogger <LinuxHeapDumper>(); var logger2 = loggerFactory.CreateLogger <HeapDumpEndpoint>(); var dumper = new LinuxHeapDumper(new HeapDumpEndpointOptions(), logger: logger1); var ep = new HeapDumpEndpoint(new HeapDumpEndpointOptions(), dumper, logger2); var result = ep.Invoke(); Assert.NotNull(result); Assert.True(File.Exists(result)); File.Delete(result); } } }
protected internal async Task HandleHeapDumpRequestAsync(IOwinContext context) { var filename = _endpoint.Invoke(); _logger?.LogDebug("Returning: {0}", filename); context.Response.Headers.SetValues("Content-Type", new string[] { "application/octet-stream" }); if (!File.Exists(filename)) { context.Response.StatusCode = (int)HttpStatusCode.NotFound; return; } string gzFilename = filename + ".gz"; var result = await Utils.CompressFileAsync(filename, gzFilename); if (result != null) { using (result) { context.Response.Headers.Add("Content-Disposition", new string[] { "attachment; filename=\"" + Path.GetFileName(gzFilename) + "\"" }); context.Response.StatusCode = (int)HttpStatusCode.OK; context.Response.ContentLength = result.Length; await result.CopyToAsync(context.Response.Body); } File.Delete(gzFilename); } else { context.Response.StatusCode = (int)HttpStatusCode.NotFound; } }
public void Invoke_CreatesDump() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { var loggerFactory = TestHelpers.GetLoggerFactory(); var logger1 = loggerFactory.CreateLogger <HeapDumper>(); var logger2 = loggerFactory.CreateLogger <HeapDumpEndpoint>(); var dumper = new HeapDumper(new HeapDumpEndpointOptions(), logger: logger1); var ep = new HeapDumpEndpoint(new HeapDumpEndpointOptions(), dumper, logger2); var result = ep.Invoke(); Assert.NotNull(result); Assert.True(File.Exists(result)); File.Delete(result); } }
public void Invoke_CreatesDump() { if (Environment.OSVersion.Platform == PlatformID.Win32NT) { LoggerFactory loggerFactory = new LoggerFactory(); loggerFactory.AddConsole(minLevel: LogLevel.Debug); var logger1 = loggerFactory.CreateLogger <HeapDumper>(); var logger2 = loggerFactory.CreateLogger <HeapDumpEndpoint>(); var dumper = new HeapDumper(new HeapDumpOptions(), logger: logger1); var ep = new HeapDumpEndpoint(new HeapDumpOptions(), dumper, logger2); var result = ep.Invoke(); Assert.NotNull(result); Assert.True(File.Exists(result)); File.Delete(result); } }