dongnuoyi8833 2016-10-11 19:00
浏览 61
已采纳

如何在OS X上的Go程序中计算系统调用?

I'm trying to count the syscalls in my Go program on OS X Yosemite. I've tried using dtruss and dtrace, but both cause my program to crash with the following error, followed by a stack trace:

fatal error: runtime: bsdthread_register error

The two commands I've used are:

  1. sudo dtruss "./my_program my_arg"
  2. sudo dtrace -c "powerset 2" -n 'syscall:::entry { @num[probefunc] = count(); }'

Things I've Tried

The main takeaway from my Google-foo has been to unset DYLD_INSERT_LIBRARIES, which I have done numerous times to no avail.

./my_program is a binary that I created with go install. I've written an equivalent C program and both of the above commands work fine with that.

  • 写回答

1条回答 默认 最新

  • donglan7594 2016-10-11 19:47
    关注

    If you want to use dtrace on macOS, you will need to use the external linker to build your program

    -ldflags -linkmode=external
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?