tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
DotnetDumpService.cs
Go to the documentation of this file.
1using System;
2using System.Threading;
3using System.Threading.Tasks;
4
5using Microsoft.Diagnostics.NETCore.Client;
6using Microsoft.Extensions.Logging;
7
10
12{
15 {
19 readonly ILogger<DotnetDumpService> logger;
20
26 ILogger<DotnetDumpService> logger)
27 {
28 this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
29 }
30
32 public async ValueTask Dump(IProcess process, string outputFile, bool minidump, CancellationToken cancellationToken)
33 {
34 // need to use an extra timeout here because if the process is truly deadlocked. A cooperative dump will hang forever
35 using var cts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
36
37 const int TimeoutMinutes = 5;
38 cts.CancelAfter(TimeSpan.FromMinutes(TimeoutMinutes));
39 cts.Token.Register(() =>
40 {
41 if (!cancellationToken.IsCancellationRequested)
42 logger.LogError("dotnet-dump timed out after {minutes} minutes!", TimeoutMinutes);
43 });
44
45 var pid = process.Id;
46 logger.LogDebug("dotnet-dump requested for PID {pid}...", pid);
47 var client = new DiagnosticsClient(pid);
48 try
49 {
50 await client.WriteDumpAsync(
51 minidump
52 ? DumpType.Normal
53 : DumpType.Full,
54 outputFile,
55 false,
56 cts.Token);
57 }
58 catch (Exception ex)
59 {
60 throw new JobException(ErrorCode.GCoreFailure, ex);
61 }
62 }
63 }
64}
Operation exceptions thrown from the context of a Models.Job.
async ValueTask Dump(IProcess process, string outputFile, bool minidump, CancellationToken cancellationToken)
Attempt to dump a given process .A ValueTask representing the running operation.
DotnetDumpService(ILogger< DotnetDumpService > logger)
Initializes a new instance of the DotnetDumpService class.
readonly ILogger< DotnetDumpService > logger
The ILogger for the DotnetDumpService.
Service for managing the dotnet-dump installation.
Abstraction over a global::System.Diagnostics.Process.
Definition IProcess.cs:11
ErrorCode
Types of Response.ErrorMessageResponses that the API may return.
Definition ErrorCode.cs:12