diff --git a/include/ircd/allocator.h b/include/ircd/allocator.h index 9a434b74f..ea8cb54ee 100644 --- a/include/ircd/allocator.h +++ b/include/ircd/allocator.h @@ -26,6 +26,7 @@ namespace ircd::allocator template struct node; bool trim(const size_t &pad = 0); // malloc_trim(3) + string_view info(const mutable_buffer &); }; /// Profiling counters. diff --git a/ircd/allocator.cc b/ircd/allocator.cc index 380bc638b..195538245 100644 --- a/ircd/allocator.cc +++ b/ircd/allocator.cc @@ -18,6 +18,40 @@ // // #define RB_PROF_ALLOC +#if defined(__GNU_LIBRARY__) && defined(HAVE_MALLOC_H) +ircd::string_view +ircd::allocator::info(const mutable_buffer &buf) +{ + std::stringstream out; + pubsetbuf(out, buf); + + const auto ma + { + ::mallinfo() + }; + + out << "arena: " << ma.arena << std::endl + << "ordblks: " << ma.ordblks << std::endl + << "smblks: " << ma.smblks << std::endl + << "hblks: " << ma.hblks << std::endl + << "hblkhd: " << ma.hblkhd << std::endl + << "usmblks: " << ma.usmblks << std::endl + << "fsmblks: " << ma.fsmblks << std::endl + << "uordblks: " << ma.uordblks << std::endl + << "fordblks: " << ma.fordblks << std::endl + << "keepcost: " << ma.keepcost << std::endl + ; + + return view(out, buf); +} +#else +ircd::string_view +ircd::allocator::info(const mutable_buffer &buf) +{ + return {}; +} +#endif + #if defined(__GNU_LIBRARY__) && defined(HAVE_MALLOC_H) bool ircd::allocator::trim(const size_t &pad) diff --git a/modules/console.cc b/modules/console.cc index 2cced7d72..09251830a 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -535,6 +535,11 @@ console_cmd__mem(opt &out, const string_view &line) << "freed count ____ " << this_thread.free_count << std::endl << "alloc bytes ____ " << this_thread.alloc_bytes << std::endl << "freed bytes ____ " << this_thread.free_bytes << std::endl + << std::endl; + + thread_local char buf[1024]; + out << "malloc() information:" << std::endl + << allocator::info(buf) << std::endl ; return true;