From e26b567218fb8a1d71ef74f16970ce2974dd7ede Mon Sep 17 00:00:00 2001 From: Carlos Salguero Date: Thu, 17 May 2018 14:35:52 -0300 Subject: [PATCH] PT-1554 Improved jemalloc detection --- bin/pt-mysql-summary | 21 +++++++---------- lib/bash/report_mysql_info.sh | 23 +++++++------------ .../samples/expected_output_temp002.txt | 2 -- .../samples/expected_output_temp003.txt | 2 -- .../samples/expected_output_temp004.txt | 2 -- .../samples/expected_output_temp005.txt | 2 -- .../samples/expected_output_temp006.txt | 2 -- .../samples/expected_output_temp007.txt | 2 -- 8 files changed, 16 insertions(+), 40 deletions(-) diff --git a/bin/pt-mysql-summary b/bin/pt-mysql-summary index 30d5fe3a..24ffa558 100755 --- a/bin/pt-mysql-summary +++ b/bin/pt-mysql-summary @@ -2254,24 +2254,19 @@ report_jemalloc_enabled() { local JEMALLOC_LOCATION='' for PID in $(pidof mysqld); do - grep -qc jemalloc /proc/${PID}/environ || ldd $(which mysqld) 2>/dev/null | grep -qc jemalloc - JEMALLOC_STATUS=$? - if [ $JEMALLOC_STATUS = 1 ]; then - echo "jemalloc is not enabled in MySQL config for process with ID ${PID}" + grep -qc jemalloc /proc/${pid}/environ || ldd $(which mysqld) 2>/dev/null | grep -qc jemalloc + jemalloc_status=$? + if [ $jemalloc_status = 1 ]; then + echo "jemalloc is not enabled in mysql config for process with id ${pid}" else - echo "jemalloc enabled in MySQL config for process with ID ${PID}" + echo "jemalloc enabled in mysql config for process with id ${pid}" GENERAL_JEMALLOC_STATUS=1 fi done - if [ $GENERAL_JEMALLOC_STATUS = 1 ]; then - for libjemall in "/usr/lib64" "/usr/lib/x86_64-linux-gnu" "/usr/lib"; do - if [ -r "$libjemall/libjemalloc.so.1" ]; then - JEMALLOC_LOCATION="$libjemall/libjemalloc.so.1" - break - fi - done - if [ -z $JEMALLOC_LOCATION ]; then + if [ $GENERAL_JEMALLOC_STATUS -eq 1 ]; then + JEMALLOC_LOCATION=$(find /usr/lib64/ /usr/lib/x86_64-linux-gnu /usr/lib -name "libjemalloc.*" 2>/dev/null | head -n 1) + if [ -z "$JEMALLOC_LOCATION" ]; then echo "Jemalloc library not found" else echo "Using jemalloc from $JEMALLOC_LOCATION" diff --git a/lib/bash/report_mysql_info.sh b/lib/bash/report_mysql_info.sh index 11776096..539bbd6a 100644 --- a/lib/bash/report_mysql_info.sh +++ b/lib/bash/report_mysql_info.sh @@ -1256,26 +1256,19 @@ report_jemalloc_enabled() { local JEMALLOC_LOCATION='' for PID in $(pidof mysqld); do - grep -qc jemalloc /proc/${PID}/environ || ldd $(which mysqld) 2>/dev/null | grep -qc jemalloc - JEMALLOC_STATUS=$? - if [ $JEMALLOC_STATUS = 1 ]; then - echo "jemalloc is not enabled in MySQL config for process with ID ${PID}" + grep -qc jemalloc /proc/${pid}/environ || ldd $(which mysqld) 2>/dev/null | grep -qc jemalloc + jemalloc_status=$? + if [ $jemalloc_status = 1 ]; then + echo "jemalloc is not enabled in mysql config for process with id ${pid}" else - echo "jemalloc enabled in MySQL config for process with ID ${PID}" + echo "jemalloc enabled in mysql config for process with id ${pid}" GENERAL_JEMALLOC_STATUS=1 fi done - if [ $GENERAL_JEMALLOC_STATUS = 1 ]; then - # Check location for libjemalloc.so.1 - #for libjemall in "${SCRIPT_PWD}/lib/mysql" "/usr/lib64" "/usr/lib/x86_64-linux-gnu" "/usr/lib"; do - for libjemall in "/usr/lib64" "/usr/lib/x86_64-linux-gnu" "/usr/lib"; do - if [ -r "$libjemall/libjemalloc.so.1" ]; then - JEMALLOC_LOCATION="$libjemall/libjemalloc.so.1" - break - fi - done - if [ -z $JEMALLOC_LOCATION ]; then + if [ $GENERAL_JEMALLOC_STATUS -eq 1 ]; then + JEMALLOC_LOCATION=$(find /usr/lib64/ /usr/lib/x86_64-linux-gnu /usr/lib -name "libjemalloc.*" 2>/dev/null | head -n 1) + if [ -z "$JEMALLOC_LOCATION" ]; then echo "Jemalloc library not found" else echo "Using jemalloc from $JEMALLOC_LOCATION" diff --git a/t/pt-mysql-summary/samples/expected_output_temp002.txt b/t/pt-mysql-summary/samples/expected_output_temp002.txt index 070af6a3..b7b7a5e2 100644 --- a/t/pt-mysql-summary/samples/expected_output_temp002.txt +++ b/t/pt-mysql-summary/samples/expected_output_temp002.txt @@ -277,5 +277,3 @@ report-port = 12345 log-error = mysqld.log innodb_lock_wait_timeout = 3 # Memory management library ################################## -Jemalloc library not found -# The End #################################################### diff --git a/t/pt-mysql-summary/samples/expected_output_temp003.txt b/t/pt-mysql-summary/samples/expected_output_temp003.txt index 0e919522..e5b20824 100644 --- a/t/pt-mysql-summary/samples/expected_output_temp003.txt +++ b/t/pt-mysql-summary/samples/expected_output_temp003.txt @@ -220,5 +220,3 @@ report-port = 12345 log-error = mysqld.log innodb_lock_wait_timeout = 3 # Memory management library ################################## -Jemalloc library not found -# The End #################################################### diff --git a/t/pt-mysql-summary/samples/expected_output_temp004.txt b/t/pt-mysql-summary/samples/expected_output_temp004.txt index 6961496d..55cd02a8 100644 --- a/t/pt-mysql-summary/samples/expected_output_temp004.txt +++ b/t/pt-mysql-summary/samples/expected_output_temp004.txt @@ -219,5 +219,3 @@ report-port = 12345 log-error = mysqld.log innodb_lock_wait_timeout = 3 # Memory management library ################################## -Jemalloc library not found -# The End #################################################### diff --git a/t/pt-mysql-summary/samples/expected_output_temp005.txt b/t/pt-mysql-summary/samples/expected_output_temp005.txt index 95cbb20f..3f48c826 100644 --- a/t/pt-mysql-summary/samples/expected_output_temp005.txt +++ b/t/pt-mysql-summary/samples/expected_output_temp005.txt @@ -292,5 +292,3 @@ report-port = 12345 log-error = mysqld.log innodb_lock_wait_timeout = 3 # Memory management library ################################## -Jemalloc library not found -# The End #################################################### diff --git a/t/pt-mysql-summary/samples/expected_output_temp006.txt b/t/pt-mysql-summary/samples/expected_output_temp006.txt index d8788b2b..10b79804 100644 --- a/t/pt-mysql-summary/samples/expected_output_temp006.txt +++ b/t/pt-mysql-summary/samples/expected_output_temp006.txt @@ -341,5 +341,3 @@ log_queries_not_using_indexes | OFF # Configuration File ######################################### Config File | Cannot autodetect or find, giving up # Memory management library ################################## -Jemalloc library not found -# The End #################################################### diff --git a/t/pt-mysql-summary/samples/expected_output_temp007.txt b/t/pt-mysql-summary/samples/expected_output_temp007.txt index 50116ee3..bd784839 100644 --- a/t/pt-mysql-summary/samples/expected_output_temp007.txt +++ b/t/pt-mysql-summary/samples/expected_output_temp007.txt @@ -295,5 +295,3 @@ log_queries_not_using_indexes | OFF # Configuration File ######################################### Config File | Cannot autodetect or find, giving up # Memory management library ################################## -Jemalloc library not found -# The End ####################################################