16

I am using Eclipse CDT under Linux, can anyone recommend a good profiler under that environment please.

I am also new to C++ and multi-thread programming, can anyone also offer some advice on how to run profiling for multi-threaded application please, e.g., what to look for performance bottleneck, etc.

Thanks.

2607
  • 4,037
  • 13
  • 49
  • 64

2 Answers2

14

I don't know if it's best choice, but it's definitely obvious one: gprof. You just need to set compilation switches right (enable gprof (-pg) for that project in project properties -> c/c++ build -> Settings -> Debugging). When you have compiled program with this options, you need to run it (until in normally exits). This generates profile file (gmon.out). There is additional plug-in you can install in eclipse, that visualizes the contents of gmon.out (go to Help -> Install -> Linux tools -> GProf integration). Just open generated gmon.out file as you would any other file, once you have that plugin installed.

dbrank0
  • 9,026
  • 2
  • 37
  • 55
  • 1
    One thing to note about GProf (maybe other tools as well), is that if you close you application using Ctrl-C (Like one usually closes a server he writes) then the gmon.out file will not be written. – kroiz Jan 12 '14 at 20:27
  • Here is http://stackoverflow.com/questions/1030829/gprof-reports-no-time-accumulated related question. Someone noted that if one of dependent libraries like stdc++ is build without -pg then not timing information could be gathered. Is it true? – Sergei Krivonos May 05 '15 at 09:50
3

As mentioned by dbrank0 you need to set the compilation option (-pg) for that project. Go to project properties -> c/c++ build -> Settings -> C++ compiler -> Debugging and check generate gpof information. When you compile the program(test_prof.c) you will get an exe file(in our case test_prof).

$ ls
test_gprof  test_gprof.c

and when you run it there will be a gmon.out file generated in the same directory.

$ ls
gmon.out  test_gprof  test_gprof.c

The gprof tool is run with the executable name and the above generated ‘gmon.out’ as argument. This produces an analysis file which contains all the desired profiling information.

$  gprof test_gprof gmon.out > analysis.txt

A file named ‘analysis.txt’ will be generated which contains all the profilig information and can be easily read out. For further details look at http://www.thegeekstuff.com/2012/08/gprof-tutorial/

Umair R
  • 820
  • 8
  • 16
  • Hi Umair, Here is http://stackoverflow.com/questions/1030829/gprof-reports-no-time-accumulated related question. Someone noted that if one of dependent libraries like stdc++ is build without -pg then not timing information could be gathered. Can you confirm or refute this, please? – Sergei Krivonos May 05 '15 at 09:54