🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › perf-record.1.html
perf-record(1) - Linux manual page
If other --filter exists, the new filter expression will be combined with them by &&. --latency Enable data collection for latency profiling. Use perf report --latency for latency-centric profile. -a, --all-cpus System-wide collection from all CPUs (default if no target is specified). -p, --pid= Record events on existing process ID (comma separated list).
🌐
Brendan Gregg
brendangregg.com › perf.html
Linux perf Examples
# Sample CPU stack traces for the PID, using dwarf (dbg info) to unwind stacks, at 99 Hertz, for 10 seconds: perf record -F 99 -p PID --call-graph dwarf sleep 10 · # Sample CPU stack traces for the entire system, at 99 Hertz, for 10 seconds (< Linux 4.11): perf record -F 99 -ag -- sleep 10
🌐
Linux Man Pages
linux.die.net › man › 1 › perf-record
perf-record(1) - Linux man page
perf-record - Run a command and record its profile into perf.data
🌐
Arch Linux Man Pages
man.archlinux.org › man › perf-record.1.en
perf-record(1) — Arch manual pages
Arch Linux · Home · Packages · Forums · Wiki · GitLab · Security · AUR · Download · perf-record - Run a command and record its profile into perf.data ·
🌐
PhoenixNAP
phoenixnap.com › home › kb › sysadmin › linux perf: how to use the command and profiler
Linux perf: How to Use the Command and Profiler | phoenixNAP KB
August 24, 2023 - ... After five seconds, the output displays all system-wide calls and their count. CPU cycles are a hardware event. To record CPU cycles, use the record subcommand and provide the event name with the -e tag:
🌐
Ubuntu
manpages.ubuntu.com › bionic › man(1)
Ubuntu Manpage: perf-record - Run a command and record its profile into perf.data
Run a command and record its profile into perf.data · Provided by: linux-tools-common (Version: 4.15.0-213.224) Source: linux · Report a bug ·
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › perf-report.1.html
perf-report(1) - Linux manual page
This option will affect the percentage of the overhead and latency columns. See --percentage for more info. Also see the ‘CPU and latency overheads’ section for more details. --latency Show latency-centric profile rather than the default CPU-consumption-centric profile (requires perf record --latency flag).
🌐
Perfwiki
perfwiki.github.io › main › tutorial
Introduction - perf: Linux profiling with performance counters
LC_NUMERIC=en_US.UTF8 perf stat -B -e cycles:u,instructions:u dd if=/dev/zero of=/dev/null count=10000000 100000+0 records in 100000+0 records out 51200000 bytes (51 MB) copied, 0.0971547 s, 527 MB/s Performance counter stats for 'dd if=/dev/zero of=/dev/null count=100000': 96,551,461 cycles 38,176,009 instructions # 0.395 IPC 0.098556460 seconds time elapsed
Find elsewhere
🌐
Medium
medium.com › @redswitches › linux-perf-command-a-comprehensive-guide-with-13-use-cases-0afdde83448a
Linux perf Command: A Comprehensive Guide with 13 Use Cases
August 19, 2024 - It combines the output of perf record and provides information such as where a program spends most of its time and parts of code that need to be optimized for speed. To annotate performance data and display the output, execute the following command: ... The -v option gives a detailed output, showing the source code and disassembly of the events. Linux perf is an invaluable tool for developers and system administrators seeking to optimize system performance.
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › perf-stat.1.html
perf-stat(1) - Linux manual page
This command runs a command and gathers performance counter statistics from it. <command>... Any command you can specify in a shell. record See STAT RECORD. report See STAT REPORT. -e, --event= Select the PMU event.
🌐
GitHub
github.com › torvalds › linux › blob › master › tools › perf › Documentation › perf-record.txt
linux/tools/perf/Documentation/perf-record.txt at master · torvalds/linux
This file can then be inspected later on, using 'perf report'. ... Collect raw sample records from all opened counters (default for tracepoint counters).
Author   torvalds
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › perf.1.html
perf(1) - Linux manual page
Performance counters for Linux are a new kernel-based subsystem that provide a framework for all things performance analysis. It covers hardware level (CPU/PMU, Performance Monitoring Unit) features and software features (software counters, tracepoints) as well. perf-stat(1), perf-top(1), perf-record(1), perf-report(1), perf-list(1) perf-amd-ibs(1), perf-annotate(1), perf-archive(1), perf-arm-spe(1), perf-bench(1), perf-buildid-cache(1), perf-buildid-list(1), perf-c2c(1), perf-config(1), perf-data(1), perf-diff(1), perf-evlist(1), perf-ftrace(1), perf-help(1), perf-inject(1), perf-intel-pt(1), perf-iostat(1), perf-kallsyms(1), perf-kmem(1), perf-kvm(1), perf-lock(1), perf-mem(1), perf-probe(1), perf-sched(1), perf-script(1), perf-test(1), perf-trace(1), perf-version(1)
Top answer
1 of 1
17

