diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-02-01 15:14:15 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-02-01 15:14:15 +0300 |
commit | baf7be9e466a2f111b030b9098be71f3aba3aca7 (patch) | |
tree | 0d9f453dc09592fc42e46769432ae579808f063b /source/blender/blenkernel | |
parent | f971304158c68638db225d17a603de71ec16a1c8 (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 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_image.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/image.c | 41 |
2 files changed, 44 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_image.h b/source/blender/blenkernel/BKE_image.h index ca34240cf27..a584722031b 100644 --- a/source/blender/blenkernel/BKE_image.h +++ b/source/blender/blenkernel/BKE_image.h @@ -148,6 +148,9 @@ void BKE_image_all_free_anim_ibufs(int except_frame); void BKE_image_memorypack(struct Image *ima); +/* prints memory statistics for images */ +void BKE_image_print_memlist(void); + #ifdef __cplusplus } #endif diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c index 0c45356eb0b..3b7ab4951f6 100644 --- a/source/blender/blenkernel/intern/image.c +++ b/source/blender/blenkernel/intern/image.c @@ -629,6 +629,47 @@ void free_old_images() } } +static unsigned long image_mem_size(Image *ima) +{ + ImBuf *ibuf, *ibufm; + int level; + unsigned long size = 0; + + size= 0; + for(ibuf= ima->ibufs.first; ibuf; ibuf= ibuf->next) { + if(ibuf->rect) size += MEM_allocN_len(ibuf->rect); + else if(ibuf->rect_float) size += MEM_allocN_len(ibuf->rect_float); + + for(level=0; level<IB_MIPMAP_LEVELS; level++) { + ibufm= ibuf->mipmap[level]; + if(ibufm) { + if(ibufm->rect) size += MEM_allocN_len(ibufm->rect); + else if(ibufm->rect_float) size += MEM_allocN_len(ibufm->rect_float); + } + } + } + + return size; +} + +void BKE_image_print_memlist(void) +{ + Image *ima; + unsigned long size, totsize= 0; + + for(ima= G.main->image.first; ima; ima= ima->id.next) + totsize += image_mem_size(ima); + + printf("\ntotal image memory len: %.3lf MB\n", (double)totsize/(double)(1024*1024)); + + for(ima= G.main->image.first; ima; ima= ima->id.next) { + size= image_mem_size(ima); + + if(size) + printf("%s len: %.3f MB\n", ima->id.name+2, (double)size/(double)(1024*1024)); + } +} + void BKE_image_free_all_textures(void) { Tex *tex; |