3

Both tools are linux performance and profiling probing tool. I found that "perf" looks more powerful as it could trace into kernel call level. So my question is, with "perf", is there still a need to learn and keep "gprof"/

I mean, is there any work that only with gprof that could be done, while perf doesn't work well?

Troskyvs
  • 7,537
  • 7
  • 47
  • 115
  • 1
    They are completely different animals. gprof has been around since 1982. It is simple and venerable, and [*I think it should be retired*](http://stackoverflow.com/a/1779343/23771). perf is a modern tool with many options. If it would allow you to see a random selection of its stack (callchain) samples, it could even be as good as [*this*](http://stackoverflow.com/a/378024/23771). – Mike Dunlavey Mar 21 '17 at 12:33

1 Answers1

6

gprof (several implementations for different OS) works with instrumentation of the program (requires recompilation) and with statistical PC sampling on interval timer signal (setitimer, up to 0.1-1 kHz). By instrumentation it get information about calls between functions and function call counts. Check https://en.wikipedia.org/wiki/Gprof:

Gprof is a performance analysis tool for Unix applications. It uses a hybrid of instrumentation and sampling[1] and was created as extended version of the older "prof" tool. Unlike prof, gprof is capable of limited call graph collecting and printing.[1][2]

perf is Linux-only modern tool for statistical profiling. It can sample PC and call stacks (if there are frame pointers or enough debug information to unwind call stack) both on software timers and on hardware performance counters (like instruction executed, L1 miss count, and many other; full event list by showevtinfo is http://www.bnikolic.co.uk/blog/hpc-prof-events.html, found in https://stackoverflow.com/a/23965237). There are other modes built into perf too: http://www.brendangregg.com/perf.html

So, gprof can show you exact function call count of single program, but it can't resolve call stack (it only approximate it). And there are gprofs in Linux, BSD, and many other Unixes and Unix-like OS. perf is Linux-only, but have access to hardware performance monitoring unit and support both single-program profiling and system-wide profiling.

Community
  • 1
  • 1
osgx
  • 90,338
  • 53
  • 357
  • 513