Perf can be used to spot optimization candidates or to benchmark the result of changes.
- Assuming you want to optimize a decoder
perf record ./avconv -i sample -f null - perf report
Would be enough to get a list of function sorted by their global usage. The ones at the top are our candidates.
- Assuming you want to optimize an encoder
perf record ./avconv -i rawdata.mkv -c encoder -f null - perf report
Would work fine for the purpose.
Assuming you have a command you want to benchmark (perhaps one of the FATE tests, or avconv), you can do so with:
perf stat --repeat 30 yourcommand
This calculates averages and standard deviations for you.
Never blindly trust benchmarks.
If you are comparing two commands, make sure you look at both the totals and the variances; if the variances are much larger than the differences in total, you probably do not have a meaningful difference.
A meaningful statistic requires at least 30 samples.
On a fast machine with a quick command, you may choose to use more (such as 150) to reduce variance slightly. It can also be worth running perf multiple times; if it sometimes shows one command as faster, and sometimes the other, it is another sign that there is not a speed difference significant enough to measure.
On Ubuntu and Debian, it is packaged in linux-tools-generic.
apt-get install linux-tools-generic
On Gentoo, it is packaged as dev-util/perf.