Mesa (master): util/vma: Add a debug print helper

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu May 14 00:07:41 UTC 2020


Module: Mesa
Branch: master
Commit: 38e68db778439c34ebb876273fcf9139764abc80
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=38e68db778439c34ebb876273fcf9139764abc80

Author: Jason Ekstrand <jason at jlekstrand.net>
Date:   Thu Sep 12 18:42:21 2019 -0500

util/vma: Add a debug print helper

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
Reviewed-by: Eric Anholt <eric at anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5019>

---

 src/util/vma.c | 20 ++++++++++++++++++++
 src/util/vma.h |  4 ++++
 2 files changed, 24 insertions(+)

diff --git a/src/util/vma.c b/src/util/vma.c
index f17ec0c08f1..dddc3fe187c 100644
--- a/src/util/vma.c
+++ b/src/util/vma.c
@@ -22,6 +22,7 @@
  */
 
 #include <stdlib.h>
+#include <inttypes.h>
 
 #include "util/u_math.h"
 #include "util/vma.h"
@@ -304,3 +305,22 @@ util_vma_heap_free(struct util_vma_heap *heap,
 
    util_vma_heap_validate(heap);
 }
+
+void
+util_vma_heap_print(struct util_vma_heap *heap, FILE *fp,
+                    const char *tab, uint64_t total_size)
+{
+   fprintf(fp, "%sutil_vma_heap:\n", tab);
+
+   uint64_t total_free = 0;
+   util_vma_foreach_hole(hole, heap) {
+      fprintf(fp, "%s    hole: offset = %"PRIu64" (0x%"PRIx64", "
+              "size = %"PRIu64" (0x%"PRIx64")\n",
+              tab, hole->offset, hole->offset, hole->size, hole->size);
+      total_free += hole->size;
+   }
+   assert(total_free <= total_size);
+   fprintf(fp, "%s%"PRIu64"B (0x%"PRIx64") free (%.2f%% full)\n",
+           tab, total_free, total_free,
+           ((double)(total_size - total_free) / (double)total_size) * 100);
+}
diff --git a/src/util/vma.h b/src/util/vma.h
index 58b4f8bf941..9bc058a2c58 100644
--- a/src/util/vma.h
+++ b/src/util/vma.h
@@ -25,6 +25,7 @@
 #define _UTIL_VMA_H
 
 #include <stdint.h>
+#include <stdio.h>
 
 #include "list.h"
 
@@ -55,6 +56,9 @@ bool util_vma_heap_alloc_addr(struct util_vma_heap *heap,
 void util_vma_heap_free(struct util_vma_heap *heap,
                         uint64_t offset, uint64_t size);
 
+void util_vma_heap_print(struct util_vma_heap *heap, FILE *fp,
+                         const char *tab, uint64_t total_size);
+
 #ifdef __cplusplus
 } /* extern C */
 #endif



More information about the mesa-commit mailing list