diff options
author | Campbell Barton <ideasman42@gmail.com> | 2008-01-01 19:14:08 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2008-01-01 19:14:08 +0300 |
commit | 9db2035e3650ecbd1baf1943c490d6a4e140f2c3 (patch) | |
tree | 2b796bec9d7c17ea18a0efea3011436a25e2d470 /intern | |
parent | 65f1999435224c14ddbe232535dacd52b1ae465a (diff) |
while trying to debug memory leaks, extended MEM_printmemlist to print a python dict and some lines at the end to format it in a useful way when run as a python script.
Diffstat (limited to 'intern')
-rw-r--r-- | intern/guardedalloc/intern/mallocn.c | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/intern/guardedalloc/intern/mallocn.c b/intern/guardedalloc/intern/mallocn.c index 51c2a2427b5..44909bbea54 100644 --- a/intern/guardedalloc/intern/mallocn.c +++ b/intern/guardedalloc/intern/mallocn.c @@ -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(); } |