Hi all.

What is the right way to measure wall-clock time in profiling on FreeBSD?

Standard profiling method in UNIX like 'gprof' measures CPU time, but
it doesn't always offer a good indication for tuning if application is
not CPU bound.

For example, the below simple program spend most of the time for disk
I/O, but gprof doesn't tell me that fsync(2) in output() is the
hot-spot which should be removed at first.

#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>

char calc()
        int i;
        char c;
        for (i = 0; i < 10000; i++) {
                c = c * i;
        return c;

void output(int fd, char c)
        write(fd, &c, 1);
        fsync(fd);                      /* XXX time consuming system call */

int main()
        int fd;
        int i;
        char c;

        fd = open("testfile", O_CREAT | O_WRONLY);

        for (i = 0; i < 10000; i++) {
                c = calc(i);
                output(fd, c);

        return 0;
gprof's output:

  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 84.2       0.56     0.56    10000     0.06     0.06  calc [3]
 13.6       0.65     0.09    10000     0.01     0.01  _fsync [5]
  1.4       0.66     0.01    10000     0.00     0.00  write [6]
  0.7       0.66     0.00                             .mcount (12)
  0.2       0.66     0.00    10000     0.00     0.01  output [4]

Measuring CPU time has been proper for traditional UNIX as TSS, but I
think wall-clock time is also useful in these days. It is affected by
system load, but it is easy to arrange some dedicated system for
profiling purpose.

Wall-clock time profiling itself could be implemented by simple kernel
hack (i386/i386/trap.c:syscall() and kern/subr_trap.c:userret()), but
if both CPU and wall-clock time profiling are available, I don't know
how users should change the method. sysctl(8) may be inappropriate.

Although I'm not familiar with another analysis tools, like DTrace for
FreeBSD, is there something help for me?


Akihiro KAYAMA
freebsd-questions@freebsd.org mailing list
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to