public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: "Michael Pakhomov" <mpakhomo@mail.ru>
To: gcc-help@gcc.gnu.org
Subject: there is no 'main' function in gprof flat profile results
Date: Wed, 23 Oct 2002 08:22:00 -0000	[thread overview]
Message-ID: <E184NKl-000KJY-00@f7.mail.ru> (raw)

hi all,
it's quite interesting for me why gprof doesn't display 'main' function in flat profile results.
that's what i did:
1. compiled a simple application with -pg key as follows:
  g++ -o foo foo.cpp -g -pg

  pls see the code of foo.cpp below:

//====================================================================
#include <iostream.h>

// g++ -o foo foo.cpp -g -pg

//===      
const int num = 50000;
double eval_sum(int n = 200);
//====

void f1()
{
    eval_sum();
}

void f2_call_f1()
{   
    eval_sum();
    f1();
}

void f3()
{
    eval_sum();
}

double eval_sum(int n/* = 200*/){
    double sum = 0.0, fact = 1.0;
    int i, j; // loop

    // direct order
    for (i = 1; i <= n; ++i){
        fact *=  (i + 1);
        sum += 1.0 / fact;
    }


    // reset sum
    sum = 0.0;

    // indirect order
    for (i = n; i >= 1; --i){
        fact = 1.0;
        for (j = 1; j < i + 1; ++j){
            fact *= (j + 1);
        }
        sum += 1.0 / fact;
    }
    return sum;
}
 

int main (void)
{   
    cout << "start->..." << endl;
    int i, step;
    for (i = 0, step = num / 10; i < num; ++i) {
        // progress bar
        if ((i % step) == 0) {
            cout << "*" << flush;
        }
        f1();
        f2_call_f1();
        f3();
    }
    cout << endl << "finish->..." << endl;
    return 0;
}
//====================================================================

2. ran foo
3. execute 'gprof -p -b foo' and got the following output:
Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total
 time   seconds   seconds    calls  us/call  us/call  name
100.00    111.09   111.09   200000   555.45   555.45  eval_sum(int)
  0.00    111.09     0.00   100000     0.00   555.45  f1(void)
  0.00    111.09     0.00    50000     0.00  1110.90  f2_call_f1(void)
  0.00    111.09     0.00    50000     0.00   555.45  f3(void)


where is function 'main'? gprof doesn't display it in flat profile results, but display it in the call graph. than i ran gprof on another applications and found out that for some of them gprof displays 'main' and for some of them not.

i read documentation on gprof, looked in gcc/binutils maillists archive, but haven't find the answer. 
did i miss something? can somebody kindly help me?
my platform is a p4 running red hat 7.3
gcc version 2.96 20000731 (Red Hat Linux 7.3 2.96-110)
binutils-2.11.93.0.2-11
glibc-2.2.5-34

thanks in advance 

cheers
/mpakhomo

                 reply	other threads:[~2002-10-23 15:22 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E184NKl-000KJY-00@f7.mail.ru \
    --to=mpakhomo@mail.ru \
    --cc=gcc-help@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).