1 Star2 Stars3 Stars4 Stars5 Stars (还没有评分)
Loading...

使用DTrace度量系统调用的执行时间

Jim Mauro写过一个度量系统调用执行时间的DTrace脚本(参考这里:Measuring the execution of each system call):

#!/usr/sbin/dtrace -qs

syscall:::entry
/pid == $target/
{
        @count[probefunc] = count();
        self->st[probefunc] = timestamp;
}
syscall:::return
/self->st[probefunc]/
{
        this->t = (timestamp - self->st[probefunc]) / 1000;
        @times[probefunc] = sum(this->t);

        self->st[probefunc] = 0; this->t = 0;
}
END
{
        printf("%-16s %-8s %-8s\n","SYSCALL","COUNT","TIME(us)");
        printa("%-16s %[email protected] %[email protected]\n",@count,@times);
}

这个脚本用到了两个aggregationcounttimescount是统计系统调用次数,而times则是统计系统调用所花费的时间(需要注意的是时间是wall-clock时间),它们都以系统调用的名字作为key。在SmartOS上,执行如下:

# ./sc.d -p 3207
^C
SYSCALL          COUNT    TIME(us)
read             2        8
write            2        113
pollsys          4        12
clock_gettime    8        10
lwp_sigmask      8        13

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.