Skip to content

Commit 547d542

Browse files
authored
Add GPU crash dump attachments (#712)
* Add GPU crash dump attachment for desktop * Fix gpu dump path * Fix tooltip * Update changelog * Fix build errors on Linux
1 parent 5301f56 commit 547d542

File tree

7 files changed

+62
-1
lines changed

7 files changed

+62
-1
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
### Features
6+
7+
- Add GPU crash dump attachments ([#712](https://github.com/getsentry/sentry-unreal/pull/712))
8+
59
### Dependencies
610

711
- Bump Native SDK from v0.7.16 to v0.7.17 ([#717](https://github.com/getsentry/sentry-unreal/pull/717))

plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp

+28
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "SentryTraceSampler.h"
2020

21+
#include "Utils/SentryFileUtils.h"
2122
#include "Utils/SentryLogUtils.h"
2223
#include "Utils/SentryScreenshotUtils.h"
2324

@@ -41,8 +42,11 @@
4142

4243
#if PLATFORM_WINDOWS
4344
#include "Windows/WindowsPlatformMisc.h"
45+
#include "Windows/WindowsPlatformCrashContext.h"
4446
#endif
4547

48+
extern CORE_API bool GIsGPUCrashed;
49+
4650
#if USE_SENTRY_NATIVE
4751

4852
void PrintVerboseLog(sentry_level_t level, const char *message, va_list args, void *userdata)
@@ -135,6 +139,11 @@ sentry_value_t HandleBeforeCrash(const sentry_ucontext_t *uctx, sentry_value_t e
135139
SentrySubsystemDesktop* SentrySubsystem = static_cast<SentrySubsystemDesktop*>(closure);
136140
SentrySubsystem->TryCaptureScreenshot();
137141

142+
if (GIsGPUCrashed)
143+
{
144+
IFileManager::Get().Copy(*SentrySubsystem->GetGpuDumpBackupPath(), *SentryFileUtils::GetGpuDumpPath());
145+
}
146+
138147
FSentryCrashContext::Get()->Apply(SentrySubsystem->GetCurrentScope());
139148

140149
TSharedPtr<SentryEventDesktop> eventDesktop = MakeShareable(new SentryEventDesktop(event, true));
@@ -219,6 +228,15 @@ void SentrySubsystemDesktop::InitWithSettings(const USentrySettings* settings, U
219228
#endif
220229
}
221230

231+
if (settings->AttachGpuDump)
232+
{
233+
#if PLATFORM_WINDOWS
234+
sentry_options_add_attachmentw(options, *GetGpuDumpBackupPath());
235+
#elif PLATFORM_LINUX
236+
sentry_options_add_attachment(options, TCHAR_TO_UTF8(*GetGpuDumpBackupPath()));
237+
#endif
238+
}
239+
222240
if(settings->UseProxy)
223241
{
224242
sentry_options_set_http_proxy(options, TCHAR_TO_ANSI(*settings->ProxyUrl));
@@ -562,6 +580,16 @@ void SentrySubsystemDesktop::TryCaptureScreenshot() const
562580
SentryScreenshotUtils::CaptureScreenshot(GetScreenshotPath());
563581
}
564582

583+
FString SentrySubsystemDesktop::GetGpuDumpBackupPath() const
584+
{
585+
static const FString DateTimeString = FDateTime::Now().ToString();
586+
587+
const FString GpuDumpPath = FPaths::Combine(GetDatabasePath(), TEXT("gpudumps"), *FString::Printf(TEXT("UEAftermath-%s.nv-gpudmp"), *DateTimeString));;
588+
const FString GpuDumpFullPath = FPaths::ConvertRelativePathToFull(GpuDumpPath);
589+
590+
return GpuDumpFullPath;
591+
}
592+
565593
TSharedPtr<SentryScopeDesktop> SentrySubsystemDesktop::GetCurrentScope()
566594
{
567595
if(scopeStack.Num() == 0)

plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.h

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class SentrySubsystemDesktop : public ISentrySubsystem
4949

5050
void TryCaptureScreenshot() const;
5151

52+
FString GetGpuDumpBackupPath() const;
53+
5254
TSharedPtr<SentryScopeDesktop> GetCurrentScope();
5355

5456
private:

plugin-dev/Source/Sentry/Private/SentrySettings.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ USentrySettings::USentrySettings(const FObjectInitializer& ObjectInitializer)
2020
, AttachStacktrace(true)
2121
, SendDefaultPii(false)
2222
, AttachScreenshot(false)
23+
, AttachGpuDump(true)
2324
, MaxBreadcrumbs(100)
2425
, EnableAutoSessionTracking(true)
2526
, SessionTimeout(30000)

plugin-dev/Source/Sentry/Private/Utils/SentryFileUtils.cpp

+22-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,25 @@ FString SentryFileUtils::GetGameLogBackupPath()
4242
GameLogBackupFiles.Sort(FSentrySortFileByDatePredicate());
4343

4444
return GameLogBackupFiles[0];
45-
}
45+
}
46+
47+
FString SentryFileUtils::GetGpuDumpPath()
48+
{
49+
TArray<FString> GpuDumpFiles;
50+
IFileManager::Get().FindFiles(GpuDumpFiles, *FString::Printf(TEXT("%s*.nv-gpudmp"), *FPaths::ProjectLogDir()), true, false);
51+
52+
if (GpuDumpFiles.Num() == 0)
53+
{
54+
UE_LOG(LogSentrySdk, Log, TEXT("There is no GPU dump file available."));
55+
return FString("");
56+
}
57+
58+
if (GpuDumpFiles.Num() > 1)
59+
{
60+
// By default, engine should handle clean up of GPU dumps from the previous runs
61+
UE_LOG(LogSentrySdk, Log, TEXT("There are multiple GPU dump files, can't determine reliably which one to pick."));
62+
return FString("");
63+
}
64+
65+
return IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*(FPaths::ProjectLogDir() / GpuDumpFiles[0]));
66+
}

plugin-dev/Source/Sentry/Private/Utils/SentryFileUtils.h

+1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ class SentryFileUtils
99
public:
1010
static FString GetGameLogPath();
1111
static FString GetGameLogBackupPath();
12+
static FString GetGpuDumpPath();
1213
};

plugin-dev/Source/Sentry/Public/SentrySettings.h

+4
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ class SENTRY_API USentrySettings : public UObject
242242
Meta = (DisplayName = "Attach screenshots", ToolTip = "Flag indicating whether to attach screenshot of the application when an error occurs. Currently this feature is supported for Windows and Linux only."))
243243
bool AttachScreenshot;
244244

245+
UPROPERTY(Config, EditAnywhere, Category = "General|Attachments",
246+
Meta = (DisplayName = "Attach GPU dump", ToolTip = "Flag indicating whether to attach GPU crash dump when an error occurs. Currently this feature is supported for Nvidia graphics only."))
247+
bool AttachGpuDump;
248+
245249
UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "General|Breadcrumbs",
246250
Meta = (DisplayName = "Max breadcrumbs", Tooltip = "Total amount of breadcrumbs that should be captured."))
247251
int32 MaxBreadcrumbs;

0 commit comments

Comments
 (0)