0

In spite of compiling my code with -pg flag set, I am unable to view the complete details of the gprof output from gmon.out

Specifically, I am not getting the details of calls, self Ts/call and total Ts/call.

This is the output of gprof deepflow-static gmon.out :

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  Ts/call  Ts/call  name    
 52.72      7.18     7.18                             sor_coupled
 34.07     11.82     4.64                             compute_data_and_match
  2.28     12.13     0.31                             convolve_vert
  2.28     12.44     0.31                             compute_smoothness
  2.06     12.72     0.28                             convolve_horiz
  1.47     12.92     0.20                             color_image_resize_vert
  1.03     13.06     0.14                             sub_laplacian
  0.88     13.18     0.12                             image_resize_vert
  0.88     13.30     0.12                             image_warp
  0.73     13.40     0.10                             color_image_resize_horiz
  0.59     13.48     0.08                             image_resize_horiz
  0.18     13.51     0.03                             frexp
  0.15     13.53     0.02                             compute_one_level
  0.15     13.55     0.02                             fwrite
  0.15     13.57     0.02                             memcpy
  0.11     13.58     0.02                             __floorf_sse41
  0.07     13.59     0.01                             brk
  0.07     13.60     0.01                             color_image_png_load
  0.07     13.61     0.01                             get_derivatives
  0.07     13.62     0.01                             png_read_filter_row_paeth_multibyte_pixel

 %         the percentage of the total running time of the
time       program used by this function.

cumulative a running sum of the number of seconds accounted
 seconds   for by this function and those listed above it.

 self      the number of seconds accounted for by this
seconds    function alone.  This is the major sort for this
           listing.

calls      the number of times this function was invoked, if
           this function is profiled, else blank.

 self      the average number of milliseconds spent in this
ms/call    function per call, if this function is profiled,
       else blank.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this 
       function is profiled, else blank.

name       the name of the function.  This is the minor sort
           for this listing. The index shows the location of
       the function in the gprof listing. If the index is
       in parenthesis it shows where it would appear in
       the gprof listing if it were to be printed.


Copyright (C) 2012 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

This is my Makefile :

CC=gcc
CFLAGS=-Wall -g -O3
LDFLAGS=-g -Wall -O3
LIBFLAGS=-lm -ljpeg -lpng -pg
LIBAFLAGS=-static /usr/lib/x86_64-linux-gnu/libjpeg.a /usr/local/lib/libpng16.a /usr/lib/x86_64-linux-gnu/libz.a /usr/lib/x86_64-linux-gnu/libm.a

all: deepflow-static

deepflow: deepflow.o image.o io.o opticalflow_aux.o opticalflow.o solver.o
$(CC) $(LDFLAGS) $(LIBFLAGS) -o $@ $^

deepflow-static: deepflow.o image.o io.o opticalflow_aux.o opticalflow.o solver.o
$(CC) $(LIBFLAGS) -o $@ $^ $(LIBAFLAGS)

%.o: %.c
$(CC) -o $@ $(CFLAGS) -c $+ 

clean:
rm -f *.o deepflow

Please help me in figuring out what is missing. Thanks in advance

Swaroop
  • 1,219
  • 3
  • 16
  • 32
  • As rightly pointed out by BlunT, in the Makefile, I didn't add -pg option to CFLAGS, which was causing all this incomplete output. – Swaroop Aug 21 '15 at 15:54
  • I'm curious - how did you learn about `gprof`? Did a teacher recommend it? – Mike Dunlavey Aug 21 '15 at 17:12
  • @MikeDunlavey I wanted to identify the compute intensive parts of the program, and I was earlier using `perf` tool, but my advisor advised me to use `gprof`, as it is better suited for this task. Thats when I got into using `gprof`. – Swaroop Aug 22 '15 at 06:16
  • OK, thanks. You might want to relay to your adviser the second answer on [*this post*](https://archive.is/9r927). There are better ways to find out how to speed up your program. – Mike Dunlavey Aug 22 '15 at 12:11

1 Answers1

1

This has happened to me when the application being run with gprof was not terminating successfully.

The generation of the analysis file could not complete as the information was not fully written to gmon.out.

Try exiting the program after a few lines with:

        exit(EXIT_SUCCESS);

And check whether or not the file is correctly generated.

You can also run the program through gdb.

I am not a Makefile expert, but you should be using the -pg flag on two steps:

GPROF=-pg

all: $(SOURCES) $(EXECUTABLE)

$(EXECUTABLE): $(OBJECTS) 
    $(CC) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBS) $(GPROF)

.cpp.o:
    $(CC) $(CPPFLAGS) $(CFLAGS) $< -o $@ $(GPROF)
Miguel Mesquita Alfaiate
  • 2,851
  • 5
  • 30
  • 56
  • It seems to me that the program is normally terminating. Is there any specific way to check for termination status for a program ? – Swaroop Aug 21 '15 at 09:04
  • I have run my code by inserting exit(EXIT_SUCCESS) at various places, but the gprof details are still missing. – Swaroop Aug 21 '15 at 09:21
  • @GuruSwaroop have you tried running gdb and / or valgrind to check if you find any error? – Miguel Mesquita Alfaiate Aug 21 '15 at 09:36
  • I just executed my program along with gdb and this is the output [Inferior 1 (process 10479) exited normally] – Swaroop Aug 21 '15 at 15:06
  • @GuruSwaroop then you're program is executing normally, so the issue must be somewhere else. is this the command you're executing for generating the report: `gprof [executable] gmon.out > [ReportFile]` ? – Miguel Mesquita Alfaiate Aug 21 '15 at 15:32
  • Yeah problem was in the Makefile. I had to add -pg option to CFLAGS. Bingo. – Swaroop Aug 21 '15 at 15:52