Print compositor execution statistics when in background mode
authorSergey Sharybin <sergey.vfx@gmail.com>
Tue, 12 Mar 2013 14:28:52 +0000 (14:28 +0000)
committerSergey Sharybin <sergey.vfx@gmail.com>
Tue, 12 Mar 2013 14:28:52 +0000 (14:28 +0000)
This will print memory usage, mapped memory usage, memory peak,
compositing tree name and number of finished tiles to stdout
when blender is rendering in background mode.

This makes compositor a less blackbox and should help trouble
shooting issues happening during 4K ToS project.

source/blender/compositor/intern/COM_ExecutionGroup.cpp
source/blender/compositor/intern/COM_ExecutionGroup.h

index 6d01e2f..7d34db1 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "MEM_guardedalloc.h"
 #include "BLI_math.h"
+#include "BKE_global.h"
 #include "PIL_time.h"
 #include "WM_api.h"
 #include "WM_types.h"
@@ -410,6 +411,29 @@ MemoryBuffer *ExecutionGroup::constructConsolidatedMemoryBuffer(MemoryProxy *mem
        return result;
 }
 
+void ExecutionGroup::printBackgroundStats(void)
+{
+       uintptr_t mem_in_use, mmap_in_use, peak_memory;
+       float megs_used_memory, mmap_used_memory, megs_peak_memory;
+
+       mem_in_use = MEM_get_memory_in_use();
+       mmap_in_use = MEM_get_mapped_memory_in_use();
+       peak_memory = MEM_get_peak_memory();
+
+       megs_used_memory = (mem_in_use - mmap_in_use) / (1024.0 * 1024.0);
+       mmap_used_memory = (mmap_in_use) / (1024.0 * 1024.0);
+       megs_peak_memory = (peak_memory) / (1024.0 * 1024.0);
+
+       fprintf(stdout, "Mem:%.2fM (%.2fM, Peak %.2fM) ",
+               megs_used_memory, mmap_used_memory, megs_peak_memory);
+
+       printf("| Tree %s, Tile %d-%d ", this->m_bTree->id.name + 2,
+              this->m_chunksFinished, this->m_numberOfChunks);
+
+       fputc('\n', stdout);
+       fflush(stdout);
+}
+
 void ExecutionGroup::finalizeChunkExecution(int chunkNumber, MemoryBuffer **memoryBuffers)
 {
        if (this->m_chunkExecutionStates[chunkNumber] == COM_ES_SCHEDULED)
@@ -433,6 +457,9 @@ void ExecutionGroup::finalizeChunkExecution(int chunkNumber, MemoryBuffer **memo
                float progress = this->m_chunksFinished;
                progress /= this->m_numberOfChunks;
                this->m_bTree->progress(this->m_bTree->prh, progress);
+
+               if (G.background)
+                       printBackgroundStats();
        }
 }
 
index 52f5bae..b595261 100644 (file)
@@ -341,6 +341,11 @@ public:
         * @see determineChunkRect
         */
        MemoryBuffer *allocateOutputBuffer(int chunkNumber, rcti *rect);
+
+       /**
+        * @brief print execution statistics to stdout when running in a background mode
+        */
+       void printBackgroundStats(void);
        
        /**
         * @brief after a chunk is executed the needed resources can be freed or unlocked.