mirror of
https://github.com/matrix-construct/construct
synced 2024-06-02 10:08:56 +02:00
ircd::allocator: Add ctrl get()/set() w/ console cmd.
This commit is contained in:
parent
9129be58eb
commit
612eeb3b7f
|
@ -36,9 +36,11 @@ namespace ircd::allocator
|
|||
profile operator+(const profile &, const profile &);
|
||||
profile operator-(const profile &, const profile &);
|
||||
|
||||
bool trim(const size_t &pad = 0) noexcept; // malloc_trim(3)
|
||||
string_view info(const mutable_buffer &);
|
||||
};
|
||||
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)
|
||||
}
|
||||
|
||||
/// Valgrind memcheck hypercall suite
|
||||
/// note: definitions located in ircd/vg.cc
|
||||
|
|
|
@ -16,13 +16,6 @@
|
|||
//
|
||||
// #define RB_PROF_ALLOC
|
||||
|
||||
ircd::string_view
|
||||
__attribute__((weak))
|
||||
ircd::allocator::info(const mutable_buffer &buf)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
bool
|
||||
__attribute__((weak))
|
||||
ircd::allocator::trim(const size_t &pad)
|
||||
|
@ -31,6 +24,23 @@ noexcept
|
|||
return false;
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
__attribute__((weak))
|
||||
ircd::allocator::get(const string_view &key,
|
||||
const mutable_buffer &buf)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
ircd::string_view
|
||||
__attribute__((weak))
|
||||
ircd::allocator::set(const string_view &key,
|
||||
const string_view &val,
|
||||
const mutable_buffer &cur)
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
//
|
||||
// allocator::state
|
||||
//
|
||||
|
|
|
@ -39,6 +39,50 @@ ircd::allocator::je_malloc_version_abi
|
|||
"jemalloc", info::versions::ABI, //TODO: get this
|
||||
};
|
||||
|
||||
#if defined(IRCD_ALLOCATOR_USE_JEMALLOC) && defined(HAVE_JEMALLOC_H)
|
||||
bool
|
||||
ircd::allocator::trim(const size_t &pad)
|
||||
noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(IRCD_ALLOCATOR_USE_JEMALLOC) && defined(HAVE_JEMALLOC_H)
|
||||
ircd::string_view
|
||||
ircd::allocator::get(const string_view &key_,
|
||||
const mutable_buffer &buf)
|
||||
{
|
||||
thread_local char key[128];
|
||||
strlcpy(key, key_);
|
||||
|
||||
size_t len(size(buf));
|
||||
syscall(::mallctl, key, data(buf), &len, nullptr, 0UL);
|
||||
return string_view
|
||||
{
|
||||
data(buf), len
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(IRCD_ALLOCATOR_USE_JEMALLOC) && defined(HAVE_JEMALLOC_H)
|
||||
ircd::string_view
|
||||
ircd::allocator::set(const string_view &key_,
|
||||
const string_view &val,
|
||||
const mutable_buffer &cur)
|
||||
{
|
||||
thread_local char key[128];
|
||||
strlcpy(key, key_);
|
||||
|
||||
size_t curlen(size(cur));
|
||||
syscall(::mallctl, key, data(cur), &curlen, const_cast<char *>(data(val)), size(val));
|
||||
return string_view
|
||||
{
|
||||
data(cur), curlen
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
||||
void
|
||||
ircd::allocator::je_stats_handler(void *const ptr,
|
||||
const char *const msg)
|
||||
|
@ -81,15 +125,6 @@ ircd::allocator::info(const mutable_buffer &buf)
|
|||
}
|
||||
#endif
|
||||
|
||||
#if defined(IRCD_ALLOCATOR_USE_JEMALLOC) && defined(HAVE_JEMALLOC_H)
|
||||
bool
|
||||
ircd::allocator::trim(const size_t &pad)
|
||||
noexcept
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(IRCD_ALLOCATOR_USE_JEMALLOC) && defined(HAVE_JEMALLOC_H)
|
||||
void
|
||||
ircd::allocator::scope::hook_init()
|
||||
|
|
|
@ -943,6 +943,139 @@ console_cmd__mem__trim(opt &out, const string_view &line)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__mem__set(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"key", "type", "val"
|
||||
}};
|
||||
|
||||
const string_view &key
|
||||
{
|
||||
param.at("key")
|
||||
};
|
||||
|
||||
const string_view &type
|
||||
{
|
||||
param.at("type", "string"_sv)
|
||||
};
|
||||
|
||||
string_view set;
|
||||
thread_local char buf[2][4_KiB];
|
||||
switch(hash(type))
|
||||
{
|
||||
case "void"_:
|
||||
set = {};
|
||||
break;
|
||||
|
||||
case "bool"_:
|
||||
*reinterpret_cast<bool *>(buf[0]) = lex_cast<bool>(param.at("val"));
|
||||
set = { buf[0], sizeof(bool) };
|
||||
break;
|
||||
|
||||
case "size_t"_:
|
||||
*reinterpret_cast<size_t *>(buf[0]) = lex_cast<size_t>(param.at("val"));
|
||||
set = { buf[0], sizeof(size_t) };
|
||||
break;
|
||||
|
||||
case "ssize_t"_:
|
||||
*reinterpret_cast<ssize_t *>(buf[0]) = lex_cast<ssize_t>(param.at("val"));
|
||||
set = { buf[0], sizeof(ssize_t) };
|
||||
break;
|
||||
|
||||
case "unsigned"_:
|
||||
*reinterpret_cast<unsigned *>(buf[0]) = lex_cast<unsigned>(param.at("val"));
|
||||
set = { buf[0], sizeof(unsigned) };
|
||||
break;
|
||||
|
||||
case "uint64_t"_:
|
||||
*reinterpret_cast<uint64_t *>(buf[0]) = lex_cast<uint64_t>(param.at("val"));
|
||||
set = { buf[0], sizeof(uint64_t) };
|
||||
break;
|
||||
|
||||
case "uint64_t*"_:
|
||||
*reinterpret_cast<uintptr_t *>(buf[0]) = lex_cast<uintptr_t>(param.at("val"));
|
||||
set = { buf[0], sizeof(uintptr_t) };
|
||||
break;
|
||||
|
||||
default:
|
||||
case "string"_:
|
||||
set = param.at("val");
|
||||
break;
|
||||
}
|
||||
|
||||
const string_view &get
|
||||
{
|
||||
allocator::set(key, set, buf[1])
|
||||
};
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
console_cmd__mem__get(opt &out, const string_view &line)
|
||||
{
|
||||
const params param{line, " ",
|
||||
{
|
||||
"key", "type"
|
||||
}};
|
||||
|
||||
const string_view &key
|
||||
{
|
||||
param.at("key")
|
||||
};
|
||||
|
||||
const string_view &type
|
||||
{
|
||||
param.at("type", "string"_sv)
|
||||
};
|
||||
|
||||
thread_local char buf[4_KiB];
|
||||
const string_view &val
|
||||
{
|
||||
allocator::get(key, buf)
|
||||
};
|
||||
|
||||
switch(hash(type))
|
||||
{
|
||||
case "void"_:
|
||||
out << std::endl;
|
||||
break;
|
||||
|
||||
case "bool"_:
|
||||
out << lex_cast(*reinterpret_cast<const bool *>(data(val))) << std::endl;
|
||||
break;
|
||||
|
||||
case "size_t"_:
|
||||
out << lex_cast(*reinterpret_cast<const size_t *>(data(val))) << std::endl;
|
||||
break;
|
||||
|
||||
case "ssize_t"_:
|
||||
out << lex_cast(*reinterpret_cast<const ssize_t *>(data(val))) << std::endl;
|
||||
break;
|
||||
|
||||
case "unsigned"_:
|
||||
out << lex_cast(*reinterpret_cast<const unsigned *>(data(val))) << std::endl;
|
||||
break;
|
||||
|
||||
case "uint64_t"_:
|
||||
out << lex_cast(*reinterpret_cast<const uint64_t *>(data(val))) << std::endl;
|
||||
break;
|
||||
|
||||
case "uint64_t*"_:
|
||||
out << lex_cast(*reinterpret_cast<const uintptr_t *>(data(val))) << std::endl;
|
||||
break;
|
||||
|
||||
default:
|
||||
case "string"_:
|
||||
out << val << std::endl;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
// prof
|
||||
//
|
||||
|
|
Loading…
Reference in a new issue