8
Performance Analysis with Perf By Dominic Duval [email protected]

Linux Performance Analysis with Perf

Embed Size (px)

DESCRIPTION

Tuning systems and applications for speed requires tools to gain visibility into the performance hotspots that will yield the largest improvements. Perf, which we cover in this tutorial, constitute one of the latest addition to the Linux world in the field of performance analysis.

Citation preview

Page 1: Linux Performance Analysis with Perf

Performance Analysis with Perf

By Dominic Duval

[email protected]

Page 2: Linux Performance Analysis with Perf

Performance Monitoring

Localizing performance hotspots Profiling : gathering statistics on how the code executes Can be done in two ways:

Software: low precision Hardware: uses specialized counters on the CPU

Hardware method is more efficient and precise Also gives us access to data we can’t record otherwise

Page 3: Linux Performance Analysis with Perf

Perf: More Than a Profiler

perf : interface to hardware and software events Built in the kernel

With user space utilities for control and reports

One command: perf Many subcommands, very git-like No daemons

Requires debugging symbols to be installed kernel-debuginfo or vmlinux for kernel Applications compiled with -g

Focuses on hardware performance counters but also other events:

Tracepoints Software counters Hardware breakpoints

Page 4: Linux Performance Analysis with Perf

Perf Security

Perf commands restricted to root by default Security checks can be disabled withecho 0 > / proc / sys / kernel / perf_event_paranoid

Can be made persistent via sysctl Proper write access to current directory still required Paranoid mode recommended for production

environments

Page 5: Linux Performance Analysis with Perf

Listing perf events: perf list

Lists all events supported by the current architecture Any event names in first column can be used Hardware events use the PMU

Low overhead

Software events are triggered by the kernel Tracepoints : similar to software events and refer to

specific functions Many hardware events missing

Can be set as a raw event Documented by CPU manufacturers

Page 6: Linux Performance Analysis with Perf

System overview: perf stat

Provides a standard set of statistics after invoking a command

Events include: Task-clock ticks Context switches CPU migrations Page faults CPU cycles Stalled cycles Instructions Branches and branch misses

Uses round-robin to support multiple events Subject to wild extrapolations Can lack precision with short workloads

Page 7: Linux Performance Analysis with Perf

Recording performance data: perf record

Reads performance data and generates a file in the current directory:

perf.data Make sure the current directory is writable!

Can generate a large dataset if profiling the whole system

Or if recording with call-graphs (-g)

Which is event is recorded can be specified with -e:perf record -e instructions sleep 5

perf record -e LLC-loads / usr / bin / firefox

Page 8: Linux Performance Analysis with Perf

For more information

To watch a detailed video presentation on how to use perf for performance analysis, visit:

http://go.linuxfoundation.org/PerfVideo