radv: Allow triggering thread traces by file.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 1 Sep 2020 12:59:55 +0000 (14:59 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 1 Sep 2020 14:19:51 +0000 (14:19 +0000)
Makes it actually feasible to trace games and not just demos/apitraces.

Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6537>

src/amd/vulkan/layers/radv_sqtt_layer.c
src/amd/vulkan/radv_device.c
src/amd/vulkan/radv_private.h

index 04909b202240f47b6bf74b200b22bba91cfea1c4..af4264b4b550eea9f13893039e4aa2fbbd92e4d6 100644 (file)
@@ -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;
index e2a5727f934c2c8621622343a69a71058aa71b14..a64c90e2308abea050e3364527e0bfcc64c30fa5 100644 (file)
@@ -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);
index 579b16de680495d584ec43145ad3ef09307cdc44..bb58fa700feade9ccac1c6352f46e807fa31d1ec 100644 (file)
@@ -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;