Cycles: Add human readable sizes to debug output
authorMai Lavelle <mai.lavelle@gmail.com>
Sun, 29 May 2016 22:02:05 +0000 (18:02 -0400)
committerMai Lavelle <mai.lavelle@gmail.com>
Tue, 31 May 2016 10:13:54 +0000 (06:13 -0400)
Some of these values can get quite large and are hard to read, adding this
makes it easy to read them at a glance.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D2039

intern/cycles/bvh/bvh_build.cpp
intern/cycles/device/device_cpu.cpp
intern/cycles/device/device_cuda.cpp
intern/cycles/device/device_multi.cpp
intern/cycles/device/device_network.cpp
intern/cycles/device/device_opencl.cpp
intern/cycles/render/scene.cpp
intern/cycles/util/util_string.cpp
intern/cycles/util/util_string.h

index 8dbd5abc1839c93e39cb454d3eb87c55b837d76b..87a889955fe0ac9000b5a39eaf52a1b16a5deef7 100644 (file)
@@ -328,11 +328,11 @@ BVHNode* BVHBuild::run()
                        VLOG(1) << "BVH build statistics:\n"
                                << "  Build time: " << time_dt() - build_start_time << "\n"
                                << "  Total number of nodes: "
-                               << rootnode->getSubtreeSize(BVH_STAT_NODE_COUNT) << "\n"
+                               << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_NODE_COUNT)) << "\n"
                                << "  Number of inner nodes: "
-                               << rootnode->getSubtreeSize(BVH_STAT_INNER_COUNT)  << "\n"
+                               << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_INNER_COUNT)) << "\n"
                                << "  Number of leaf nodes: "
-                               << rootnode->getSubtreeSize(BVH_STAT_LEAF_COUNT)  << "\n"
+                               << string_human_readable_number(rootnode->getSubtreeSize(BVH_STAT_LEAF_COUNT)) << "\n"
                                << "  Allocation slop factor: "
                                       << ((prim_type.capacity() != 0)
                                               ? (float)prim_type.size() / prim_type.capacity()
index 275ee028eb4bd087240cd893b643b73e816486b7..aed86d8d85377c2825484188099689aa0b4c88cf 100644 (file)
@@ -155,7 +155,9 @@ public:
                       InterpolationType interpolation,
                       ExtensionType extension)
        {
-               VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
+               VLOG(1) << "Texture allocate: " << name << ", "
+                       << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                       << string_human_readable_size(mem.memory_size()) << ")";
                kernel_tex_copy(&kernel_globals,
                                name,
                                mem.data_pointer,
index 9a78d05558079073da4e59e1cbe42341e569e359..d7ed7b4f853475edd2f0ae6844242c2316650909 100644 (file)
@@ -493,7 +493,9 @@ public:
                       InterpolationType interpolation,
                       ExtensionType extension)
        {
-               VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
+               VLOG(1) << "Texture allocate: " << name << ", "
+                       << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                       << string_human_readable_size(mem.memory_size()) << ")";
 
                /* Check if we are on sm_30 or above.
                 * We use arrays and bindles textures for storage there */
index 434d0085d39333377d0c1ec94769794c783a1e90..c4f8d9e16e0f526fd3a69aef3688ffba0e867043 100644 (file)
@@ -175,7 +175,9 @@ public:
                       interpolation,
                       ExtensionType extension)
        {
-               VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
+               VLOG(1) << "Texture allocate: " << name << ", "
+                       << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                       << string_human_readable_size(mem.memory_size()) << ")";
 
                foreach(SubDevice& sub, devices) {
                        mem.device_pointer = 0;
index cf4a05de8fc35f321b33fda81549432a202f3fe4..3eb5ad2d2dbb63f8aa7ea9439b4c14681d601f41 100644 (file)
@@ -168,7 +168,9 @@ public:
                       InterpolationType interpolation,
                       ExtensionType extension)
        {
-               VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
+               VLOG(1) << "Texture allocate: " << name << ", "
+                       << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                       << string_human_readable_size(mem.memory_size()) << ")";
 
                thread_scoped_lock lock(rpc_lock);
 
index 1b4e5421b5ae7d0f9fc808c9628a2ff8f4fec5d8..c7dcf7602dfd7cc37c0d66644491112788c010e3 100644 (file)
@@ -1187,7 +1187,9 @@ public:
                       InterpolationType /*interpolation*/,
                       ExtensionType /*extension*/)
        {
-               VLOG(1) << "Texture allocate: " << name << ", " << mem.memory_size() << " bytes.";
+               VLOG(1) << "Texture allocate: " << name << ", "
+                       << string_human_readable_number(mem.memory_size()) << " bytes. ("
+                       << string_human_readable_size(mem.memory_size()) << ")";
                mem_alloc(mem, MEM_READ_ONLY);
                mem_copy_to(mem);
                assert(mem_map.find(name) == mem_map.end());
index b0052c30af416fbee958a38964c960da7c37d816..e8367e1eb3628d59077eeeb08b35589632bb9269 100644 (file)
@@ -242,9 +242,14 @@ void Scene::device_update(Device *device_, Progress& progress)
        }
 
        if(print_stats) {
+               size_t mem_used = util_guarded_get_mem_used();
+               size_t mem_peak = util_guarded_get_mem_peak();
+
                VLOG(1) << "System memory statistics after full device sync:\n"
-                       << "  Usage: " << util_guarded_get_mem_used() << "\n"
-                       << "  Peak: " << util_guarded_get_mem_peak();
+                       << "  Usage: " << string_human_readable_number(mem_used)
+                       << " (" << string_human_readable_size(mem_used) << ")\n"
+                       << "  Peak: " << string_human_readable_number(mem_peak)
+                       << " (" << string_human_readable_size(mem_peak) << ")";
        }
 }
 
index b3a8c6d7c2eb3ac65e927b410c8dc3b58492f6d9..e16a83d56d0cd5a58bc043807786a2dd3ae4a59b 100644 (file)
@@ -239,5 +239,45 @@ string string_to_ansi(const string& str)
 
 #endif  /* _WIN32 */
 
+string string_human_readable_size(size_t size)
+{
+       static const char suffixes[] = "BKMGTPEZY";
+
+       const char* suffix = suffixes;
+       size_t r = 0;
+
+       while(size >= 1024) {
+               r = size % 1024;
+               size /= 1024;
+               suffix++;
+       }
+
+       if(*suffix != 'B')
+               return string_printf("%.2f%c", double(size*1024+r)/1024.0, *suffix);
+       else
+               return string_printf("%zu", size);
+}
+
+string string_human_readable_number(size_t num)
+{
+       /* add thousands separators */
+       char buf[32];
+
+       char* p = buf+31;
+       *p = '\0';
+
+       int i = -1;
+       while(num) {
+               if(++i && i % 3 == 0)
+                       *(--p) = ',';
+
+               *(--p) = '0' + (num % 10);
+
+               num /= 10;
+       }
+
+       return p;
+}
+
 CCL_NAMESPACE_END
 
index c4b51bda432508bf76ea9ad30be85d770ac67798..d3b5248c3808106ed5656bb7c7bb28a1006bed93 100644 (file)
@@ -62,6 +62,11 @@ string string_from_wstring(const wstring& path);
 string string_to_ansi(const string& str);
 #endif
 
+/* Make a string from a size in bytes in human readable form */
+string string_human_readable_size(size_t size);
+/* Make a string from a unitless quantity in human readable form */
+string string_human_readable_number(size_t num);
+
 CCL_NAMESPACE_END
 
 #endif /* __UTIL_STRING_H__ */