From c7b473485b31ec8ce8f9c608652c88cfc21ec726 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 22 May 2020 15:10:54 -0700 Subject: [PATCH] ircd::allocator: Add argument for options string to info() interface. --- include/ircd/allocator.h | 2 +- ircd/allocator_gnu.cc | 3 ++- ircd/allocator_je.cc | 10 +++++++--- modules/console.cc | 14 +++++++++++++- 4 files changed, 23 insertions(+), 6 deletions(-) diff --git a/include/ircd/allocator.h b/include/ircd/allocator.h index 82b16fabb..46f875961 100644 --- a/include/ircd/allocator.h +++ b/include/ircd/allocator.h @@ -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) diff --git a/ircd/allocator_gnu.cc b/ircd/allocator_gnu.cc index e34248787..79ab0170b 100644 --- a/ircd/allocator_gnu.cc +++ b/ircd/allocator_gnu.cc @@ -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); diff --git a/ircd/allocator_je.cc b/ircd/allocator_je.cc index 79538573d..2e2436b14 100644 --- a/ircd/allocator_je.cc +++ b/ircd/allocator_je.cc @@ -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); @@ -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); diff --git a/modules/console.cc b/modules/console.cc index 92802aa16..eaac44378 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -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 @@ -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;