Skip to content

Commit

Permalink
vkd3d: Flush debug log after sensitive crashes.
Browse files Browse the repository at this point in the history
We really need to make sure we get everything in the log.
The important information might be hidden in the buffer. Especially
relevant for indirect trace debug where we need buffered logs to keep
FPS above fractional values.

Signed-off-by: Hans-Kristian Arntzen <[email protected]>
  • Loading branch information
HansKristian-Work committed Jul 13, 2023
1 parent d13a334 commit b542c17
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 5 deletions.
1 change: 1 addition & 0 deletions include/private/vkd3d_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ enum vkd3d_dbg_level vkd3d_dbg_get_level(enum vkd3d_dbg_channel channel);

void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level, const char *function,
const char *fmt, ...) VKD3D_PRINTF_FUNC(4, 5);
void vkd3d_dbg_flush(void);

const char *vkd3d_dbg_sprintf(const char *fmt, ...) VKD3D_PRINTF_FUNC(1, 2);
const char *vkd3d_dbg_vsprintf(const char *fmt, va_list args);
Expand Down
36 changes: 31 additions & 5 deletions libs/vkd3d-common/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,35 @@ enum vkd3d_dbg_level vkd3d_dbg_get_level(enum vkd3d_dbg_channel channel)
return vkd3d_dbg_level[channel];
}

static spinlock_t vkd3d_debug_buffer_spin;

void vkd3d_dbg_flush(void)
{
if (vkd3d_dbg_buffer.buffer)
{
spinlock_acquire(&vkd3d_debug_buffer_spin);
if (vkd3d_dbg_buffer.offset)
{
if (vkd3d_log_file)
{
fwrite(vkd3d_dbg_buffer.buffer, 1, vkd3d_dbg_buffer.offset, vkd3d_log_file);
}
else
{
/* Binary vs text matters on Win32.
* Don't bother trying to be clever here reopening stdio files as O_BINARY, etc. */
fputs(vkd3d_dbg_buffer.buffer, stderr);
}

vkd3d_dbg_buffer.offset = 0;
fflush(vkd3d_log_file ? vkd3d_log_file : stderr);
}
spinlock_release(&vkd3d_debug_buffer_spin);
}
}

void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level, const char *function, const char *fmt, ...)
{
static spinlock_t spin;
unsigned int tid;
FILE *log_file;
va_list args;
Expand All @@ -175,7 +201,7 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level
local_buffer_count = vsnprintf(local_buffer, sizeof(local_buffer), fmt, args);
required_count = prefix_buffer_count + local_buffer_count;

spinlock_acquire(&spin);
spinlock_acquire(&vkd3d_debug_buffer_spin);
if (vkd3d_dbg_buffer.offset + required_count > vkd3d_dbg_buffer.size)
{
if (vkd3d_log_file)
Expand Down Expand Up @@ -206,7 +232,7 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level
fputs(prefix_buffer, log_file);
fputs(local_buffer, log_file);
}
spinlock_release(&spin);
spinlock_release(&vkd3d_debug_buffer_spin);
}
#ifdef _WIN32
else if (wine_log_output)
Expand All @@ -228,10 +254,10 @@ void vkd3d_dbg_printf(enum vkd3d_dbg_channel channel, enum vkd3d_dbg_level level
#endif
else
{
spinlock_acquire(&spin);
spinlock_acquire(&vkd3d_debug_buffer_spin);
fprintf(log_file, "%04x:%s:%s: ", tid, debug_level_names[level], function);
vfprintf(log_file, fmt, args);
spinlock_release(&spin);
spinlock_release(&vkd3d_debug_buffer_spin);
fflush(log_file);
}
va_end(args);
Expand Down
1 change: 1 addition & 0 deletions libs/vkd3d/breadcrumbs.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,7 @@ void vkd3d_breadcrumb_tracer_report_device_lost(struct vkd3d_breadcrumb_tracer *
}

ERR("Done analyzing breadcrumbs ...\n");
vkd3d_dbg_flush();
pthread_mutex_unlock(&global_report_lock);
}

Expand Down
1 change: 1 addition & 0 deletions libs/vkd3d/debug_ring.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,7 @@ void *vkd3d_shader_debug_ring_thread_main(void *arg)
}
}
INFO("Done fishing for clues ...\n");
vkd3d_dbg_flush();
}

return NULL;
Expand Down

0 comments on commit b542c17

Please sign in to comment.