[Spice-devel,17/19] qxl_surface: add DEBUG_SURFACE_LIFECYCLE helpers

Submitted by Alon Levy on May 31, 2012, 10:24 a.m.

Details

Message ID 1338459893-1980-18-git-send-email-alevy@redhat.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Alon Levy May 31, 2012, 10:24 a.m.
---
 src/qxl_surface.c |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

Patch hide | download patch | download mbox

diff --git a/src/qxl_surface.c b/src/qxl_surface.c
index fd62576..669a022 100644
--- a/src/qxl_surface.c
+++ b/src/qxl_surface.c
@@ -49,6 +49,12 @@ 
 
 #include "qxl.h"
 
+#ifdef DEBUG_SURFACE_LIFECYCLE
+#include <stdio.h>
+
+static FILE* surface_log;
+#endif
+
 typedef struct evacuated_surface_t evacuated_surface_t;
 
 struct qxl_surface_t
@@ -122,6 +128,44 @@  struct surface_cache_t
     qxl_surface_t *cached_surfaces[N_CACHED_SURFACES];
 };
 
+#ifdef DEBUG_SURFACE_LIFECYCLE
+static void debug_surface_open(void)
+{
+    if (surface_log) {
+        return;
+    }
+    surface_log = fopen("/tmp/xf86-video-qxl.surface.log", "w+");
+    if (!surface_log) {
+        fprintf(stderr, "error creating surface log file (DEBUG_SURFACE_LIFECYCLE)\n");
+        exit(-1);
+    }
+}
+
+static int surface_count(qxl_surface_t *surface)
+{
+    int i;
+
+    for (i = 0; surface ;++i, surface = surface->next);
+    return i;
+}
+
+static void debug_surface_log(surface_cache_t *cache)
+{
+    int  live_n, free_n;
+
+    debug_surface_open();
+    live_n = surface_count(cache->live_surfaces);
+    free_n = surface_count(cache->free_surfaces);
+    fprintf(surface_log, "live,free,sum = %d, %d, %d\n", live_n, free_n,
+            live_n + free_n);
+    fflush(surface_log);
+}
+
+#else
+#define debug_surface_log(cache)
+#endif
+
+
 static Bool
 surface_cache_init (surface_cache_t *cache, qxl_screen_t *qxl)
 {
@@ -691,6 +735,8 @@  unlink_surface (qxl_surface_t *surface)
 	surface->prev->next = surface->next;
     else
 	surface->cache->live_surfaces = surface->next;
+
+    debug_surface_log(surface->cache);
     
     if (surface->next)
 	surface->next->prev = surface->prev;