-3

Please let me know which tool (GNU or 3rd party tool) is the best we can make use for profiling and optimizing our code. Is gprof an effective tool? Do we have dtrace tool ported in Linux?

apaderno
  • 28,547
  • 16
  • 75
  • 90
Sanjay
  • 7
  • 1

3 Answers3

3

You're not alone in conflating the terms "profiling" and "optimizing", but they're really very different. As different as weighing a book versus reading it.

As far as gprof goes, here are some issues.

Among profilers, the most useful are the ones that

  • Sample the whole call stack (not just the program counter) or at least as much of it as contains your code.

  • Samples on wall-clock time (not just CPU time). If you're losing time in I/O or other blocking calls, a CPU-only profiler will simply not see it.

  • Tells you by line-of-code (not just by function) the percent of stack samples containing that line. That's important because any such line of code that you could eliminate would save you that percent of overall time, and you don't have to eyeball functions to guess where it is.

A good profiler for linux that does this is Zoom. I'm sure there are others. (Don't get confused about what matters. Efficiency and/or timing accuracy of a profiler is not important for helping you locate speed bugs. What's important is that it draws your attention to the right things.)

Personally, I use the random-pausing method, because I find it's the most effective. Not only is it simple and requires no investment, but it finds speedup opportunities that are not localized to particular routines or lines of code, as in this example. This is reflected in the speedup factors that can be achieved.

Community
  • 1
  • 1
Mike Dunlavey
  • 40,059
  • 14
  • 91
  • 135
2

gprof is better than nothing. But not much. It estimates time spent not only in a function, but also in all of the functions called by the function - but beware it is an estimate, not a direct measurement. It does not make the distinction that some two callers of the same subroutine may have widely differing times spent inside it, per call. To do better than that you need a real call graph profiler, one that looks at several levels of the stack on a timer tick.

dtrace is good for what it does.

If you are doing low level performance optimization on x86, you should consider Intel's Vtune tool. Not only does it provide the best access I am aware of to low level performance measurement hardware on the chip, the so-called EMON (Event Monitoring) system (some of which I designed), but Vtune also has some pretty good high level tools. Such as call graph profiling that, I believe, is better than gprof. On the low level, I like doing things like generating profiles of the leading suspects, like branch mispredictions and cache misses, and looking at the code to see if there is something that can be done. Sometimes simple stuff, such as making an array size 255 rather than 256, helps a lot.

Generic Linux oprofile, http://oprofile.sourceforge.net/about/, is almost as good as Vtune, and better in some ways. And available for x86 and ARM. I haven't used it much, but I particularly like that you can use it in an almost completely non-intrusive manner, with no need to create the special -pg binary that gprof needs.

Krazy Glew
  • 7,210
  • 2
  • 49
  • 62
  • Thanks - please let me know if dtrace tool available for Linux too. Please let me know from where I can download it? Since our whole development is on Red Hat Linux / C++ - please provide tools for the same platform. – Sanjay Nov 17 '11 at 07:15
0

Their are many tools from where you can optimize your code,

For web application their are different tools to optimize the code i.e jzip compressors e.g YUI Compressor etc.

For desktop application optimizing compiler is good.

Suleman Ahmad
  • 2,025
  • 4
  • 28
  • 43