https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95348
Bug ID: 95348
Summary: GCC records zero functions and modules in the
profiling data file, ICC does NOT
Product: gcc
Version: 11.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: gcov-profile
Assignee: unassigned at gcc dot gnu.org
Reporter: qinzhao at gcc dot gnu.org
CC: marxin at gcc dot gnu.org
Target Milestone: ---
when using GCC and ICC to build a big parallel application with profiling
feedback, the size of the profiling feedback data of GCC is over 20x times
larger than that of ICC.
As we studied, one of the major reason for this size difference is:
GCC records all functions and modules that execute 0 times, but ICC does NOT.
since I cannot expose the details of the real application that has the
profiling data size issue. I come up with a small testing case to show this
problem.
******testing case:
[]$ cat lib.h
void five (int);
void ten (int);
[]$ cat lib.c
#include <stdio.h>
void five(int n) {
if (n > 5) {
printf("%d is greater than five\n", n);
} else {
printf("%d is not greater than five\n", n);
}
}
void ten(int n) {
if (n > 10) {
printf("%d is greater than ten\n", n);
} else {
printf("%d is not greater than ten\n", n);
}
}
[]$ cat ten.c
#include <stdlib.h>
#include "lib.h"
int main(int argc, char *argv[]) {
if (argc != 2) {
return 2;
}
int n = atoi(argv[1]);
ten(n);
return 0;
}
[]$ cat five.c
#include "lib.h"
void foo(int n) {
if (n > 0)
five(n);
return;
}
******ICC :
[]$ cat build_it_icc
#!/bin/bash
ICC=/ICC-install-dir/bin/icc
opt="-O0 "
opt_gen="-prof_gen"
opt_gen="$opt_gen -prof_dir ./icc_prof_dir"
tf1="five.c"
tf2="ten.c"
libf="lib.c"
rm *.o ten
rm -rf icc_prof_dir
mkdir icc_prof_dir
echo $ICC $opt $opt_gen -c $tf1 -o five.o
$ICC $opt $opt_gen -c $tf1 -o five.o
echo $ICC $opt $opt_gen -c $libf -o lib.o
$ICC $opt $opt_gen -c $libf -o lib.o
echo $ICC $opt $opt_gen -c $tf2 -o ten.o
$ICC $opt $opt_gen -c $tf2 -o ten.o
echo $ICC $opt $opt_gen ten.o five.o lib.o -o ten
$ICC $opt $opt_gen ten.o five.o lib.o -o ten
./ten 12
echo "Done"
[]$ sh build_it_icc
then we got the profiling data under
./icc_prof_dir/5ec6e83f_78751.dyn
using
/ICC-install-dir/bin/profmerge -dump 5ec6e83f_78751.dyn > data
we can see, only two functions, "main" in ten.c, and "ten" in lib.c have
records in this profiling data file.
******GCC: with latest upstream gcc11:
[]$ cat build_it_gcc
#!/bin/bash
GCC=/GCC-install-dir/bin/gcc
opt="-O0 "
opt="$opt -fno-inline"
opt_gen="-fprofile-generate"
opt_gen="$opt_gen -fprofile-dir=gcc_prof_dir/%p"
tf1="five.c"
tf2="ten.c"
libf="lib.c"
rm -rf gcc_prof_dir
echo $GCC $opt $opt_gen -c $libf
$GCC $opt $opt_gen -c $libf -o lib.o
echo $GCC $opt $opt_gen $tf1
$GCC $opt $opt_gen -c $tf1 -o five.o
echo $GCC $opt $opt_gen $tf2
$GCC $opt $opt_gen -c $tf2 -o ten.o
echo $GCC $opt $opt_gen ten.o five.o lib.o -o ten
$GCC $opt $opt_gen ten.o five.o lib.o -o ten
./ten 12
echo "Done"
[]$ build_it_gcc
then the profiling data are under
./gcc_prof_dir/16856
under ~/Bugs/profile/small_gcc/gcc_prof_dir/16856
[]$ ls -l
total 12
-rw-r--r-- 1 qinzhao qinzhao 100 May 26 19:18
#home#qinzhao#Bugs#profile#small_gcc#five.gcda
-rw-r--r-- 1 qinzhao qinzhao 184 May 26 19:18
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda
-rw-r--r-- 1 qinzhao qinzhao 100 May 26 19:18
#home#qinzhao#Bugs#profile#small_gcc#ten.gcda
[]$ /home/qinzhao/Install/latest/bin/gcov-dump *.gcda
#home#qinzhao#Bugs#profile#small_gcc#five.gcda:data:magic `gcda':version
`B10e'
#home#qinzhao#Bugs#profile#small_gcc#five.gcda:stamp 1375590637
#home#qinzhao#Bugs#profile#small_gcc#five.gcda: a1000000: 2:OBJECT_SUMMARY
runs=1, sum_max=1
#home#qinzhao#Bugs#profile#small_gcc#five.gcda: 01000000: 3:FUNCTION
ident=1636255671, lineno_checksum=0x13fda123, cfg_checksum=0xc7b3f828
#home#qinzhao#Bugs#profile#small_gcc#five.gcda: 01a10000: 6:COUNTERS
arcs 3 counts
#home#qinzhao#Bugs#profile#small_gcc#five.gcda: 01af0000: 2:COUNTERS
time_profiler 1 counts
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda:data:magic `gcda':version
`B10e'
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda:stamp 1375590591
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda: a1000000: 2:OBJECT_SUMMARY
runs=1, sum_max=1
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda: 01000000: 3:FUNCTION
ident=1977925159, lineno_checksum=0x5bf41dc5, cfg_checksum=0xf9e50e8f
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda: 01a10000: 8:COUNTERS arcs
4 counts
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda: 01af0000: 2:COUNTERS
time_profiler 1 counts
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda: 01000000: 3:FUNCTION
ident=193180204, lineno_checksum=0x020d7b16, cfg_checksum=0xf9e50e8f
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda: 01a10000: 8:COUNTERS arcs
4 counts
#home#qinzhao#Bugs#profile#small_gcc#lib.gcda: 01af0000: 2:COUNTERS
time_profiler 1 counts
#home#qinzhao#Bugs#profile#small_gcc#ten.gcda:data:magic `gcda':version
`B10e'
#home#qinzhao#Bugs#profile#small_gcc#ten.gcda:stamp 1375590675
#home#qinzhao#Bugs#profile#small_gcc#ten.gcda: a1000000: 2:OBJECT_SUMMARY
runs=1, sum_max=1
#home#qinzhao#Bugs#profile#small_gcc#ten.gcda: 01000000: 3:FUNCTION
ident=108032747, lineno_checksum=0x2fbc5f5a, cfg_checksum=0x5018cc66
#home#qinzhao#Bugs#profile#small_gcc#ten.gcda: 01a10000: 6:COUNTERS arcs
3 counts
#home#qinzhao#Bugs#profile#small_gcc#ten.gcda: 01af0000: 2:COUNTERS
time_profiler 1 counts
from the above, there are records for all functions and modules that are
instrumented, for example, the routine "five" in lib.c, and the whole module
"five.c". all the records for these are zero.
Is it possible for GCC to only record functions and modules that have non-zero
counts?