Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/intern
diff options
context:
space:
mode:
authorBrecht Van Lommel <brechtvanlommel@pandora.be>2008-02-01 15:14:15 +0300
committerBrecht Van Lommel <brechtvanlommel@pandora.be>2008-02-01 15:14:15 +0300
commitbaf7be9e466a2f111b030b9098be71f3aba3aca7 (patch)
tree0d9f453dc09592fc42e46769432ae579808f063b /intern
parentf971304158c68638db225d17a603de71ec16a1c8 (diff)
Memory usage debugging: now with the -d debug option enabled, at the end
of rendering it prints memory usage for images and all memory blocks.
Diffstat (limited to 'intern')
-rw-r--r--intern/guardedalloc/MEM_guardedalloc.h3
-rw-r--r--intern/guardedalloc/intern/mallocn.c85
2 files changed, 88 insertions, 0 deletions
diff --git a/intern/guardedalloc/MEM_guardedalloc.h b/intern/guardedalloc/MEM_guardedalloc.h
index 94276c0454a..73eddff7d8a 100644
--- a/intern/guardedalloc/MEM_guardedalloc.h
+++ b/intern/guardedalloc/MEM_guardedalloc.h
@@ -106,6 +106,9 @@ extern "C" {
/** Print a list of the names and sizes of all allocated memory
* blocks. */
void MEM_printmemlist(void);
+
+ /** Print statistics about memory usage */
+ void MEM_printmemlist_stats(void);
/** Set the callback function for error output. */
void MEM_set_error_callback(void (*func)(char *));
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c
index 413f4d80514..c1ddfa71a10 100644
--- a/intern/guardedalloc/intern/mallocn.c
+++ b/intern/guardedalloc/intern/mallocn.c
@@ -332,6 +332,91 @@ void *MEM_mapallocN(unsigned int len, const char *str)
#endif
}
+/* Memory statistics print */
+typedef struct MemPrintBlock {
+ const char *name;
+ unsigned long len;
+ int items;
+} MemPrintBlock;
+
+static int compare_name(const void *p1, const void *p2)
+{
+ const MemPrintBlock *pb1= (const MemPrintBlock*)p1;
+ const MemPrintBlock *pb2= (const MemPrintBlock*)p2;
+
+ return strcmp(pb1->name, pb2->name);
+}
+
+static int compare_len(const void *p1, const void *p2)
+{
+ const MemPrintBlock *pb1= (const MemPrintBlock*)p1;
+ const MemPrintBlock *pb2= (const MemPrintBlock*)p2;
+
+ if(pb1->len < pb2->len)
+ return 1;
+ else if(pb1->len == pb2->len)
+ return 0;
+ else
+ return -1;
+}
+
+void MEM_printmemlist_stats()
+{
+ MemHead *membl;
+ MemPrintBlock *pb, *printblock;
+ int totpb, a, b;
+
+ mem_lock_thread();
+
+ /* put memory blocks into array */
+ printblock= malloc(sizeof(MemPrintBlock)*totblock);
+
+ pb= printblock;
+ totpb= 0;
+
+ membl = membase->first;
+ if (membl) membl = MEMNEXT(membl);
+
+ while(membl) {
+ pb->name= membl->name;
+ pb->len= membl->len;
+ pb->items= 1;
+
+ totpb++;
+ pb++;
+
+ if(membl->next)
+ membl= MEMNEXT(membl->next);
+ else break;
+ }
+
+ /* sort by name and add together blocks with the same name */
+ qsort(printblock, totpb, sizeof(MemPrintBlock), compare_name);
+ for(a=0, b=0; a<totpb; a++) {
+ if(a == b) {
+ continue;
+ }
+ else if(strcmp(printblock[a].name, printblock[b].name) == 0) {
+ printblock[b].len += printblock[a].len;
+ printblock[b].items++;
+ }
+ else {
+ b++;
+ memcpy(&printblock[b], &printblock[a], sizeof(MemPrintBlock));
+ }
+ }
+ totpb= b+1;
+
+ /* sort by length and print */
+ qsort(printblock, totpb, sizeof(MemPrintBlock), compare_len);
+ printf("\ntotal memory len: %.3f MB\n", (double)mem_in_use/(double)(1024*1024));
+ for(a=0, pb=printblock; a<totpb; a++, pb++)
+ printf("%s items: %d, len: %.3f MB\n", pb->name, pb->items, (double)pb->len/(double)(1024*1024));
+
+ free(printblock);
+
+ mem_unlock_thread();
+}
/* Prints in python syntax for easy */
static void MEM_printmemlist_internal( int pydict )