6

AFAIK profilers can only tell how much time is spent in each function. But since C++ compilers tend to inline code aggressively and also some functions are not that short it's often useful to know more details - how much time each construct consumes.

How can this be achieved except restructuring code into smaller functions?

sharptooth
  • 163,328
  • 92
  • 501
  • 942

2 Answers2

5

If you use a sampling profiler (e.g. Zoom or Shark), rather than an instrumented profiler (e.g. gprof) then you can get much finer grained profiles, down to the statement and instruction level.

Paul R
  • 202,568
  • 34
  • 375
  • 539
  • 1
    ++ Try Zoom, or any profiler that gets **stack** samples, at random **wall-clock** times, in the **interval you care about**, and tells you **per line of code** the **percent of samples it appears on**. [Here's a list of reasons why.](http://stackoverflow.com/questions/1777556/alternatives-to-gprof/1779343#1779343) It's amazing how many profilers don't "get it". – Mike Dunlavey Dec 04 '10 at 01:17
  • @sharptooth: What makes line-percenting wall-time stack-samplers so effective is that they automate what is (IMHO) an even more effective [manual method](http://stackoverflow.com/questions/375913/what-can-i-use-to-profile-c-code-in-linux/378024#378024) - random pausing. – Mike Dunlavey Dec 04 '10 at 01:27
2

If you can use callgrind then you can get a summary of which methods are taking most of the processing time. Then you can use kcachegrind to view the results. It gives a very nice graph, through which you can easily browse and find bottlenecks.

BЈовић
  • 59,719
  • 40
  • 167
  • 261