mirror of
https://github.com/matrix-construct/construct
synced 2024-09-27 11:18:51 +02:00
ircd::allocator: Add mallinfo to string support w/ console command.
This commit is contained in:
parent
feb1aa5d2f
commit
acddfa77f8
3 changed files with 40 additions and 0 deletions
|
@ -26,6 +26,7 @@ namespace ircd::allocator
|
|||
template<class T> struct node;
|
||||
|
||||
bool trim(const size_t &pad = 0); // malloc_trim(3)
|
||||
string_view info(const mutable_buffer &);
|
||||
};
|
||||
|
||||
/// Profiling counters.
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue