This is the mail archive of the
mailing list for the GCC project.
Re: gmon.out creation procedure
- From: "Mohamed Shafi" <shafitvm at gmail dot com>
- To: raja dot saleru at iap-online dot com
- Cc: gcc at gcc dot gnu dot org, iant at google dot com
- Date: Mon, 19 May 2008 19:37:03 +0530
- Subject: Re: gmon.out creation procedure
- References: <firstname.lastname@example.org>
> 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
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