In earlier years, if you know there strace command, it is cattle, and now we basically know strace, if you experience performance problems to help others, in all likelihood would suggest that you hang with strace to see, but when you hang up, watching the full screen rolling character, but in all likelihood not see what they were. In this paper, a simple case, to show you what some of the repertoire with strace diagnose problems when.
Follows the real case, any similarity, it is inevitable! Let's look at the results of a top high-load servers:
Tip: When you run top, press "1" to open the CPU list, press "shift + p" to sort the CPU.
In this example, we can easily find the main CPU is occupied by a number of PHP processes, while PHP process takes up more memory, but the memory still balances system, SWAP is not serious, this is not the main cause of the problem.
However, the list can be seen in the CPU CPU mainly consumed in kernel mode "sy", rather than the user mode "us" and our experience does not match. Linux operating system has a lot of tools for tracking program behavior, function call tracking kernel mode "strace" user mode tracking function call "ltrace", so here we should use "strace":
shell> strace-p < PID >
However, if the direct use strace to track a process, then wait for your characters tend to be full screen roll and want to be seen from the crux of the problem here is not an easy thing, but fortunately strace can be aggregated by time operation:
shell> strace-cp < PID >
By "c" option to summarize total time of each operation, the result after running roughly as follows:
Obviously, we can see the main CPU clone operation is consumed, you can also track what clone alone:
shell> strace-T -e clone-p < PID >
By "T" option to obtain the actual operating time consumed by "e" option to track an action:
strace -T -e clone -p
Obviously, a clone operation takes a few hundred milliseconds, as clone meaning, reference man documentation:
clone () creates a new process, in a manner similar to fork (2). It is actually a library function layered on top of the underlying clone () system call, hereinafter referred to as sys_clone. A description of sys_clone is given towards the end of this page.
Unlike fork (2), these calls allow the child process to share parts of its execution context with the calling process, such as the memory space, the table of file descriptors, and the table of signal handlers. (Note that on this manual page , "calling process" normally corresponds to "parent process". But see the description of CLONE_PARENT below.)
In simple terms, it is to create a new process. So in PHP when such a system would appear to call it? Discover the business code to see the exec function, the following command to verify that it does cause clone system call:
shell> strace-eclone php -r 'exec ( "ls");'
Finally, we test a question: If we use strace to track a process, very little output, it is not that the process is idle? In fact, try ltrace, may find amazing. Remember the kernel mode and user mode points.