gprof for profiling standard libraries

Jan 2, 2015 at 9:30pm
Hello, I'm new to profiling, and in general terminal software testing tools, and am trying to understand how to profile a library function against my own function, in this case in gprof. I have googled a bit and seen that people have said you must statically link any standard library in order to do this but am getting no results. My code without the headers is:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
long myPow(int n, int r)
{
    assert(r > 0);

    int product = 1;
    for (int i = 0; i < r; i++)
        product *= n;
        
    return product;
}

int main(void)
{
    srand(time(NULL));
    int x = rand() % 100 + 1;
    int y = rand() % 100 + 1;

        long my, other;
    for (int i = 0; i < 100; i++)
        my = myPow(x, y);
    for (int i = 0; i < 100; i++)
        other = pow(x, y);
    
    return 0;
}


I ran this against:
gcc -pg -std=c11 -static -o workbench workbench.c -lm
followed by:
gprof workbench gmon.out > res.txt
but only get the following statistics
1
2
3
4
 %   cumulative   self              self     total           
  7  time   seconds   seconds    calls  Ts/call  Ts/call  name    
  8   0.00      0.00     0.00      100     0.00     0.00  myPow
  9   0.00      0.00     0.00        1     0.00     0.00  main


How can I get math's pow function to show?
Jan 2, 2015 at 11:50pm
Perhaps by adding -fno-builtin to your compilation options.

May be informative:
http://stackoverflow.com/questions/23930588/how-gcc-handles-built-in-function
Jan 3, 2015 at 1:59am
Unforunately, I get the same results. I'm starting to think this I may be missing a gprof option or something.
Jan 3, 2015 at 2:57am
Ok, so I think I'm getting a little closer to the solution. Under some documentation of gprof it states "In addition, you would probably want to specify the profiling C library, `/usr/lib/libc_p.a', by writing `-lc_p' instead of the usual `-lc'". Unfortunately I don't have a _p version of libm under my Ubuntu distribution's libm's lib directory. I have no idea how to obtain these binaries if even possible, starting to believe I'm going to have to compile gcc from source.
Anyone have any ideas as to what my options are from here? While I'm at it should I remove gcc before building from source? Is there any easy way to easily maintain source packages for upgrades and removal?

Thank you all for your time to whomever is reading.
Topic archived. No new replies allowed.