Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any way to specify the location of profile data

Tags:

linux

gcc

gprof

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?

I'm using gcc 3.4.6 on i386/linux2.6

like image 646
hhafez Avatar asked Jan 21 '09 04:01

hhafez


3 Answers

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.

like image 170
jscoot Avatar answered Sep 26 '22 00:09

jscoot


jscoot's solution worked for me, with the important difference of setting GMON_OUT_PREFIX at execution time, not at compile time.

like image 37
Sassan Panahinejad Avatar answered Sep 22 '22 00:09

Sassan Panahinejad


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
like image 24
Srikanth Avatar answered Sep 23 '22 00:09

Srikanth