2015-06-25 66 views
11

我想跟踪由找到命令to debug some performance issues所做的系统调用,但是我无法弄清楚如何在Mac OS X Yosemite上执行此操作。我如何跟踪任意程序的系统调用,类似于FreeBSD上的strace?我特别感兴趣的是跟踪文件系统相关的调用。如何在Mac OS X中跟踪程序的系统调用

+2

快速搜索* strace的OSX *给了我[这个四岁的博客文章(HTTPS:

您可以通过可执行文件的副本,在你的主目录,并跟踪复制绕过这个://opensourcehacker.com/2011/12/02/osx-strace-equivalent-dtruss-seeing-inside-applications-what-they-do-and-why-they-hang/)。使用相同的搜索应该很容易找到其他替代方案。 –

+0

@JoachimPileborg尼斯点。我用另一种方法,从* apropos trace *开始搜索。我忽视了* dtruss *和* dtrace *,因为我发现的所有结果都是关于* D *语言的跟踪实用程序。 –

回答

11

您可以使用dtruss

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

该实用程序的manual page将帮助您使用该工具的满足你的需要。

+7

当时(15年6月)dtruss做了工作,但被El Capitan的系统完整性保护制度打破了。 – Olsonist

+1

@Olsonist与dtrace相同的问题:'当前的安全限制(无根启用)阻止dtrace附加到未使用[com.apple.security.get-task-allow]权利签名的可执行文件 – Nakilon

+1

可能会禁用SIP https://developer.apple.com/library/content/documentation/Security/Conceptual/System_Integrity_Protection_Guide/ConfiguringSystemIntegrityProtection/ConfiguringSystemIntegrityProtection.html – mttrb

6

在当前版本的macOS下,SIP覆盖的路径下的可执行文件(如/usr/bin)无法跟踪。

cp /usr/bin/find find 
sudo dtruss ./find … 
+0

在我的情况下,复制可执行文件后,我想调试的错误停止了..( – Nakilon

+0

也许我的错误实际上是与SIP有关的,所以也是成功的。 – Nakilon