26 #include <google/malloc_extension.h>
28 #include <graphlab/logger/assertions.hpp>
31 namespace memory_info {
46 MallocExtension::instance()->
47 GetNumericProperty(
"generic.heap_size", &heap_size);
50 "memory_info::heap_bytes() requires tcmalloc" << std::endl;
57 size_t allocated_bytes() {
58 size_t allocated_size(0);
60 MallocExtension::instance()->
61 GetNumericProperty(
"generic.current_allocated_bytes",
65 "memory_info::allocated_bytes() requires tcmalloc" << std::endl;
67 return allocated_size;
72 void print_usage(
const std::string& label) {
74 const double BYTES_TO_MB = double(1) / double(1024 * 1024);
76 <<
"Memory Info: " << label << std::endl
77 <<
"\t Heap: " << (heap_bytes() * BYTES_TO_MB) <<
" MB"
79 <<
"\t Allocated: " << (allocated_bytes() * BYTES_TO_MB) <<
" MB"
83 <<
"Unable to print memory info for: " << label <<
". "
84 <<
"No memory extensions api available." << std::endl;
88 void log_usage(
const std::string& label) {
90 const double BYTES_TO_MB = double(1) / double(1024 * 1024);
92 <<
"Memory Info: " << label
93 <<
"\n\t Heap: " << (heap_bytes() * BYTES_TO_MB) <<
" MB"
94 <<
"\n\t Allocated: " << (allocated_bytes() * BYTES_TO_MB) <<
" MB"
98 <<
"Unable to print memory info for: " << label <<
". "
99 <<
"No memory extensions api available." << std::endl;