Cycles: Add human readable sizes to debug output

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
This commit is contained in:
Mai Lavelle 2016-05-29 18:02:05 -04:00
parent a2aa44370b
commit 4388b29e98
9 changed files with 70 additions and 10 deletions

View 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()

View 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,

View 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 */

View 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;

View 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);

View 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());

View 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) << ")";
}
}

View 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

View 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__ */