In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail how to use strace to track mysql execution statements in linux. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Strace is a program debugging tool in Linux environment, which is used to monitor the system calls used by an application and the system information it receives. Track the entire life cycle of the program, and output the name, parameters, return value and execution time of each system call.
Common parameters of strace:
-p tracks the specified process
The-f trace is called by the fork child process system
-F attempts to trace the vfork subprocess system tuning inhalation, and when it occurs at the same time as-f, the VFork is not tracked.
-o filename outputs the result to stdout by default strace. The output can be written to the filename file with-o
-ff is often used with the-o option, and system calls generated by different processes (child processes) are output to the filename.PID file
-r print the relative time of each system call
-t adds time information before each line in the output. -tt time is set to microsecond level. You can also use-ttt to print the relative time
-v outputs all system calls. By default, some frequently called system calls do not output
-s specifies the length of each line of output string, which defaults to 32. The file name is always output.
-c counts the execution time, number of calls and errors of each system call.
-e expr output filter, through expressions, you can filter out the output you don't want
1. Strace tracks multiple processes:
When there are multiple sub-processes, such as php-fpm, nginx, etc., it is very inconvenient to use strace to trace. You can use the following methods to track all child processes.
# vim / root/.bashrc / / add the following content: function straceall {strace $(pidof "${1}" | sed's /\ ([0-9] *\) /-p\ 1ax g')} # source / root/.bashrc
Execute:
# traceall php-fpm
two。 Track web server system calls
# strace-f-F-s 1024-o nginx-strace / usr/local/nginx/sbin/nginx-c / usr/local/nginx/conf/nginx.conf# strace-f-F-o php-fpm-strace / usr/local/php/sbin/php-fpm-y / usr/local/php/etc/php-fpm.conf
3. Trace mysql execution statement
# strace-f-F-ff-o mysqld-strace-s 1024-p mysql_pid# find. /-name "mysqld-strace*"-type f-print | xargs grep-n "SELECT.*FROM"
4. Whatisdong- to see what the program is doing
#! / bin/bash# This script is from http://poormansprofiler.org/nsamples=1sleeptime=0pid=$(pidof $1) for x in $(seq 1$ nsamples) do gdb-ex "set pagination 0"-ex "thread apply all bt"-batch-p $pid sleep $sleeptime done |\ awk 'BEGIN {s = ";} / ^ Thread/ {print s; s =" } / ^\ # / {if (s! = ") {s = s", "$4} else {s = $4}} END {print s}'|\ sort | uniq-c | sort-r-n-k 1Lign1
Output:
# profiler.sh mysqld727 pthread_cond_wait@@GLIBC_2.3.2,cache_thread,put_in_cache=true), handle_one_connection,start_thread,?? 4 pthread_cond_wait@@GLIBC_2.3.2,os_event_wait_low,os_aio_simulated_handle,fil_aio_wait,io_handler_thread,start_thread,?? 4 read,my_real_read,my_net_read,do_command,handle_one_connection,start_thread ?? 1 pthread_cond_wait@@GLIBC_2.3.2,os_event_wait_low,srv_master_thread,start_thread,?? 1 pthread_cond_wait@@GLIBC_2.3.2,MYSQL_BIN_LOG::wait_for_update,mysql_binlog_send,dispatch_command,do_command,handle_one_connection,start_thread,?? 1 do_sigwait,sigwait,signal_hand,start_thread This is the end of the article on "how to use strace to track mysql execution statements in linux" Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 275
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.