strace
Learn about strace and ltrace. These two tools are very useful when your program fails, hangs or even crashes and you don't know why or you want to get an overall understanding of performance. Note the profile parameter (-c) and append to a running process parameter (-p).
example
Order
strace -tt -T -v -f -e trace=file -o /data/log/strace.log -s 1024 -p 23489
parameter
-tt 在每行输出的前面,显示毫秒级别的时间
-T 显示每次系统调用所花费的时间
-v 对于某些相关调用,把完整的环境变量,文件stat结构等打出来。
-f 跟踪目标进程,以及目标进程创建的所有子进程
-e 控制要跟踪的事件和跟踪行为,比如指定要跟踪的系统调用名称
-o 把strace的输出单独写到指定的文件
-s 当系统调用的某个参数是字符串时,最多输出指定长度的内容,默认是32个字节
-p 指定要跟踪的进程pid, 要同时跟踪多个pid, 重复多次-p选项即可。
Debugger
strace -tt -f ./some_server ../conf/some_server.conf
Debug an already running program
get nginx pid
pidof nginx
1111
track, test track effect,nginx -s reload
strace -p 1111
Files loaded during debugger startup
The output here only shows content related to file access, because we specified it through the -e trace=file option.
strace -tt -T -f -e trace=file -s 1024 -o output.log nginx -s reload
experience
God knows what the program did to cause it to fail to start or report an error. This command is very useful for analyzing some behaviors
For example, if the program cannot start without a configuration file, or there is no permission, but the program does not have a clear prompt, you can use strace to track it at this time
The usage example in laravel can analyze the sequence of file loading
strace -tt -T -f -e trace=file -s 1024 -o output.log php artisan list
Of course, this is used in more scenarios in swoole