0

I am currently using the min-gw GCC profiler tool gprof to find the slow portions of my code. I compile the code with

gcc -p -pg -o3 example.c -o example.exe

After running the file I use

 gprof example.exe > data.txt

My program prints its running time to be ~8 seconds, but the data.txt only shows the functions of my program, which account for 3.47 seconds. I imagine that unaccounted for time is used in other C functions, such as malloc, free, etc, but I still need to know where the time is being used. Any thoughts?

Jens
  • 69,818
  • 15
  • 125
  • 179
AndrewGrant
  • 786
  • 7
  • 17
  • Any chance you are confusing execution time and wall-clock time? How does your program come to the conclusion it takes 8 seconds? How much I/O does your program do? Is it CPU bound, memory bound, or I/O bound? – Jens Mar 19 '15 at 15:52
  • I am using time.h, time_t start = time(0), time_t end= time(0),, total time = difftime(end,start) – AndrewGrant Mar 19 '15 at 15:53

2 Answers2

1

gprof together with most other profilers sample, rather than present accurate results so it's completely possible that you're getting less time than the actual execution time. Further gprof, according to this only cares about the code inside the program, not any other library functions that are called so this is also a factor.

Try using valgrind with the callgrind tool for a performance analysis. It's quite good and intuitive and you can visualize it with multiple other tools.

Another thing you can use is gperftool which can attach to a process and show you where most of the time is spent (in percentage).

There are really good proprietary profilers such as Intel vTune but in my experience there hasn't been a time where I couldn't find what I needed using gperftools.

XapaJIaMnu
  • 1,408
  • 3
  • 12
  • 28
1

There's a very good proprietary profiler - you own it.

It's any debugger that can be paused or interrupted, even GDB, augmented with the best artificial intelligence you can get - your head.

Some people call it "poor man's profiler", but it works, and it can find anything a profiler can find (especially gprof) and plenty that it can't.

If you want, I'll explain why.

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