Skip to content

Commit

Permalink
ircd::allocator: Add argument for options string to info() interface.
Browse files Browse the repository at this point in the history
  • Loading branch information
jevolk committed May 22, 2020
1 parent f069cdf commit c7b4734
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion include/ircd/allocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace ircd::allocator
profile operator+(const profile &, const profile &);
profile operator-(const profile &, const profile &);

string_view info(const mutable_buffer &);
string_view info(const mutable_buffer &, const string_view &opts = {});
string_view get(const string_view &var, const mutable_buffer &val);
string_view set(const string_view &var, const string_view &val, const mutable_buffer &cur = {});
bool trim(const size_t &pad = 0) noexcept; // malloc_trim(3)
Expand Down
3 changes: 2 additions & 1 deletion ircd/allocator_gnu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ namespace ircd::allocator
#ifdef IRCD_ALLOCATOR_USE_GNU
ircd::string_view
ircd::allocator::info(const mutable_buffer &buf)
ircd::allocator::info(const mutable_buffer &buf,
[[unused]] const string_view &opts)
{
std::stringstream out;
pubsetbuf(out, buf);
Expand Down
10 changes: 7 additions & 3 deletions ircd/allocator_je.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,8 @@ catch(const std::bad_function_call &)

#if defined(IRCD_ALLOCATOR_JEMALLOC)
ircd::string_view
ircd::allocator::info(const mutable_buffer &buf)
ircd::allocator::info(const mutable_buffer &buf,
const string_view &opts_)
{
std::stringstream out;
pubsetbuf(out, buf);
Expand All @@ -136,9 +137,12 @@ ircd::allocator::info(const mutable_buffer &buf)
out << msg;
};

static const char *const &opts
thread_local char opts_buf[64];
const char *const opts
{
""
opts_?
data(strlcpy(opts_buf, opts_)):
""
};

malloc_stats_print(je::stats_handler, &out, opts);
Expand Down
14 changes: 13 additions & 1 deletion modules/console.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1028,6 +1028,18 @@ console_cmd__proc__smaps(opt &out, const string_view &line)
bool
console_cmd__mem(opt &out, const string_view &line)
{
const params param{line, " ",
{
"opts"
}};

// Optional options string passed to implementation; might not be available
// or ignored. See jemalloc(3) etc.
const string_view &opts
{
param["opts"]
};

auto &this_thread
{
ircd::allocator::profile::this_thread
Expand All @@ -1043,7 +1055,7 @@ console_cmd__mem(opt &out, const string_view &line)

thread_local char buf[48_KiB];
out << "Allocator information:" << std::endl
<< allocator::info(buf) << std::endl
<< allocator::info(buf, opts) << std::endl
;

return true;
Expand Down

0 comments on commit c7b4734

Please sign in to comment.