SpiecsEngine
 
Loading...
Searching...
No Matches

◆ WriteGpuCrashDumpToFile()

void Spices::GpuCrashTracker::WriteGpuCrashDumpToFile ( const void * pGpuCrashDump,
const uint32_t gpuCrashDumpSize )
private

Helper for writing a GPU crash dump to a file.

Parameters
[in]pGpuCrashDump.
[in]gpuCrashDumpSize.

Create a GPU crash dump decoder object for the GPU crash dump.

Use the decoder object to read basic information, like application name, PID, etc.from the GPU crash dump.

Use the decoder object to query the application name that was set in the GPU crash dump description.

Create a unique file name for writing the crash dump data to a file. Note: due to an Nsight Aftermath bug (will be fixed in an upcoming driver release) we may see redundant crash dumps. As a workaround, attach a unique count to each generated file name.

Aftermath file folder.

Write the crash dump data to a file using the .nv-gpudmp extension registered with Nsight Graphics.

Step 2: Allocate a buffer and fetch the generated JSON.

Write the crash dump data as JSON to a file.

Write the JSON to the file (excluding string termination).

Destroy the GPU crash dump decoder object.

Create a GPU crash dump decoder object for the GPU crash dump.

Use the decoder object to read basic information, like application name, PID, etc.from the GPU crash dump.

Use the decoder object to query the application name that was set in the GPU crash dump description.

Create a unique file name for writing the crash dump data to a file. Note: due to an Nsight Aftermath bug (will be fixed in an upcoming driver release) we may see redundant crash dumps. As a workaround, attach a unique count to each generated file name.

Aftermath file folder.

Write the crash dump data to a file using the .nv-gpudmp extension registered with Nsight Graphics.

Step 2: Allocate a buffer and fetch the generated JSON.

Write the crash dump data as JSON to a file.

Write the JSON to the file (excluding string termination).

Destroy the GPU crash dump decoder object.

Definition at line 232 of file NsightAftermathGpuCrashTracker.cpp.

233 {
235
239 GFSDK_Aftermath_GpuCrashDump_Decoder decoder = {};
240 AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_CreateDecoder(
241 GFSDK_Aftermath_Version_API ,
242 pGpuCrashDump ,
243 gpuCrashDumpSize ,
244 &decoder
245 ));
246
251 GFSDK_Aftermath_GpuCrashDump_BaseInfo baseInfo = {};
252 AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetBaseInfo(decoder, &baseInfo));
253
258 uint32_t applicationNameLength = 0;
259 AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetDescriptionSize(
260 decoder ,
261 GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName ,
262 &applicationNameLength
263 ));
264
265 std::vector<char> applicationName(applicationNameLength, '\0');
266
267 AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetDescription(
268 decoder ,
269 GFSDK_Aftermath_GpuCrashDumpDescriptionKey_ApplicationName ,
270 static_cast<uint32_t>(applicationName.size()) ,
271 applicationName.data()
272 ));
273
280 static int count = 0;
281 const std::string baseFileName =
282 std::string(applicationName.data())
283 + "-"
284 + std::to_string(baseInfo.pid)
285 + "-"
287
291 time_t timep;
292 tm* p;
293
294 auto error = time(&timep);
295 p = localtime(&timep);
296
297 std::stringstream ss;
298 ss << SPICES_GPUCRASHREPORT_PATH <<
299 p->tm_year + 1900 <<
300 p->tm_mon + 1 <<
301 p->tm_mday << "_" <<
302 p->tm_hour <<
303 p->tm_min << "00" << "/";
304 std::filesystem::create_directories(ss.str());
305
310 const std::string crashDumpFileName = baseFileName + ".nv-gpudmp";
311 std::ofstream dumpFile(ss.str() + crashDumpFileName, std::ios::out | std::ios::binary);
312 if (dumpFile)
313 {
314 dumpFile.write(static_cast<const char*>(pGpuCrashDump), gpuCrashDumpSize);
315 dumpFile.close();
316 }
317
318 /*
319 * @brief Decode the crash dump to a JSON string.
320 * Step 1: Generate the JSON and get the size.
321 */
322 uint32_t jsonSize = 0;
323 AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GenerateJSON(
324 decoder ,
325 GFSDK_Aftermath_GpuCrashDumpDecoderFlags_ALL_INFO ,
326 GFSDK_Aftermath_GpuCrashDumpFormatterFlags_NONE ,
330 this ,
331 &jsonSize
332 ));
333
337 std::vector<char> json(jsonSize);
338 AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_GetJSON(
339 decoder ,
340 static_cast<uint32_t>(json.size()) ,
341 json.data()
342 ));
343
347 const std::string jsonFileName = crashDumpFileName + ".json";
348 std::ofstream jsonFile(ss.str() + jsonFileName, std::ios::out | std::ios::binary);
349 if (jsonFile)
350 {
354 jsonFile.write(json.data(), json.size() - 1);
355 jsonFile.close();
356 }
357
361 AFTERMATH_CHECK_ERROR(GFSDK_Aftermath_GpuCrashDump_DestroyDecoder(decoder));
362 }
#define AFTERMATH_CHECK_ERROR(FC)
Helper macro for checking Nsight Aftermath results and throwing exception in case of a failure.
#define SPICES_PROFILE_ZONE
static void ShaderSourceDebugInfoLookupCallback(const GFSDK_Aftermath_ShaderDebugName *pShaderDebugName, PFN_GFSDK_Aftermath_SetData setShaderBinary, void *pUserData)
Shader source debug info lookup callback.
static void ShaderDebugInfoLookupCallback(const GFSDK_Aftermath_ShaderDebugInfoIdentifier *pIdentifier, PFN_GFSDK_Aftermath_SetData setShaderDebugInfo, void *pUserData)
Shader debug information lookup callback.
static void ShaderLookupCallback(const GFSDK_Aftermath_ShaderBinaryHash *pShaderHash, PFN_GFSDK_Aftermath_SetData setShaderBinary, void *pUserData)
Shader lookup callback.
constexpr int count
Calculate count that meets requirement.
Definition TypeList.h:289
std::string to_string(GFSDK_Aftermath_Result result)
Convert GFSDK_Aftermath_Result to string.

Referenced by OnCrashDump().