6

I am trying to find a performance issue in my program and thus instrumented the code with profiling. gprof creates a flat profile like this:

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 27.97      4.10     4.10                             std::_Deque_iterator<char, char&, char*>::_Deque_iterator(std::_Deque_iterator<char, char&, char*> const&)
  6.96      5.12     1.02                             std::_Deque_iterator<char, char&, char*>::difference_type std::operator-<char, char&, char*>(std::_Deque_iterator<char, char&, char*> const&, std::_Deque_iterator<char, char&, char*> const&)
  5.12      5.87     0.75                             std::__deque_buf_size(unsigned int)
  4.23      6.49     0.62                             std::_Deque_iterator<char, char&, char*>::operator+=(int)
  3.41      6.99     0.50                             std::deque<char, std::allocator<char> >::begin()
  1.91      7.27     0.28     7896     0.04     0.04  std::vector<MyClass, std::allocator<MyClass> >::_M_insert_aux(__gnu_cxx::__normal_iterator<MyClass*, std::vector<MyClass, MyClasst> > >, MyClassconst&)
  1.91      7.55     0.28                             std::deque<char, std::allocator<char> >::size() const
  1.91      7.83     0.28                             std::_Deque_iterator<char, char&, char*>::_S_buffer_size()

followed by many lines with less time.

First question: is it a valid assumption to believe that there seems to be a problem with a std::deque? The problem is: I know we are using std::deque, but I am not aware of a usage with <char>.

If this assumption is true, it seems to make sense to look at the call stack and see where this deque is used. Howevre all entries concerning the deque<char> stuff are only called by <spontaneous>!

Just one example:

index % time    self  children    called     name
                                                 <spontaneous>
[1]     28.0    4.10    0.00                 std::_Deque_iterator<char, char&, char*>::_Deque_iterator(std::_Deque_iterator<char, char&, char*> const&) [1]

Is there any way to find out more about this deque?

Thanks for any hints!

Philipp
  • 11,549
  • 8
  • 66
  • 126
  • For statistical sampling, google-perftools produces much more useful output than gprof in my experience. – Nemo Sep 30 '11 at 05:57
  • That's gprof. It points the finger at innocent code, and totally misses the real problem. [Alternatives to Gprof.](http://stackoverflow.com/questions/1777556/alternatives-to-gprof/1779343#1779343) – Mike Dunlavey Sep 30 '11 at 13:16
  • I am using gprof because it seems to be the far easiest choice for profiling on an embedded platform (especially as I don't have lots of Linux experience), but thanks for the tips, I will consider to try something else. – Philipp Oct 01 '11 at 07:04

2 Answers2

3

Apparently, spontaneous is what gprof uses when it can't work out the calling function. I would try recompiling all code with -pg (is it possible you missed some files?). Also, make sure you have optimisation turned on. Inlining will typically make these little functions disappear into the calling function which is generally more useful.

Bowie Owens
  • 2,798
  • 23
  • 20
  • I guess, "Also, make sure you have optimisation turned **off**". Am I right? –  Nov 21 '12 at 04:55
  • 5
    @skwllsp I believe in general you want optimisations turned on when profiling for a couple of reasons. My feeling is that inlining removes noise from the profile which I thought might help the OP. Enabling optimisation is also important because the compiler optimisations may change the location of bottlenecks in your code. You don't want to spend a long time optimising your code only to find that the compiler can do a better job than you. – Bowie Owens Nov 21 '12 at 05:27
0

The accepted answer is corret. Another reason you might find a lot of <spontaneous> entries is if you pass gprof the wrong executable. Make sure you pass the same compiled binary you generated the gmon.out file to gprof to generate the analysis.

HParker
  • 1,567
  • 15
  • 19