How to trace system calls of a program in Mac OS X

2019-01-23 03:20发布

I wanted to trace the system calls made by the find command to debug some performance issues however I could not figure out how to do this on Mac OS X Yosemite. How can I trace system calls for an arbitrary program similarly to what strace does on FreeBSD? I am especially interested in tracing file-system related calls.

标签: macos strace
2条回答
Juvenile、少年°
2楼-- · 2019-01-23 03:44

Under current versions of macOS, executables under paths covered by SIP (like /usr/bin) cannot be traced.

You can bypass this by making a copy of the executable in your home directory and tracing the copy:

cp /usr/bin/find find
sudo dtruss ./find …
查看更多
叼着烟拽天下
3楼-- · 2019-01-23 03:51

You can use dtruss like in

sudo dtruss find ~/repo -depth 2 -type d -name '.git'

The manual page of that utility will help you to tailor the use of the tool to your needs.

查看更多
登录 后发表回答