Skip to content

Commit

Permalink
Add GPU crash dump attachments (#712)
Browse files Browse the repository at this point in the history
* Add GPU crash dump attachment for desktop

* Fix gpu dump path

* Fix tooltip

* Update changelog

* Fix build errors on Linux
  • Loading branch information
tustanivsky authored Dec 20, 2024
1 parent 5301f56 commit 547d542
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Unreleased

### Features

- Add GPU crash dump attachments ([#712](https://github.com/getsentry/sentry-unreal/pull/712))

### Dependencies

- Bump Native SDK from v0.7.16 to v0.7.17 ([#717](https://github.com/getsentry/sentry-unreal/pull/717))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "SentryTraceSampler.h"

#include "Utils/SentryFileUtils.h"
#include "Utils/SentryLogUtils.h"
#include "Utils/SentryScreenshotUtils.h"

Expand All @@ -41,8 +42,11 @@

#if PLATFORM_WINDOWS
#include "Windows/WindowsPlatformMisc.h"
#include "Windows/WindowsPlatformCrashContext.h"
#endif

extern CORE_API bool GIsGPUCrashed;

#if USE_SENTRY_NATIVE

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

if (GIsGPUCrashed)
{
IFileManager::Get().Copy(*SentrySubsystem->GetGpuDumpBackupPath(), *SentryFileUtils::GetGpuDumpPath());
}

FSentryCrashContext::Get()->Apply(SentrySubsystem->GetCurrentScope());

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

if (settings->AttachGpuDump)
{
#if PLATFORM_WINDOWS
sentry_options_add_attachmentw(options, *GetGpuDumpBackupPath());
#elif PLATFORM_LINUX
sentry_options_add_attachment(options, TCHAR_TO_UTF8(*GetGpuDumpBackupPath()));
#endif
}

if(settings->UseProxy)
{
sentry_options_set_http_proxy(options, TCHAR_TO_ANSI(*settings->ProxyUrl));
Expand Down Expand Up @@ -562,6 +580,16 @@ void SentrySubsystemDesktop::TryCaptureScreenshot() const
SentryScreenshotUtils::CaptureScreenshot(GetScreenshotPath());
}

FString SentrySubsystemDesktop::GetGpuDumpBackupPath() const
{
static const FString DateTimeString = FDateTime::Now().ToString();

const FString GpuDumpPath = FPaths::Combine(GetDatabasePath(), TEXT("gpudumps"), *FString::Printf(TEXT("UEAftermath-%s.nv-gpudmp"), *DateTimeString));;
const FString GpuDumpFullPath = FPaths::ConvertRelativePathToFull(GpuDumpPath);

return GpuDumpFullPath;
}

TSharedPtr<SentryScopeDesktop> SentrySubsystemDesktop::GetCurrentScope()
{
if(scopeStack.Num() == 0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class SentrySubsystemDesktop : public ISentrySubsystem

void TryCaptureScreenshot() const;

FString GetGpuDumpBackupPath() const;

TSharedPtr<SentryScopeDesktop> GetCurrentScope();

private:
Expand Down
1 change: 1 addition & 0 deletions plugin-dev/Source/Sentry/Private/SentrySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ USentrySettings::USentrySettings(const FObjectInitializer& ObjectInitializer)
, AttachStacktrace(true)
, SendDefaultPii(false)
, AttachScreenshot(false)
, AttachGpuDump(true)
, MaxBreadcrumbs(100)
, EnableAutoSessionTracking(true)
, SessionTimeout(30000)
Expand Down
23 changes: 22 additions & 1 deletion plugin-dev/Source/Sentry/Private/Utils/SentryFileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,25 @@ FString SentryFileUtils::GetGameLogBackupPath()
GameLogBackupFiles.Sort(FSentrySortFileByDatePredicate());

return GameLogBackupFiles[0];
}
}

FString SentryFileUtils::GetGpuDumpPath()
{
TArray<FString> GpuDumpFiles;
IFileManager::Get().FindFiles(GpuDumpFiles, *FString::Printf(TEXT("%s*.nv-gpudmp"), *FPaths::ProjectLogDir()), true, false);

if (GpuDumpFiles.Num() == 0)
{
UE_LOG(LogSentrySdk, Log, TEXT("There is no GPU dump file available."));
return FString("");
}

if (GpuDumpFiles.Num() > 1)
{
// By default, engine should handle clean up of GPU dumps from the previous runs
UE_LOG(LogSentrySdk, Log, TEXT("There are multiple GPU dump files, can't determine reliably which one to pick."));
return FString("");
}

return IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*(FPaths::ProjectLogDir() / GpuDumpFiles[0]));
}
1 change: 1 addition & 0 deletions plugin-dev/Source/Sentry/Private/Utils/SentryFileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ class SentryFileUtils
public:
static FString GetGameLogPath();
static FString GetGameLogBackupPath();
static FString GetGpuDumpPath();
};
4 changes: 4 additions & 0 deletions plugin-dev/Source/Sentry/Public/SentrySettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@ class SENTRY_API USentrySettings : public UObject
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."))
bool AttachScreenshot;

UPROPERTY(Config, EditAnywhere, Category = "General|Attachments",
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."))
bool AttachGpuDump;

UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "General|Breadcrumbs",
Meta = (DisplayName = "Max breadcrumbs", Tooltip = "Total amount of breadcrumbs that should be captured."))
int32 MaxBreadcrumbs;
Expand Down

0 comments on commit 547d542

Please sign in to comment.