views:

204

answers:

4

What free tools could I use to test the performance of C++ code in Linux? Basically I want to identify the bottleneck of the code and improve on the performance. My application mainly involves computational code using the data from the network. So I would like to improve the speed of execution of the code.

Thanks.

+6  A: 

For typical performance benchmarking this is what i use.

  • gprof/oprofile - for CPU intensive profiling of your code.
  • netstat/ethereal - for network statistics
  • iostat/sar - for I/O
  • vmstat - for memory
  • mpstat/sar - for cpu usage

Now u can isolate the problems based on the output of these tools.

For eg:- if I/O is constant and within limits u can eliminate I/O as a problem. If CPU usage is heavy as shown my mpstat then get into profiling using gprof/oprofile.

Without the use of all of them together for different runs, its difficult to identify the bottleneck.

Note: U can write a script to run all of them together and store the results in designated folders for each run.

aeh
+1 for mentioning good tools. +valgrind for extremely CPU/cache intensive tasks. For a quick start, it's worth checking the ratio of CPU to elapsed time while the program's working - can see that in top. If it's pretty idle then you need to improve your network - consider alternative ways of packing/compressing the data. If the CPUs pegged, use `gprof` or whatever to describe which functions are taking the time, or introduce your own timers (boost has high-res timing functions you can use) to measure how long it takes particular parts of your processing to complete.
Tony
+1  A: 

By far the best profiler for Linux that I know of is Zoom. Although it's a commercial product it's not too expensive and you can get a free 30 day evaluation licence on request

Paul R
+1  A: 

I recommend valgrind for

  • cpu usage, callgrind submodule (source line granularity)
  • memory leaks
  • building call graphs
  • some advanced issues like finding problems in multithread locking mechanism

The callgrind output can be visually displayed via KCacheGrind.

Gabriel Schreiber
A: 

As @Paul says, give Zoom a try.

Personally, I use this method, which works for these reasons, and Zoom approximates it. It is a technique that some programmers have independently discovered.

I'm also told OProfile can do it, but you have to know what you need to make it do.

Mike Dunlavey