• Martin Thoma
  • Home
  • Categories
  • Tags
  • Archives
  • Support me

Profiling C programs

Contents

  • Profiling C programs
    • valgrind and kcachegrind

If you have a working program and you want to improve its execution speed, you might want to profile it. An easy way to do so, is adding global variables, increasing them at interesting points and counting how often these points are executed. A more sophisticated way is using a profiler.

valgrind and kcachegrind

Install valgrind and kcachegrind. For Ubuntu users:

sudo apt-get install valgrind kcachegrind

Create a profile:

valgrind --tool=callgrind ./connectfour

(I've profiled a connect four application. Replace that with your application) This command will create a file called similar to "callgrind.out.4846".

Take a look at the profile:

kcachegrind callgrind.out.4846

You can also create a call-graph:

Call graph of connect four game graph creation program
Call graph of connect four game graph creation program

Just take a look at it by yourself. You will see much more than I could tell you now.


Published

Dez 1, 2012
by Martin Thoma

Category

Code

Tags

  • C 23
  • Performance 3
  • profiling 1

Contact

  • Martin Thoma - A blog about Code, the Web and Cyberculture
  • E-mail subscription
  • RSS-Feed
  • Privacy/Datenschutzerklärung
  • Impressum
  • Powered by Pelican. Theme: Elegant by Talha Mansoor