Can anybody explain to me the difference between profile-generate
and the pg
options?
Both will generate the profile data. But their usage differs.
fprofile-generate
is to generate the binary with profiling information which you can re-use to give feedback to the compiler when you compile it again with fprofile-use
.
For example:
$ gcc -fprofile-generate filename.c
If you execute the binary generated by the about command, it will produce a file called filename.gcda
with profile data.
When you compile it with fprofile-use
again:
$ gcc -fprofile-use filename.c
This time, gcc will use that data from filename.gcda
to optimize further.
When you execute the binary which was compiled with -pg
, it'll generate gmon.out
which can be later used to analyze the code using gprof
command. This is more like static analysis which will give information about code path.