2015-06-25 69 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