while trying to debug memory leaks, extended MEM_printmemlist to print a python dict...
authorCampbell Barton <ideasman42@gmail.com>
Tue, 1 Jan 2008 16:14:08 +0000 (16:14 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Tue, 1 Jan 2008 16:14:08 +0000 (16:14 +0000)
intern/guardedalloc/intern/mallocn.c
source/blender/src/editscreen.c

index 51c2a2427b5f9f56f8c1cd8366eb467b319dfca2..44909bbea548470c768f0c5fd95c612af7cca843 100644 (file)
@@ -333,6 +333,7 @@ void *MEM_mapallocN(unsigned int len, const char *str)
 }
 
 
+/* Prints in python syntax for easy */
 void MEM_printmemlist()
 {
        MemHead *membl;
@@ -341,13 +342,33 @@ void MEM_printmemlist()
 
        membl = membase->first;
        if (membl) membl = MEMNEXT(membl);
+       
+       print_error("# membase_debug.py\n");
+       print_error("membase = [\\\n");
        while(membl) {
-               print_error("%s len: %d %p\n",membl->name,membl->len, membl+1);
+               fprintf(stderr, "{'len':%i, 'name':'''%s''', 'pointer':'%p'},\\\n", membl->len, membl->name, membl+1);
                if(membl->next)
                        membl= MEMNEXT(membl->next);
                else break;
        }
-
+       fprintf(stderr, "]\n\n");
+       fprintf(stderr,
+"mb_userinfo = {}\n"
+"totmem = 0\n"
+"for mb_item in membase:\n"
+"\tmb_item_user_size = mb_userinfo.setdefault(mb_item['name'], [0,0])\n"
+"\tmb_item_user_size[0] += 1 # Add a user\n"
+"\tmb_item_user_size[1] += mb_item['len'] # Increment the size\n"
+"\ttotmem += mb_item['len']\n"
+"print '(membase) items:', len(membase), '| unique-names:', len(mb_userinfo), '| total-mem:', totmem\n"
+"mb_userinfo_sort = mb_userinfo.items()\n"
+"for sort_name, sort_func in (('size', lambda a: -a[1][1]), ('users', lambda a: -a[1][0]), ('name', lambda a: a[0])):\n"
+"\tprint '\\nSorting by:', sort_name\n"
+"\tmb_userinfo_sort.sort(key = sort_func)\n"
+"\tfor item in mb_userinfo_sort:\n"
+"\t\tprint 'name:%%s, users:%%i, len:%%i' %% (item[0], item[1][0], item[1][1])\n"
+       );
+       
        mem_unlock_thread();
 }
 
index 35c0692510d9d459b2f8ba5ee511a623dae1b73b..43d163bff09a5178d1bead8d9cb14759c7a847c9 100644 (file)
@@ -1397,9 +1397,14 @@ void screenmain(void)
                        towin= 0;
                }
                else if (event==QKEY) {
-                       if((G.obedit && G.obedit->type==OB_FONT && g_activearea->spacetype==SPACE_VIEW3D)||g_activearea->spacetype==SPACE_TEXT||g_activearea->spacetype==SPACE_SCRIPT);
+                       /* Temp place to print mem debugging info ctrl+alt+shift + qkey */
+                       if ( G.qual == (LR_SHIFTKEY | LR_ALTKEY | LR_CTRLKEY) ) {
+                               MEM_printmemlist();
+                       }
+                       
+                       else if((G.obedit && G.obedit->type==OB_FONT && g_activearea->spacetype==SPACE_VIEW3D)||g_activearea->spacetype==SPACE_TEXT||g_activearea->spacetype==SPACE_SCRIPT);
                        else {
-                               if(val && (G.qual & LR_CTRLKEY)) {
+                               if(val && (G.qual == LR_CTRLKEY)) {
                                        if(okee("Quit Blender")) exit_usiblender();
                                }
                                towin= 0;