The default the profile file is from the executable is run and the file is called gmon.out
. Is there any way to specify a new location?
默认情况下,配置文件来自可执行文件,该文件名为gmon.out。有没有办法指定新的位置?
I'm using gcc 3.4.6 on i386/linux2.6
我在i386 / linux2.6上使用gcc 3.4.6
4 个解决方案
#1
15
Too badly, the environment variable GMON_OUT_PREFIX
is not documented in the glibc. I got the following information from the web and tested on my machine.
太糟糕了,glibc中没有记录环境变量GMON_OUT_PREFIX。我从网上获得了以下信息,并在我的机器上进行了测试。
if you set the environment variable GMON_OUT_PREFIX
, then the output file is named as ${GMON_OUT_PREFIX}.[PID]
, the pid is the id of the profiled process.
如果设置环境变量GMON_OUT_PREFIX,则输出文件命名为$ {GMON_OUT_PREFIX}。[PID],pid是配置文件进程的id。
For example:
例如:
GMON_OUT_PREFIX=mygmon; gcc -o foo -pg foo.c
the gmon out file is: mygmon.12345
, assuming the foo process id=12345.
gmon out文件是:mygmon.12345,假设foo进程id = 12345。
#2
3
jscoot's solution worked for me. but setting GMON_OUT_PREFIX is important at execution time, not at compile time.
jscoot的解决方案对我有用。但设置GMON_OUT_PREFIX在执行时很重要,而不是在编译时。
#3
2
I encountered the same problem last week and I solved it in the following way. idea here is to change the process current directory to wherever you want to generate gmon.out file. file name can't be changed this way. It allows you to change where you can save the file.
上周我遇到了同样的问题,我用以下方式解决了这个问题。这里的想法是将进程当前目录更改为您要生成gmon.out文件的位置。文件名不能这样改变。它允许您更改保存文件的位置。
#ifdef GPROF
/* so we can gprof */
if (1) {
char tmpdir[32];
snprintf(tmpdir, 32, "/tmp/%05d", mypid);
mkdir(tmpdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
chdir(tmpdir);
}
#endif
#4
1
To give a different file name to gprof:
为gprof提供不同的文件名:
gprof a.out gprof-foo.out
As to renaming them, set the GMON_OUT_PREFIX environment variable. I found this one by good ol' objdump on libc .... Naturally, the libc docs say nothing.
至于重命名它们,设置GMON_OUT_PREFIX环境变量。我在libc上发现了这个很好的'objdump ....自然,libc文档什么也没说。
#1
15
Too badly, the environment variable GMON_OUT_PREFIX
is not documented in the glibc. I got the following information from the web and tested on my machine.
太糟糕了,glibc中没有记录环境变量GMON_OUT_PREFIX。我从网上获得了以下信息,并在我的机器上进行了测试。
if you set the environment variable GMON_OUT_PREFIX
, then the output file is named as ${GMON_OUT_PREFIX}.[PID]
, the pid is the id of the profiled process.
如果设置环境变量GMON_OUT_PREFIX,则输出文件命名为$ {GMON_OUT_PREFIX}。[PID],pid是配置文件进程的id。
For example:
例如:
GMON_OUT_PREFIX=mygmon; gcc -o foo -pg foo.c
the gmon out file is: mygmon.12345
, assuming the foo process id=12345.
gmon out文件是:mygmon.12345,假设foo进程id = 12345。
#2
3
jscoot's solution worked for me. but setting GMON_OUT_PREFIX is important at execution time, not at compile time.
jscoot的解决方案对我有用。但设置GMON_OUT_PREFIX在执行时很重要,而不是在编译时。
#3
2
I encountered the same problem last week and I solved it in the following way. idea here is to change the process current directory to wherever you want to generate gmon.out file. file name can't be changed this way. It allows you to change where you can save the file.
上周我遇到了同样的问题,我用以下方式解决了这个问题。这里的想法是将进程当前目录更改为您要生成gmon.out文件的位置。文件名不能这样改变。它允许您更改保存文件的位置。
#ifdef GPROF
/* so we can gprof */
if (1) {
char tmpdir[32];
snprintf(tmpdir, 32, "/tmp/%05d", mypid);
mkdir(tmpdir, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH);
chdir(tmpdir);
}
#endif
#4
1
To give a different file name to gprof:
为gprof提供不同的文件名:
gprof a.out gprof-foo.out
As to renaming them, set the GMON_OUT_PREFIX environment variable. I found this one by good ol' objdump on libc .... Naturally, the libc docs say nothing.
至于重命名它们,设置GMON_OUT_PREFIX环境变量。我在libc上发现了这个很好的'objdump ....自然,libc文档什么也没说。