From: Bas Nieuwenhuizen Date: Tue, 1 Sep 2020 12:59:55 +0000 (+0200) Subject: radv: Allow triggering thread traces by file. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=00973542ffe93224949ca9654757f8b0581e2ef9;p=mesa.git radv: Allow triggering thread traces by file. Makes it actually feasible to trace games and not just demos/apitraces. Reviewed-by: Samuel Pitoiset Part-of: --- diff --git a/src/amd/vulkan/layers/radv_sqtt_layer.c b/src/amd/vulkan/layers/radv_sqtt_layer.c index 04909b20224..af4264b4b55 100644 --- a/src/amd/vulkan/layers/radv_sqtt_layer.c +++ b/src/amd/vulkan/layers/radv_sqtt_layer.c @@ -591,7 +591,20 @@ radv_handle_thread_trace(VkQueue _queue) if (radv_get_thread_trace(queue, &thread_trace)) radv_dump_thread_trace(queue->device, &thread_trace); } else { - if (num_frames == queue->device->thread_trace_start_frame) { + bool frame_trigger = num_frames == queue->device->thread_trace_start_frame; + bool file_trigger = false; + if (queue->device->thread_trace_trigger_file && + access(queue->device->thread_trace_trigger_file, W_OK) == 0) { + if (unlink(queue->device->thread_trace_trigger_file) == 0) { + file_trigger = true; + } else { + /* Do not enable tracing if we cannot remove the file, + * because by then we'll trace every frame ... */ + fprintf(stderr, "RADV: could not remove thread trace trigger file, ignoring\n"); + } + } + + if (frame_trigger || file_trigger) { radv_begin_thread_trace(queue); assert(!thread_trace_enabled); thread_trace_enabled = true; diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index e2a5727f934..a64c90e2308 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -2488,7 +2488,8 @@ radv_get_int_debug_option(const char *name, int default_value) static bool radv_thread_trace_enabled() { - return radv_get_int_debug_option("RADV_THREAD_TRACE", -1) >= 0; + return radv_get_int_debug_option("RADV_THREAD_TRACE", -1) >= 0 || + getenv("RADV_THREAD_TRACE_TRIGGER"); } static void @@ -2822,6 +2823,10 @@ VkResult radv_CreateDevice( radv_get_int_debug_option("RADV_THREAD_TRACE_BUFFER_SIZE", 1024 * 1024); device->thread_trace_start_frame = radv_get_int_debug_option("RADV_THREAD_TRACE", -1); + const char *trigger_file = getenv("RADV_THREAD_TRACE_TRIGGER"); + if (trigger_file) + device->thread_trace_trigger_file = strdup(trigger_file); + if (!radv_thread_trace_init(device)) goto fail; } @@ -2918,6 +2923,7 @@ fail: radv_bo_list_finish(&device->bo_list); radv_thread_trace_finish(device); + free(device->thread_trace_trigger_file); radv_trap_handler_finish(device); @@ -2977,6 +2983,7 @@ void radv_DestroyDevice( pthread_cond_destroy(&device->timeline_cond); radv_bo_list_finish(&device->bo_list); + free(device->thread_trace_trigger_file); radv_thread_trace_finish(device); vk_free(&device->vk.alloc, device); diff --git a/src/amd/vulkan/radv_private.h b/src/amd/vulkan/radv_private.h index 579b16de680..bb58fa700fe 100644 --- a/src/amd/vulkan/radv_private.h +++ b/src/amd/vulkan/radv_private.h @@ -846,6 +846,7 @@ struct radv_device { void *thread_trace_ptr; uint32_t thread_trace_buffer_size; int thread_trace_start_frame; + char *thread_trace_trigger_file; /* Trap handler. */ struct radv_shader_variant *trap_handler_shader;