3

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.

3
  • you mean you need good tool for profiling? OProfile perhaps, valgrind-tools? Commented Oct 5, 2010 at 6:20
  • 2
    Is the code computation-intensive (CPU), disk-I/O intensive, network I/O intensive, memory consuming, multi-threaded, etc? Knowing some initial directions will help you find a more suitable tool. Commented Oct 5, 2010 at 6:20
  • 1
    do you want to time the execution or analyse the working of the code ??? Commented Oct 5, 2010 at 6:20

4 Answers 4

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

+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.
2

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.

Comments

1

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.