0

I am trying 2 profile a cpp code. I compiled with -pg flags and after I profiled it to get the output I got some very weird function names. this is the make file I am using:

# Makefile for parallel simulated annealer

PREFIX=${PARSECDIR}/pkgs/kernels/canneal/inst/${PARSECPLAT}

TARGET=canneal
LIBS:=$(LIBS) -lm

CXXFLAGS+=-pg

ifdef version
  ifeq "$(version)" "pthreads"
    CXXFLAGS+=-DENABLE_THREADS -pthread
  endif
endif

all:
    $(CXX) $(CXXFLAGS) annealer_thread.cpp -c -o annealer_thread.o
    $(CXX) $(CXXFLAGS) rng.cpp -c -o rng.o
    $(CXX) $(CXXFLAGS) netlist.cpp -c -o netlist.o
    $(CXX) $(CXXFLAGS) main.cpp -c -o main.o
    $(CXX) $(CXXFLAGS) netlist_elem.cpp -c -o netlist_elem.o
    $(CXX) $(CXXFLAGS) $(LDFLAGS) *.o $(LIBS) -o $(TARGET)

clean:
    rm -f *.o $(TARGET)

install:
    mkdir -p $(PREFIX)/bin
    cp -f $(TARGET) $(PREFIX)/bin/$(TARGET)

This is a sample of the gprof output:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls   s/call   s/call  name    
 11.21      0.73     0.73  2800002     0.00     0.00  std::_Rb_tree<std::string, std::pair<std::string const, netlist_elem*>, std::_Select1st<std::pair<std::string const, netlist_elem*> >, std::less<std::string>, std::allocator<std::pair<std::string const, netlist_elem*> > >::_M_lower_bound(std::_Rb_tree_node<std::pair<std::string const, netlist_elem*> >*, std::_Rb_tree_node<std::pair<std::string const, netlist_elem*> >*, std::string const&)
 10.45      1.41     0.68  5856992     0.00     0.00  atomic_load_acq_int(unsigned int volatile*)
  8.76      1.98     0.57   400001     0.00     0.00  netlist_elem::routing_cost_given_loc(location_t)

and these are the true function names in the file:

void annealer_thread::Run()

Any flags im forgetting? and why is the profiling also showing the parameters of the functions? is it because they are classes? is it because it is cpp? I am familiar with gprof and c but this is my first encounter with cpp

Any help is welcome:) cheers=)

Syntax_Error
  • 5,964
  • 15
  • 53
  • 73
  • As usual in a non-trivial program, the CPU time is mostly spent in library routines, which doesn't tell you much about how they got called. Even when you get answers to these questions, [with gprof you will probably have a lot more questions](http://stackoverflow.com/questions/1777556/alternatives-to-gprof/1779343#1779343). – Mike Dunlavey Jan 25 '11 at 13:20

1 Answers1

1

In C++, function names include the class they belong to, their return type, and all their argument types. That's done by "mangling" the names. This is so functions can be overloaded with different argument types. gprof is aware of that and can un-mangle them.

What you're seeing in the flat profile is that the PC is often captured in some class library routines. That's helpful only if it gives you a clue what the call paths are in your code that end up in those routines. The call graph (instrumentation) is some help there.

And of course it's blind to any I/O you'd rather not be doing. The program could be spending 99% of its time doing I/O deep in a library, where you don't know it's happening and neither does gprof.

Take a look at Zoom.

Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
  • how can I unmangle them? I tired the '-T ' flag and I think it worked. do u have any other ideas? – Syntax_Error Jan 25 '11 at 16:58
  • @Syntax_Error: `gprof` is doing it for you. `gdb` can also do it if you try the [random-pausing](http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024) method, as I think I've suggested to you before. Another way could be if the gnu linker can give you a de-mangled map file, but I'm guessing about that. – Mike Dunlavey Jan 25 '11 at 17:53
  • yes u have propose the random-pausing...but Im kinda after the automatic thing more! got several tests to do some random-pausing would be time consuming! ill try to find a way 2 de-mangle the output! for now the -T flag is working fine with me! thnks – Syntax_Error Jan 25 '11 at 20:16
  • @Syntax_Error: Time-consuming? Well, I don't think so, but regardless, do take a look at Zoom. I'm also told OProfile can do it, if you learn how to coax it. – Mike Dunlavey Jan 25 '11 at 20:27
  • @Syntax_Error: Not to bother you, but the comments from Peter M. on [this post](http://stackoverflow.com/questions/890222/analyzing-code-for-efficiency/893272#893272) show a typical experience. – Mike Dunlavey Jan 26 '11 at 17:07