# Performance statistics tool for programs (truss/ktrace/strace/nbench)



## kenorb (Nov 10, 2010)

I'm looking for some diagnostic tool, which could be combination of debuggers like truss, ktrace, strace, benchmarking tools nbench, statistic tools like top, iotop (from Linux) and FreeBSD shortcut Control-T.
Basically I need to run the binary and check the statistics, as much information as possible, how much time was spend on interrupts, user, system, how many file request. Basically on what the program spend most of the time.
Is there any tool like that?


----------



## SirDice (Nov 10, 2010)

Have a look at `% systat -vmstat`.
But that's a more overall picture. 

You're probably looking for a profiler. Have a look at gprof(1).


----------



## kenorb (Nov 10, 2010)

Installed /usr/ports/lang/php52 with -pg flags.

```
cc -pipe -pg -march=nocona -pg -g -O0 -Wall ext/date/.libs/php_date.o ext/date/...
...
> gprof `which php`
gprof: /usr/local/bin/php.gmon: No such file or directory
```
Why it doesn't work? How to generate gmon file? I want to run profiler for php binary it-self.


----------



## kenorb (Nov 10, 2010)

Ok, I figure it out:

```
sudo sl
gprof `which sl` sl.gmon | head
```


```
%   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 53.6       0.01     0.01        0  100.00%           _mcount [1]
 25.0       0.02     0.01        0  100.00%           _select [2]
 10.7       0.03     0.00    17372     0.00     0.00  __vfprintf [5]
...
  0.0       0.03     0.00      253     0.00     0.00  add_smoke [20]
```


First you need to run it, and then use gprof against generated gmon file.
Many thanks!


----------



## Galactic_Dominator (Nov 11, 2010)

Profiling FreeBSD.

http://www.youtube.com/watch?v=Mfb5_uG7BCA&feature=related


----------



## kenorb (Nov 11, 2010)

Thanks for the right direction.

Found more tools:
http://stackoverflow.com/questions/54971/profiling-visualization-tools
http://stackoverflow.com/questions/1777556/alternatives-to-gprof
http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux

valgrind(+kcachegrind, etc.) is great!

```
> pkg_add -rv kcachegrind sl
> valgrind --tool=callgrind --dump-instr=yes --trace-jump=yes sl
> kcachegrind callgrind.out.*
```
, kprof, etc.


----------

