Editing Stracing a program
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
− | Suppose some program on your system refuses to work or it works | + | Suppose some program on your system refuses to work or it works |
− | but | + | but musch slower then you've expected. How can you investigate yourself the reason |
− | of such undesirable behaviour? First of all | + | of such undesirable behaviour? First of all you can read and analyze logs that |
− | this program does (if | + | this program does (if does). It's very usefull to run unkindly program with |
− | <tt>--verbose</tt> argument or somehow else increase | + | <tt>--verbose</tt> argument or somehow else increase log level, if the program allows that. |
But what can you do, if logs are poor and it's impossible to infer the reason of badness from them? | But what can you do, if logs are poor and it's impossible to infer the reason of badness from them? | ||
One way is to use strace program to follow system calls performed by given process. | One way is to use strace program to follow system calls performed by given process. | ||
Line 10: | Line 10: | ||
Commonly to use strace you should give the following command: | Commonly to use strace you should give the following command: | ||
− | < | + | <tt>strace -o strace.out -ff touch /tmp/file</tt> |
− | strace -o strace.out -ff touch /tmp/file | + | |
− | </ | + | <tt>-o strace.out</tt> option means that strace program will output all investigated information |
+ | to the file named <tt>strace.out</tt> | ||
+ | |||
+ | <tt>touch /tmp/file</tt> is the program with arguments to strace | ||
− | + | If the process under strace (touch in our case) forks child processes, then, thanks to <tt>-ff</tt> option, child processes | |
− | + | are straced too, and ouputs are placed in <tt>strace.out.PID</tt> files appropriately. | |
− | |||
− | |||
== Strace results == | == Strace results == | ||
− | So | + | So what we have in strace.out: |
<pre> | <pre> | ||
execve("/usr/bin/touch", ["touch", "/tmp/file"], [/* 51 vars */]) = 0 | execve("/usr/bin/touch", ["touch", "/tmp/file"], [/* 51 vars */]) = 0 | ||
Line 60: | Line 61: | ||
</pre> | </pre> | ||
− | + | Strace.out in conjunction with source code is realy very powerfull thing. So if you can't analyze strace yurself - send it | |
+ | to developers, it'll be really helpful. | ||
== Additional notes == | == Additional notes == | ||
− | Sometimes (for example | + | Sometimes (for example program works slow) you are also intersted in time, that program spends in syscalls. Than |
options <tt>-tt</tt> and <tt>-T</tt> are helpful. | options <tt>-tt</tt> and <tt>-T</tt> are helpful. | ||
− | As you've seen strace program shows arguments of syscalls. But if arguments are a pointers it shows us only 32 bytes from these pointers. To increase this number use <tt>-s</tt> option | + | As you've seen strace program shows arguments of syscalls. But if arguments are a pointers it shows us only 32 bytes from these pointers. |
+ | To increase this number use <tt>-s</tt> option | ||
[[Category: Troubleshooting]] | [[Category: Troubleshooting]] |