2009-07-09 42 views
8

我有在OS X上運行gprof文件test.c麻煩主機體系結構的不就是:問題與OS X gprof的:[程序]是

#include <stdio.h> 

int main() { 
    printf("Hello, World!\n"); 
    return 0; 
} 

和我的終端是這樣的:

$ gcc -pg test.c 
$ gcc -pg -o test test.c 
$ ./test 
Hello, World! 
$ gprof test 
gprof: file: test is not of the host architecture 

編輯:另外,它不生成文件gmon.out

這是怎麼回事?

+0

它是否爲您生成的是gmon.out文件?我無法用你的例子來做到這一點。 – 2009-07-09 02:42:50

+0

不,它沒有。我忘了檢查這個。我想這意味着問題開始較早? – 2009-07-09 02:54:16

回答

9

該系列在這裏的事件應該工作如下:

  1. 使用-pg選項編譯代碼
  2. 與-pg選項
  3. 鏈接代碼
  4. 運行程序
  5. 程序生成是gmon.out文件
  6. 運行gprof

問題是,第4步永遠不會發生。有關這種特定故障的信息很少。過去幾年的普遍共識似乎是蘋果寧願用鯊魚來代替,而且他們一直在用gprof來修復bug等問題。

簡而言之:安裝Xcode中,man shark

3

聽起來像test是使用gprof並不期望的架構構建的。請嘗試以下操作:

$ cat > test2.c 
#include <stdio.h> 
int main() { printf("test\n"); return 0; } 
^D 
$ gcc -arch i386 -pg -o test2 test2.c 
$ file test2 
test2: Mach-O executable i386 
$ ./test2 
test 
$ gprof test2 
... bunch of output ... 
$ gcc -arch ppc -pg -o test2 test2.c 
$ file test2 
test: Mach-O executable ppc 
$ ./test2 
test 
$ gprof test2 
gprof: file: test2 is not of the host architecture 
$ arch -ppc gprof test2 
... same bunch of output ... 

較新的MacOS支持從IBM PPC和Intel x86架構運行可執行文件。一些工具鏈似乎對此有點密集。 Gprof似乎期望可執行文件位於本地體系結構中。但是,如果您使用arch實用程序強制執行非本地體系結構,那麼它似乎可以正常工作。剛纔有一個discussion about this in another context。我包括一些有用的鏈接和更多的信息。

+0

當我使用-arch i386或-arch ppc編譯時,我從gprof中得到同樣的錯誤(並且在任何一種情況下都不會生成gmon.out文件) – 2009-07-09 03:23:15

+0

這很奇怪......通常一個或另一個都可以工作。你運行什麼硬件和操作系統版本?該錯誤肯定是由可執行文件體系結構和主機體系結構之間的不匹配造成的。這在我的MacBook Pro上的_UNIVERSAL FILE SUPPORT_下的`gprof`手冊頁中明確提到 - Intel Core 2 Duo,OS 10.5.7。 您也可以使用不帶參數的`arch`來查看本機體系結構,並查看`gcc -v`來查看編譯器的`--target =`規範是什麼。 – 2009-07-09 03:34:20

4

不幸的是,gprof在Mac OS X上無法正常工作,您可能需要使用Shark。它是/Developer/Applications/Performance Tools/Shark中開發人員工具的一部分。

更新:似乎gprof現在正在使用最新的開發工具在Mac OS X 10.6(Snow Leopard)上工作。