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 %-@8d %-@8d\n",@count,@times);
}
这个脚本用到了两个aggregation
:count
和times
。count
是统计系统调用次数,而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