Skip to content

uftrace for gcc compiler

Honggyu Kim edited this page Oct 23, 2018 · 8 revisions

1. Download gcc-8.2.0 and uncompress

$ wget https://ftp.gnu.org/gnu/gcc/gcc-8.2.0/gcc-8.2.0.tar.gz
$ tar xfz gcc-8.2.0.tar.gz

2. Prepare external prerequisite projects

$ cd gcc-8.2.0
$ ./contrib/download_prerequisites
$ cd ..

3. Configuration

$ mkdir -p gcc-8.2.0-build sysroot.pg
$ cd gcc-8.2.0-build
$ ../gcc-8.2.0/configure --prefix=`realpath ../sysroot.pg` \
                         --enable-languages=c,c++ \
                         --disable-multilib \
                         --disable-bootstrap \
                         CFLAGS="-pg -g -fno-omit-frame-pointer" \
                         CXXFLAGS="-pg -g -fno-omit-frame-pointer"

4. Compilation and install

$ make -j8 CFLAGS="-pg -g -fno-omit-frame-pointer" CXXFLAGS="-pg -g -fno-omit-frame-pointer"
$ make install

5. Test the generated gcc image

$ cd ../sysroot.pg/bin

$ ./gcc
gcc: fatal error: no input files
compilation terminated.

$ nm gcc | grep mcount
                 U mcount@@GLIBC_2.2.5

6. Run gcc execution with uftrace

$ uftrace -F main -D 3 -- ./gcc
gcc: fatal error: no input files
compilation terminated.
# DURATION     TID     FUNCTION
            [ 14960] | main() {
   0.553 us [ 14960] |   driver::driver();
            [ 14960] |   driver::main() {
   5.544 us [ 14960] |     driver::set_progname();
  55.517 us [ 14960] |     driver::decode_argv();
 308.033 us [ 14960] |     driver::global_initializations();
   4.450 us [ 14960] |     driver::build_multilib_strings();
 956.142 us [ 14960] |     driver::set_up_specs();
   4.497 us [ 14960] |     driver::putenv_COLLECT_GCC();
  26.267 us [ 14960] |     driver::maybe_putenv_COLLECT_LTO_WRAPPER();
   0.487 us [ 14960] |     driver::maybe_putenv_OFFLOAD_TARGETS();
   0.233 us [ 14960] |     driver::handle_unrecognized_options();
   0.527 us [ 14960] |     driver::maybe_print_and_exit();
            [ 14960] |     driver::prepare_infiles() {
            [ 14960] |       /* linux:task-exit */

uftrace stopped tracing with remaining functions
================================================
task: 14960
[2] driver::prepare_infiles
[1] driver::main
[0] main

7. Run gcc with uftrace --auto-args

$ uftrace -F main -D 3 --auto-args -- ./gcc
gcc: fatal error: no input files
compilation terminated.
# DURATION     TID     FUNCTION
            [ 18041] | main(1, 0x7ffd6ea69388) {
   0.633 us [ 18041] |   driver::driver(0x7ffd6ea69270, 0, 0);
            [ 18041] |   driver::main(0x7ffd6ea69270, 1, 0x7ffd6ea69388) {
 333.397 us [ 18041] |     driver::set_progname(0x7ffd6ea69270, "./gcc");
  62.744 us [ 18041] |     driver::decode_argv(0x7ffd6ea69270, 1, 0x7ffd6ea69388);
 368.757 us [ 18041] |     driver::global_initializations(0x7ffd6ea69270);
  10.634 us [ 18041] |     driver::build_multilib_strings(0x7ffd6ea69270);
 864.179 us [ 18041] |     driver::set_up_specs(0x7ffd6ea69270);
  11.881 us [ 18041] |     driver::putenv_COLLECT_GCC(0x7ffd6ea69270, "./gcc");
  30.307 us [ 18041] |     driver::maybe_putenv_COLLECT_LTO_WRAPPER(0x7ffd6ea69270);
   0.837 us [ 18041] |     driver::maybe_putenv_OFFLOAD_TARGETS(0x7ffd6ea69270);
   0.337 us [ 18041] |     driver::handle_unrecognized_options(0x7ffd6ea69270);
   0.653 us [ 18041] |     driver::maybe_print_and_exit(0x7ffd6ea69270) = 1;
            [ 18041] |     driver::prepare_infiles(0x7ffd6ea69270) {
            [ 18041] |       /* linux:task-exit */

uftrace stopped tracing with remaining functions
================================================
task: 18041
[2] driver::prepare_infiles
[1] driver::main
[0] main

8. Visualized trace output of gcc

gcc.svg

Clone this wiki locally