Table of Contents Previous Slide Next Slide

Software Development in the UNIX Environment
Profiling Your Code

time - command prints user,system time, wall time and other parameters

etime - function to measure elapsed time in seconds


prof

Examples ( best not to optimize code )

Using gcc

gcc -o file -p file.c (compile and link with -p option)
file ( run program and produces 'mon.out')
prof file > file.prof

On Solaris

cc -o file -pg file.c (compile and link with -pg goption)
file ( run program and produces 'mon.out')
prof file > file.prof

On Irix (Use Speedshop - ssrun)

cc -o file file.c
ssrun -pcsamp file ( produces 'file..pcsamp.###')
prof file.pcsamp.###

On AIX

cc -o file -p file.c (compile and link with -p option)
file ( run program and produces 'mon.out')
prof file > file.prof

Sample output from prof

-------------------------------------------------------------------------
Function list, in descending order by time
-------------------------------------------------------------------------
 [index]      secs    %    cum.%   samples  function (dso: file, line)

     [1]  1020.180  43.6%  43.6%    102018  __pow (libm.so: pow.c, 198)
     [2]   721.570  30.8%  74.4%     72157  __log (libm.so: log.c, 139)
     [3]   358.100  15.3%  89.7%     35810  __exp (libm.so: exp.c, 102)
     [4]   235.820  10.1%  99.8%     23582  asa (asa_run: asa.c, 59)
     [5]     1.310   0.1%  99.9%       131  write_last_best (asa_run: getpd.c,566)
     [6]     0.990   0.0%  99.9%        99  loadlists (asa_run: getpd.c, 172)
     [7]     0.960   0.0%  99.9%        96  cost_derivatives (asa_run: asa.c,2229)
     [8]     0.540   0.0% 100.0%        54  print_state (asa_run: asa.c, 2762)
     [9]     0.210   0.0% 100.0%        21  _free (libc.so.1: malloc.c, 903)
    [10]     0.100   0.0% 100.0%        10  write_profile (asa_run: getpd.c,629)
    

Another sample output from prof on a different kind of computer

Name                 %Time     Seconds     Cumsecs  #Calls   msec/call
.scatter              17.7       10.35       10.35 28668877      0.0004
.ran3                 17.2       10.06       20.41 86286632      0.0001
.__mcount             16.2        9.48       29.89
.sqrt                 16.1        9.44       39.33
.doAnisotropicScatte   7.4        4.36       43.69       7       623.
.getRandomNumber       7.1        4.15       47.84 86286631      0.0000
._log                  6.5        3.81       51.65
.path                  5.7        3.36       55.01 28738877      0.0001
.cos                   4.2        2.46       57.47
.sin                   1.1        0.65       58.12