9

gprof在 OS X 上运行时遇到问题。文件test.c是:

#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

这里发生了什么?

4

3 回答 3

9

这里的一系列事件应该如下工作:

  1. -pg使用选项编译代码
  2. 链接代码与-pg选项
  3. 运行程序
  4. 程序生成gmon.out文件
  5. gprof

问题是第 4 步永远不会发生。关于这个特定故障的信息很少。过去几年的普遍共识似乎是,Apple 宁愿使用 Shark 代替,而且他们在修复 bug 等方面非常松懈gprof

简而言之:安装 Xcode,man shark

于 2009-07-09T03:11:46.400 回答
4

不幸的是gprof,它不适用于 Mac OS X。您可能想Shark改用它。它是/Developer/Applications/Performance Tools/Shark.

更新:似乎gprof现在正在使用最新的开发人员工具在 Mac OS X 10.6 (Snow Leopard) 上运行。

于 2009-07-09T03:07:37.670 回答
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实用程序强制执行非本机架构,那么它似乎可以正常工作。不久前在另一种情况下对此进行了讨论。我在那里提供了一些有用的链接和更多信息。

于 2009-07-09T03:05:57.953 回答