This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: gmon.out creation procedure

2008/5/19  <>:
> Hi,
> I am Raja, I need a favor on understand how the gmon.out file is created.
> Please help me.
> 1. gmon.c is available in both gcc and glibc.  Which is the one used to
> create gmon.out ?

I don't think gcc has gmon.c. Only glibc has it. You can also find
gmon in newlib for some targets. But this will be customized for the

> 2. Can you brief how profile information required to create gmon.out is
> captured?ï"B"BWhich are the functions are responsible for this ?

These days gmon.c is used only to get histogram records(time related
infomation). All the other information is now produced by gcc itself,
than can be analyzed using gcov. (You will get gcov when you build
For histogram records, gmon.c code primarily uses 'profil' system
call. You can get more information about this in man pages. And of
course you will get to know how this is used if you go through the
code in gmon.c

When -pg switch is enabled all complier does is inserting a call to
the function mcount, usually after the function prologue. This is the
function the collects all the needed information. For profiling
information about caller address and callee address is necessary. If
this information cannot be obtained using __bultin_return_address then
this is calculated by mcount in a target specific manner and passed
onto another function that takes these address as the arguments and
gathers the profiling information.

> 3. Suppose assume that executable is built without ÂCpg option, but want
> to create gmon.out at run-time. Is there any way or guidelines to
> implement?

A call to the profiling function (mcount) should be there to generate
profiling information. Without that you won't be able to generate

Hope this helps,


> Thanks and Regards
> Raja Saleru

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]