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:
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
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.