Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timing each call...similar to 'truss'

Status
Not open for further replies.

gonzilla

Programmer
Apr 10, 2001
125
US
Hi,

I work on UNIX SVR4. One of our admins came and asked if I could write something to time each call made by an existing C program. Basically, he wants to see what part of it is taking so long run. We looked into the 'truss' command and that is close, but doesn't quite get everything we need. We really need to get the time for each system call the program makes. The truss lists it and if you use -c will give you a pretty good idea, but he needs a bit more detail.

Is this possible - given that we can't actually add the code to the existing program - more, trace what it is doing and time it.

Thanks.

-Tyler
 
Not sure what you mean by timing each call. If you are using truss, then it is probably SunOS. The compiler has a profiling option which will tell you how much time is spent in every routine. I think you have to analyze it with a tool called gprof. The whole program has to be rebuilt with the profiling flag.

Have a look at the profiling tools in workshop.
 
why can't you add code??
you have to recompile with appropiate options, so you need the code, and so you can add in it.
a very easy way

include <time.h>
long before, after;
before = after = 0;

time(&before);
exec the func() ...;
time(&after);
printf(&quot;secs spent to exec func(): %ld\n&quot;,after-before); vox clamantis in deserto.
 
Hi,

Thanks for the responses. jamisar - we can't add code because the source doesn't belong to us. We didn't write the code, we are just trying to pin-point what part of the existing code is taking the longest to execute...we are pretty sure it is the disc access routines.

We found a solution though. Seems that a newer version of the truss (on version 7) command is out there that does exactly what we are looking for. It ouputs the time in seccnds for each system call. I will be able to write something to read this output and determine where the slowdown is.

Thanks again for your help.

-Tyler
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top