0

I am trying to gprof my program. I want a line-by-line profiling. However, I can't seem to get the syntax right. I am using "make" and not "gcc" so please help only with suggestions that fit make. I wouldbe very grateful if you can give me the full "make" syntax. Based on this website: http://sourceware.org/binutils/docs/gprof/Output-Options.html[^] http://sourceware.org/binutils/docs/gprof/Line_002dby_002dline.html[^] Here is what I am inputting:

make USE_LOCAL_HEADERS=0 LDFLAGS='-L.' BASE_CFLAGS=-m32 CFLAGS='-fopenmp -pg -l -g'

The output is:

/usr/bin/ld: cannot find -l-g
collect2: ld returned 1 exit status
make[2]: *** [build/release-linux-ppc64/ioquake3.ppc64] Error 1
make[2]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/svfb_201110271440/ioquake3dev_clean'
make[1]: *** [targets] Error 2
make[1]: Leaving directory `/r/home7/yasir/minoru/cfe2/yasirTemp/ioquake3dev/svfb_201110271440/ioquake3dev_clean'
make: *** [release] Error 2

I need option "-l", "-g" and "-pg".

alk
  • 69,737
  • 10
  • 105
  • 255
user598208
  • 217
  • 3
  • 6
  • 15
  • 3
    What do you believe the `-l` flag should be doing? It usually means to include a shared library, whose name you specify right after. Instead, you have `-g` to enable debugging. – phs Nov 18 '11 at 06:18
  • gprof isn't going to give you line-by-line information. It tells how many times program counter samples land inside each function, and counts how many times A calls B. From that it *tries* to make useful summary. It is blind to any time spent in system calls like I/O. *[Here's how it works.](http://stackoverflow.com/questions/4981121/how-exactly-does-gprof-work/5046039#5046039)* – Mike Dunlavey Nov 21 '11 at 14:50

3 Answers3

3

-pg enables profiling, -g includes symbol names which help interpreting the profile generated.

The -pg option needs to be passed to compiler and linker.

The -l command does not make sense in the way you are using it, as it needs a library name as parameter, so as long as you do not provide one, leave the -l away.

Also during development I'd recommend the -Wall option to enable all warnings during compilation.

So you might try this make command:

make USE_LOCAL_HEADERS=0 LDFLAGS='-L. -pg' BASE_CFLAGS=-m32 CFLAGS='-fopenmp -pg -g -Wall'
alk
  • 69,737
  • 10
  • 105
  • 255
  • Thank you guys for those helpful answers! However, I would like to use gprof to see which lines get executed the most within my program. Thats why I wanted to use the "-l" option. I found something else called gcov, but I cannot make sense of how to use it since it has to execute EVERY and EACH *.c file!!! Anyone has any ideas on how to achieve what I need? – user598208 Nov 21 '11 at 03:54
  • The `-l` option is what's causing the error. Remove it, and gprof will work. To use gcov, add `-ftest-coverage -fprofile-arcs`. For both gprof and gcov you'll need to recompile the whole project. – ams Nov 21 '11 at 14:18
1

You can pass most of those as environment variables, make "should" do the right thing and use them for the compiler:

$ USE_LOCAL_HEADERS=0 \
LDFLAGS='-L.' \
BASE_CFLAGS=-m32 \
CFLAGS='-fopenmp -pg -g' \
make

That will USE_LOCAL_HEADERS, LDFLAGS, BASE_CFLAGS and CFLAGS as environment variables which make and gcc can see. You may have to edit your Makefile to combine them in the correct ways for what you want.

IanNorton
  • 7,145
  • 2
  • 25
  • 28
  • That does nothing useful, and maybe breaks things even worse - command line variables override variables defined within the makefile, which in turn override environment (unless you use `-e`, which you didn't). – ams Nov 21 '11 at 14:16
  • @ams what do you mean? This is always how GNU make has worked, http://www.gnu.org/s/hello/manual/make/Environment.html – IanNorton Nov 22 '11 at 06:21
-1

make is simply a "to determine automatically which pieces of a large program need to be recompiled, and issue the commands to recompile them" (man make). It looks like make cannot make sense of your arguments; it doesn't actually get to run any commands before it encounters an error.

I'm sorry I can't help you any further, but your problem is within your make file or similar. You should read up on what a make file is, and how to gprof your program and understand the difference between make and gcc, and reevaluate what you are trying to do. Make may not be useuful to you.

BudgieInWA
  • 2,184
  • 1
  • 17
  • 31