DTrace
可以通过-x
指定编译或运行时的选项。以下列命令为例:
# dtrace -n 'syscall::write:entry /pid == $target/ { printf("Written %d bytes\n", arg2); }' -c "dd if=/dev/zero of=/dev/null count=1"
dtrace: description 'syscall::write:entry ' matched 2 probes
1+0 records in
1+0 records out
512 bytes transferred in 0.000039 secs (12964979 bytes/sec)
CPU ID FUNCTION:NAME
0 57477 write:entry Written 512 bytes
0 57477 write:entry Written 31 bytes
0 57477 write:entry Written 60 bytes
dtrace: pid 3789 has exited
对比加上-x flowindent
的运行效果:
# dtrace -x flowindent -n 'syscall::write:entry /pid == $target/ { printf("Written %d bytes\n", arg2); }' -c "dd if=/dev/zero of=/dev/null count=1"
dtrace: description 'syscall::write:entry ' matched 2 probes
1+0 records in
1+0 records out
512 bytes transferred in 0.000040 secs (12889258 bytes/sec)
CPU FUNCTION
0 => write Written 512 bytes
0 => write Written 31 bytes
0 => write Written 60 bytes
dtrace: pid 3793 has exited
如果想在脚本使用这些选项,需要使用#pragma D option ...
指令:
#!/usr/sbin/dtrace -s
#pragma D option flowindent
syscall::write:entry
/pid == $target/
{
printf("Written %d bytes\n", arg2);
}
而不能直接写在第一行,也就是dtrace
命令后面:
#!/usr/sbin/dtrace -s -x flowindent
在Solaris/illumos
系统上,只有第一个参数,也就是-s
会被处理,其余会被丢弃。而在FreeBSD
上会直接报错:
dtrace: failed to open -x flowindent: No such file or directory
参考资料:
Does DTrace script only support “#pragma D option ..”, not “-x option”?。