sna: Refactor common routines for debugfs file dumping
authorChris Wilson <chris@chris-wilson.co.uk>
Sat, 18 Jan 2014 22:38:40 +0000 (22:38 +0000)
committerChris Wilson <chris@chris-wilson.co.uk>
Sat, 18 Jan 2014 22:38:40 +0000 (22:38 +0000)
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
src/sna/kgem.c

index 32c1023..0aee958 100644 (file)
@@ -2871,51 +2871,46 @@ out_16384:
 }
 
 #if !NDEBUG
-static void dump_gtt_info(void)
+static bool dump_file(const char *path)
 {
-       int i;
+       FILE *file;
+       size_t len = 0;
+       char *line = NULL;
 
-       for (i = 0; i < DRM_MAX_MINOR; i++) {
-               char path[80];
-               FILE *file;
-
-               sprintf(path, "/sys/kernel/debug/dri/%d/i915_gem_gtt", i);
-               file = fopen(path, "r");
-               if (file) {
-                       size_t len = 0;
-                       char *line = NULL;
-
-                       while (getline(&line, &len, file) != -1)
-                               ErrorF("%s", line);
-                       free(line);
-                       fclose(file);
-                       return;
-               }
-       }
+       file = fopen(path, "r");
+       if (file == NULL)
+               return false;
+
+       while (getline(&line, &len, file) != -1)
+               ErrorF("%s", line);
+
+       free(line);
+       fclose(file);
+       return true;
 }
 
-static void dump_fence_regs(void)
+static void dump_debugfs(const char *name)
 {
        int i;
 
        for (i = 0; i < DRM_MAX_MINOR; i++) {
                char path[80];
-               FILE *file;
-
-               sprintf(path, "/sys/kernel/debug/dri/%d/i915_gem_fence_regs", i);
-               file = fopen(path, "r");
-               if (file) {
-                       size_t len = 0;
-                       char *line = NULL;
-
-                       while (getline(&line, &len, file) != -1)
-                               ErrorF("%s", line);
-                       free(line);
-                       fclose(file);
+
+               sprintf(path, "/sys/kernel/debug/dri/%d/%s", i, name);
+               if (dump_file(path))
                        return;
-               }
        }
 }
+
+static void dump_gtt_info(void)
+{
+       dump_debugfs("i915_gem_gtt");
+}
+
+static void dump_fence_regs(void)
+{
+       dump_debugfs("i915_gem_fence_regs");
+}
 #endif
 
 void _kgem_submit(struct kgem *kgem)