0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-02 10:08:56 +02:00

ircd::allocator: Start an allocator_je.cc unit.

This commit is contained in:
Jason Volk 2019-07-03 18:35:50 -07:00
parent 6a6c51d359
commit adda5ba170
2 changed files with 108 additions and 0 deletions

View file

@ -117,6 +117,7 @@ libircd_la_SOURCES += assert.cc
libircd_la_SOURCES += info.cc
libircd_la_SOURCES += allocator.cc
libircd_la_SOURCES += allocator_gnu.cc
libircd_la_SOURCES += allocator_je.cc
libircd_la_SOURCES += vg.cc
libircd_la_SOURCES += exception.cc
libircd_la_SOURCES += util.cc

107
ircd/allocator_je.cc Normal file
View file

@ -0,0 +1,107 @@
// Matrix Construct
//
// Copyright (C) Matrix Construct Developers, Authors & Contributors
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice is present in all copies. The
// full license for this software is available in the LICENSE file.
#include <RB_INC_JEMALLOC_H
namespace ircd::allocator
{
static std::function<void (std::ostream &, const string_view &)> je_stats_callback;
static void je_stats_handler(void *, const char *);
extern info::versions je_malloc_version_api;
extern info::versions je_malloc_version_abi;
}
decltype(ircd::allocator::je_malloc_version_api)
ircd::allocator::je_malloc_version_api
{
"jemalloc", info::versions::API, 0,
#ifdef HAVE_JEMALLOC_H
{
JEMALLOC_VERSION_MAJOR,
JEMALLOC_VERSION_MINOR,
JEMALLOC_VERSION_BUGFIX
},
JEMALLOC_VERSION
#endif
};
decltype(ircd::allocator::je_malloc_version_abi)
ircd::allocator::je_malloc_version_abi
{
"jemalloc", info::versions::ABI, //TODO: get this
};
void
ircd::allocator::je_stats_handler(void *const ptr,
const char *const msg)
try
{
auto &out
{
*reinterpret_cast<std::stringstream *>(ptr)
};
je_stats_callback(out, msg);
}
catch(const std::bad_function_call &)
{
assert(0);
return;
}
#if defined(IRCD_ALLOCATOR_USE_JEMALLOC) && defined(HAVE_JEMALLOC_H)
ircd::string_view
ircd::allocator::info(const mutable_buffer &buf)
{
std::stringstream out;
pubsetbuf(out, buf);
je_stats_callback = []
(auto &out, const string_view &msg)
{
out << msg;
};
static const char *const &opts
{
""
};
malloc_stats_print(je_stats_handler, &out, opts);
out << std::endl;
return view(out, 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()
noexcept
{
}
#endif
#if defined(IRCD_ALLOCATOR_USE_JEMALLOC) && defined(HAVE_JEMALLOC_H)
void
ircd::allocator::scope::hook_fini()
noexcept
{
}
#endif