Any way to specify the location of profile data

六眼飞鱼酱① 提交于 2019-12-03 10:53:35
jscoot

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.

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.

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.

jscoot's solution worked for me. but setting GMON_OUT_PREFIX is important at execution time, not at compile time.

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.

#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

To give a different file name to 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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!