Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MDEV-14315 -- Reflect use of tcmalloc in a system variable and error log
* The version of tcmalloc is written to the system variable 'version_malloc_library' if tcmalloc is used, similarly to jemalloc * Extracted method guess_malloc_library()
- Loading branch information
Vesa Pentti
committed
Dec 18, 2017
1 parent
0acac4f
commit 7fd7805
Showing
4 changed files
with
68 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* Copyright (c) 2002, 2015, Oracle and/or its affiliates. | ||
Copyright (c) 2012, 2017, MariaDB Corporation. | ||
This program is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU General Public License as published by | ||
the Free Software Foundation; version 2 of the License. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License | ||
along with this program; if not, write to the Free Software | ||
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ | ||
|
||
/* guess_malloc_library() deduces, to the best of its ability, | ||
the currently used malloc library and its version */ | ||
|
||
#include <stddef.h> | ||
#include <m_string.h> | ||
|
||
char *guess_malloc_library() | ||
{ | ||
#ifndef HAVE_DLOPEN | ||
return (char*) MALLOC_LIBRARY; | ||
#else | ||
static char buf[128]; | ||
|
||
if (strcmp(MALLOC_LIBRARY, "system") != 0) | ||
{ | ||
return (char*) MALLOC_LIBRARY; | ||
} | ||
|
||
/* tcmalloc */ | ||
typedef const char* (*tc_version_type)(int*, int*, const char**); | ||
tc_version_type 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 */ | ||
typedef int (*mallctl_type)(const char*, void*, size_t*, void*, size_t); | ||
mallctl_type 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*) MALLOC_LIBRARY; | ||
#endif | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters