--- ../new/mysql-8.0.31/sql/sys_vars.cc 2022-09-14 00:15:16.000000000 +0800 +++ sql/sys_vars.cc 2023-03-25 02:57:44.094219430 +0800 @@ -151,6 +151,11 @@ #include "storage/perfschema/pfs_server.h" #include "storage/perfschema/terminology_use_previous.h" #endif /* WITH_PERFSCHEMA_STORAGE_ENGINE */ +#include +#include +#include + + static constexpr const unsigned long DEFAULT_ERROR_COUNT{1024}; static constexpr const unsigned long DEFAULT_SORT_MEMORY{256UL * 1024UL}; @@ -5252,6 +5257,41 @@ return false; } + +typedef const char* (*tc_version_type)(int*, int*, const char**); +typedef int (*mallctl_type)(const char*, void*, size_t*, void*, size_t); + +char *get_malloc_library() +{ + tc_version_type tc_version_func; + mallctl_type mallctl_func; + static char buf[128]; + + /* tcmalloc */ + tc_version_func= (tc_version_type) dlsym(RTLD_DEFAULT, "tc_version"); + if (tc_version_func) + { + int major, minor; + const char* ver_str = tc_version_func(&major, &minor, NULL); + strxnmov(buf, sizeof(buf)-1, "tcmalloc ", ver_str, NULL); + return buf; + } + + /* jemalloc */ + mallctl_func= (mallctl_type) dlsym(RTLD_DEFAULT, "mallctl"); + if (mallctl_func) + { + char *ver; + size_t len = sizeof(ver); + mallctl_func("version", &ver, &len, NULL, 0); + strxnmov(buf, sizeof(buf)-1, "jemalloc ", ver, NULL); + return buf; + } + + return (char*) "system"; +} + + static Sys_var_transaction_read_only Sys_transaction_read_only( "transaction_read_only", "Set default transaction access mode to read only.", @@ -5274,6 +5314,13 @@ READ_ONLY NON_PERSIST GLOBAL_VAR(server_version_ptr), NO_CMD_LINE, IN_SYSTEM_CHARSET, DEFAULT(server_version)); +static char *malloc_library; +static Sys_var_version Sys_malloc_library( + "malloc_library", "Version of the used malloc library", + READ_ONLY GLOBAL_VAR(malloc_library),NO_CMD_LINE,IN_SYSTEM_CHARSET, + DEFAULT(get_malloc_library())); + + static char *server_version_comment_ptr; static Sys_var_charptr Sys_version_comment( "version_comment", "version_comment",