Quick intro to perf

Perf is a performance counters subsystem in Linux. Usually performance counters are CPU hardware registers that count hardware events such as instructions executed, cache-misses suffered, or branches mispredicted. This subsystem was designed mainly as a basis for profiling applications to trace dynamic control flow and identify hotspots. But recording some types of software events like context switch, fork() and exit() system calls, task wakeup or task migration from one core to another creates an opportunities to replay such events in a real-time fashion, thus simulating the workload was issued at the time of recording.

Now there is a support for such kind of a simulation implemented by 'record' and 'sched replay' perf commands. It works by collecting samples from all online CPUs (or from a specified subset of online CPUs) for the time period when the specified process is running, thus recording a trace of system-wide activity. Then a number of so-called 'mockup' threads are started to mimic the workload based on the events in the trace. These threads can then replay the timings (CPU runtime and sleep patterns) of the workload as it occurred when it was recorded.

Since Linux 3.6.0-rc1, this feature is expected to work in 'cross-replay' mode, e.g. perf records obtained on one system can be replayed on another. This introduces an opportunity to record, share and replay the workloads without installing any testing infrastructure since the matched version of perf tool is the only requirement to replay the records.

Some drawbacks of perf replay are noted in the blueprint

Test records

Now there are 4 test records available. Each record was taken from 10-minutes workload.

Notes

To replay these records, use:

perf sched -i [record file] replay

You need perf version at least 3.6-rc1 and matching kernel version. Do not use mismatched versions of perf and kernel, this will not work as expected and may cause kernel crash.

Appendix

WorkingGroups/PowerManagement/Archives/PerfRecordReplay (last modified 2013-08-21 11:28:17)