Editing Stracing a program

Jump to: navigation, search

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 much slower then you've expected. How can you investigate the reason
+
but musch slower then you've expected. How can you investigate yourself the reason
of such undesirable behaviour? First of all, you can read and analyze logs that  
+
of such undesirable behaviour? First of all you can read and analyze logs that  
this program does (if it does). It's very useful to run unkindly program with
+
this program does (if does). It's very usefull to run unkindly program with
<tt>--verbose</tt> argument or somehow else increase the log level, if the program allows that.
+
<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:
  
<pre>
+
<tt>strace -o strace.out -ff touch /tmp/file</tt>
strace -o strace.out -ff touch /tmp/file
+
 
</pre>
+
<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
  
Here
+
If the process under strace (touch in our case) forks child processes, then, thanks to <tt>-ff</tt> option, child processes
* <tt>-o strace.out</tt> option means that strace program will output all information to the file named <tt>strace.out</tt>;
+
are straced too, and ouputs are placed in <tt>strace.out.PID</tt> files appropriately.
* <tt>-ff</tt> means to strace the forked children of the program. Child straces outputs will be placed to <tt>strace.out.PID</tt> files, where PID is a pid of the child. If you want all the output to a single file, use <tt>-f</tt> argument instead (i.e. single <tt>f</tt> not double).
 
* <tt>touch /tmp/file</tt> is the program with arguments which is to be straced.
 
  
 
== Strace results ==
 
== Strace results ==
So this is what we have in <tt>strace.out</tt>:
+
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>
  
Analysis of <tt>strace.out</tt>, in conjunction with reading the source code, is realy very powerful thing. Even if you can not understand strace output yourself &mdash; send it to the developers, it'll be really helpful.
+
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 if a program works slow) you are also intersted in time that the program spends in syscalls. Than
+
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]]

Please note that all contributions to OpenVZ Virtuozzo Containers Wiki may be edited, altered, or removed by other contributors. If you don't want your writing to be edited mercilessly, then don't submit it here.
If you are going to add external links to an article, read the External links policy first!

To edit this page, please answer the question that appears below (more info):

Cancel Editing help (opens in new window)