1

I'm a high-school student doing some C things where I'd like to profile my code to see where the actual performance bottlenecks are. I don't have much money, so I'd prefer free tools.

I like to use the MinGW/GCC compiler toolchain. This is not something I'm stuck with, but I'd prefer tools that are capable of working with this.

Features I need:

  • See how much total time is spent in a certain function.

Features I'd like:

  • See how much time a line of code takes.
  • Cross-platform (being able to use the same software on Linux & Mac)
  • See how often a function gets called (and how long each call takes on average).
  • See what causes the time spent (cache misses, branch mispredictions, etc).

I've tried using gprof, but I couldn't get it to work (it only shows main in the profile), and I've heard bad things about it, so what are my options?

orlp
  • 98,226
  • 29
  • 187
  • 285
  • To channel [Mike Dunlavey](http://stackoverflow.com/users/23771/mike-dunlavey), [you don't need **any** profiler tool.](http://stackoverflow.com/a/378024/139010) – Matt Ball Apr 23 '12 at 18:39
  • @MДΓΓ БДLL: Why do you attempt to close my question and refer it to another closed question closed as "not constructive" with clearly not the same requirements and insuffecient answers? And I'm profiling mathematical functions, so that _any_ profiler tool doesn't work here. – orlp Apr 23 '12 at 18:41
  • My apologies. I meant to close as a dup of [Alternatives to gprof](http://stackoverflow.com/questions/1777556/alternatives-to-gprof/1779343#1779343). – Matt Ball Apr 23 '12 at 18:42
  • @MДΓΓ БДLL: That question is a linux question, I'm talking about Windows here. – orlp Apr 23 '12 at 18:43
  • gprof works fine for me on windows (with cygwin gcc 4.5.3). I can see all of my functions plus the call graph. Did you remember to compile with the `-pg` option? – markgz Apr 23 '12 at 19:08
  • @markgz: I compiled with `-O3 -g -pg`, executed and then ran `gprof`, but the output only showed `main`. – orlp Apr 23 '12 at 19:42
  • Did your code run for long enough? I think gprof is a statistical sampler. I was able to reproduce your symptoms by reducing the size of my test data so that the program ran for only 50 ms. I got good profiling results when the test data size was such that the program ran for about a minute. – markgz Apr 23 '12 at 20:20
  • @markgz: even when run a minute, no dice. But now I found the issue, it was inlining. – orlp Apr 23 '12 at 20:59

1 Answers1

0

if you want a free, Windows and Linux TBP (it also does event based and some other metric based forms of profiling) then AMD's code analyst should do the job nicely (even on Intel cpus, though Im not sure of the quality/reliability of the branching and cache analysis on Intel cpus), its also got a nice ui built in Qt which does the source + assembly line time breakdowns. its also got an API to embed events for the profiler to catch for more targeted profiling.

Necrolis
  • 24,554
  • 3
  • 57
  • 98