public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* gmon.out creation procedure
@ 2008-05-19 12:04 raja.saleru
  2008-05-19 14:07 ` Mohamed Shafi
  0 siblings, 1 reply; 4+ messages in thread
From: raja.saleru @ 2008-05-19 12:04 UTC (permalink / raw)
  To: gcc, iant; +Cc: shafitvm

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 ?

2. Can you brief how profile information required to create gmon.out is
captured?¡¡Which are the functions are responsible for this ?

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?

Thanks and Regards
Raja Saleru

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gmon.out creation procedure
  2008-05-19 12:04 gmon.out creation procedure raja.saleru
@ 2008-05-19 14:07 ` Mohamed Shafi
  2008-05-20  8:24   ` raja.saleru
  0 siblings, 1 reply; 4+ messages in thread
From: Mohamed Shafi @ 2008-05-19 14:07 UTC (permalink / raw)
  To: raja.saleru; +Cc: gcc, iant

2008/5/19  <raja.saleru@iap-online.com>:
> 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
target

>
> 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
gcc).
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
gmon.out

Hope this helps,

Regards,
Shafi

>
> Thanks and Regards
> Raja Saleru
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gmon.out creation procedure
  2008-05-19 14:07 ` Mohamed Shafi
@ 2008-05-20  8:24   ` raja.saleru
  2008-05-21  6:56     ` Mohamed Shafi
  0 siblings, 1 reply; 4+ messages in thread
From: raja.saleru @ 2008-05-20  8:24 UTC (permalink / raw)
  To: Mohamed Shafi; +Cc: raja.saleru, gcc, iant

Dear Shafi

Thanks you very much for the clear details. Definitely your inputs are
helpful.

1) I am sure that in gcc-4.0 I found there is file gmon.c in the path
gcc-4.0.0/gcc/gmon.c.  Anyhow let me concentrate on gmon.c of glibc.

2) Next thing I would like to know is to better understand the gmon.c of
glibc I would like to degug glibc. since glibc is linked with gcc, I built
gcc and glibc separately. while debugging gcc is referring shared glib
library, but not the one I built freshly for debugging purpose. To  make
this happen, where I need to change the path to like both gcc and glibc ?

3) Please correct me If I am wrong
   a. for every function mcount() function is called to collect the caller
and callee address. where this collected info is placed ?
   b. the flow of monstartup() function
                monstartup()-->moncontrol() --> profil()

      who will call the monstartup() ? is it gcrt0 ? before calling the
main() function of our routine ?

   c. write_profiling() --->  write_gmon() functions calls write_hist(),
write_call_graph() and write_bb_counts(). here who calls the
write_profiling() ?

   d. mcleanup() calls write_gmon(). who calls the mcleanup() ? is it
gcrt0 ? after control return from main() function ?

Thanks and Regards
Raja








> 2008/5/19  <raja.saleru@iap-online.com>:
>> 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
> target
>
>>
>> 2. Can you brief how profile information required to create gmon.out is
>> captured?&#65533;&#65533;&#65533;"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
> gcc).
> 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 &#65533;&#65533;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
> gmon.out
>
> Hope this helps,
>
> Regards,
> Shafi
>
>>
>> Thanks and Regards
>> Raja Saleru
>>
>>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: gmon.out creation procedure
  2008-05-20  8:24   ` raja.saleru
@ 2008-05-21  6:56     ` Mohamed Shafi
  0 siblings, 0 replies; 4+ messages in thread
From: Mohamed Shafi @ 2008-05-21  6:56 UTC (permalink / raw)
  To: raja.saleru; +Cc: gcc, iant

On Tue, May 20, 2008 at 1:54 PM,  <raja.saleru@iap-online.com> wrote:
> Dear Shafi
>
> Thanks you very much for the clear details. Definitely your inputs are
> helpful.
>
> 1) I am sure that in gcc-4.0 I found there is file gmon.c in the path
> gcc-4.0.0/gcc/gmon.c.  Anyhow let me concentrate on gmon.c of glibc.
>
   I am  not sure why this is found in gcc. It is not available in
other versions.

> 2) Next thing I would like to know is to better understand the gmon.c of
> glibc I would like to degug glibc. since glibc is linked with gcc, I built
> gcc and glibc separately. while debugging gcc is referring shared glib
> library, but not the one I built freshly for debugging purpose. To  make
> this happen, where I need to change the path to like both gcc and glibc ?

   IIRC by passing -static to linker you can link with the static
glibc. To make sure that your glibc is picked up maybe you can hide
the other glibc from the PATH variable.

>
> 3) Please correct me If I am wrong
>   a. for every function mcount() function is called to collect the caller
> and callee address. where this collected info is placed ?
>   b. the flow of monstartup() function
>                monstartup()-->moncontrol() --> profil()
>
>      who will call the monstartup() ? is it gcrt0 ? before calling the
> main() function of our routine ?

  Thats right. Thats the other thing that happen when -pg option is
provided. A different startup files is used. This will have a call to
the monstartup. monstartup will initialize all the data structures
required for collecting profile data and invokes profil system call.

>
>   c. write_profiling() --->  write_gmon() functions calls write_hist(),
> write_call_graph() and write_bb_counts(). here who calls the
> write_profiling() ?
>
>   d. mcleanup() calls write_gmon(). who calls the mcleanup() ? is it
> gcrt0 ? after control return from main() function ?

IIRC it is mcleanup that calls the output function write_gmon, which
in turn calls the other functions. mcleanup will be called from the
startup file after main returns. mcleanup dumps all the information in
the output file.

Hope this helps.

Regards,
Shafi
>
> Thanks and Regards
> Raja
>
>
>
>
>
>
>
>
>> 2008/5/19  <raja.saleru@iap-online.com>:
>>> 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
>> target
>>
>>>
>>> 2. Can you brief how profile information required to create gmon.out is
>>> captured?&#65533;&#65533;&#65533;"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
>> gcc).
>> 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 &#65533;&#65533;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
>> gmon.out
>>
>> Hope this helps,
>>
>> Regards,
>> Shafi
>>
>>>
>>> Thanks and Regards
>>> Raja Saleru
>>>
>>>
>>
>
>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-05-21  6:56 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-19 12:04 gmon.out creation procedure raja.saleru
2008-05-19 14:07 ` Mohamed Shafi
2008-05-20  8:24   ` raja.saleru
2008-05-21  6:56     ` Mohamed Shafi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).