Count and frequency are two fundamental switches that tune the rate of sampling when using perf record (which does sampling internally).

Count

When you run perf record -c <number>, you are specifying the sample period (where "number" is the sample period). That is, for every "number"th occurrence of the event a sample will be recorded. The sample will be recorded when the performance counter that keeps track of the number of events has overflowed.

I am guessing you are obtaining the number of events with the help of perf report. Note that perf report will never report the actual number of events, but only an approximate. The number of events will keep changing as you keep tweaking the sample period. perf report will only read the perf.data file that perf record generates, and based on the size of the file generated, it makes an assumption of the number of samples recorded (by knowing the size of a sample recorded in memory). The actual number of events recorded is obtained by -

Number of events = Fixed Sample Period * Number of samples collected

where Fixed Sample Period is what you specified with perf record -c.

Frequency

This is the other way around to express the sampling period, that is to specify the average rate of samples per second (frequency) - which you can do using perf record -F. So perf record -F 1000 will record around 1000 samples per second and these samples will be generated when the hardware/PMU counter corresponding to the event overflows. This means that the kernel will dynamically adjust the sampling period to make sure that the sampling process adheres to the sampling frequency.

This is how the sample period gets updated dynamically.

Higher the sampling frequency, higher the number of samples collected (almost proportionately).

The variation in the sampling period can be seen by running the command -

sudo perf report -D -i perf.data | fgrep RECORD_SAMPLE

Whenever the sampling period keeps varying, the total number of events will keep incrementing with the variation in the sampling period. And when the sampling period remains fixed, the total number of events remain fixed and is obtained by the formula showed above. The total number of events will be approximate in both the cases.

🌐
DEV Community
dev.to › franckpachot › linux-perf-top-basics-understand-the-316l
Linux perf-top basics: understand the % - DEV Community
March 21, 2021 - sudo perf record -F99 -g --call-graph fp --delay=5 -v -p $(pgrep -d, yb-tserver) -a sleep 10 sudo perf report --call-graph ,,,,callee --symbol-filter=RawUncompress
🌐
Tu-dresden
compendium.hpc.tu-dresden.de › software › perf_tools
Produce Performance Overview with Perf - ZIH HPC Compendium
This tool is very effective, if you want to help users find performance problems and hot-spots in their code but also helps to find OS daemons that disturb such applications. You would start perf record -a -g to monitor the whole node.
🌐
Perfwiki
perfwiki.github.io › main
perf: Linux profiling with performance counters
This is the wiki page for the Linux perf command, also called perf_events. perf is powerful: it can instrument CPU performance counters, tracepoints, kprobes, and uprobes (dynamic tracing). It is capable of lightweight profiling.
🌐
SysTutorials
systutorials.com › docs › linux › man › 1-perf-record
perf-record: Run a command and record its profile into perf.data - Linux Manuals (1)
This command runs a command and gathers a performance counter profile from it, into perf.data - without displaying anything. This file can then be inspected later
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_enterprise_linux › 8 › html › monitoring_and_managing_system_status_and_performance › getting-started-with-perf_monitoring-and-managing-system-status-and-performance
Chapter 18. Getting started with perf | Monitoring and managing system status and performance | Red Hat Enterprise Linux | 8 | Red Hat Documentation
This command provides overall statistics for common performance events, including instructions executed and clock cycles consumed. Options allow for selection of events other than the default measurement events. ... This command records performance data into a file, perf.data, which can be ...