pan/decode: Rotate trace files
[mesa.git] / src / panfrost / pandecode / common.c
index 1c293a4f22b2e24781060ed62b7dc633ea65887e..f4db65126b47dfafce6626744e659b7d54c13044 100644 (file)
@@ -116,20 +116,28 @@ pointer_as_memory_reference(uint64_t ptr)
 
 }
 
+static int pandecode_dump_frame_count = 0;
+
 static void
 pandecode_dump_file_open(void)
 {
         if (pandecode_dump_stream)
                 return;
 
-        const char *dump_file = debug_get_option("PANDECODE_DUMP_FILE", "pandecode.dump");
+        char buffer[1024];
+
+        /* This does a getenv every frame, so it is possible to use
+         * setenv to change the base at runtime.
+         */
+        const char *dump_file_base = debug_get_option("PANDECODE_DUMP_FILE", "pandecode.dump");
+        snprintf(buffer, sizeof(buffer), "%s.%04d", dump_file_base, pandecode_dump_frame_count);
 
-        printf("pandecode: dump command stream to file %s\n", dump_file);
-        pandecode_dump_stream = fopen(dump_file, "w");
+        printf("pandecode: dump command stream to file %s\n", buffer);
+        pandecode_dump_stream = fopen(buffer, "w");
 
         if (!pandecode_dump_stream)
                 fprintf(stderr,"pandecode: failed to open command stream log file %s\n",
-                        dump_file);
+                        buffer);
 }
 
 static void
@@ -148,6 +156,14 @@ pandecode_initialize(void)
         pandecode_dump_file_open();
 }
 
+void
+pandecode_next_frame(void)
+{
+        pandecode_dump_file_close();
+        pandecode_dump_frame_count++;
+        pandecode_dump_file_open();
+}
+
 void
 pandecode_close(void)
 {