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

DTrace脚本使用选项时需要注意的问题

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”?

Leave a Reply

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