perf record and perf stat support the -p option which you can use to specify the PID of the process to attach to. For example , the command:

perf stat -p 3129

tells perf stat to attach to the currently running process with PID 3129.

Answer from gbajson on Stack Overflow
🌐
Brendan Gregg
brendangregg.com › perf.html
Linux perf Examples
I'd generally interpret high IPC values (eg, over 1.0) as good, indicating optimal processing of work. However, I'd want to double check what the instructions are, in case this is due to a spin loop: a high rate of instructions, but a low rate of actual work completed. There are some advanced metrics now included in perf stat: frontend cycles idle, backend cycles idle, and stalled cycles per insn.
🌐
GitHub
github.com › gribnoysup › perf.html › blob › master › docs-user › guide-perf-profiling.md
perf.html/docs-user/guide-perf-profiling.md at master · gribnoysup/perf.html
You can attach perf to an existing (running) process, or you can launch a new process from it and profile it from the start, including the entire process tree launched from it.
Author   gribnoysup
🌐
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).
🌐
GitHub
gist.github.com › hrwgc › 9750190
perf-guide.md · GitHub
To isolate profiling to a single process or program use perf record.
🌐
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 - Learn how to use the Linux perf command to profile, count, and analyze system events and CPU performance in this guide.
🌐
HPC Wiki
hpc-wiki.info › hpc › Perf
Perf - HPC Wiki
September 23, 2019 - When monitoring a process, all child processes and threads will also be monitored. This can be avoided by providing the -i, --no-inherit flag. With perf record, you can set-up an event based sampling.
Find elsewhere
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_enterprise_linux › 10 › html › monitoring_and_managing_system_status_and_performance › recording-and-analyzing-performance-profiles-with-perf
Chapter 13. Recording and analyzing performance profiles with perf | Monitoring and managing system status and performance | Red Hat Enterprise Linux | 10 | Red Hat Documentation
You can profile the entire system by running perf record -a. This records performance data until you press Ctrl+C or for the duration of a specific command. You can profile a single application/process by running perf record ./your_app or by attaching to an already running one by using perf ...
🌐
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 - The perf stat command can be used to count the occurrences of different system call types. To count the number of system calls made by all processes on the system over a specific period, run the following command:
🌐
Linux Man Pages
linux.die.net › man › 1 › perf-record
perf-record(1) - Linux man page
This command runs a command and gathers a performance counter profile from it, into perf.data - without displaying anything.
🌐
Fedora Magazine
fedoramagazine.org › home › for developers › performance profiling with perf
Performance profiling with perf - Fedora Magazine
August 15, 2016 - For example, let’s examine a firefox process, and sample the data for it. In this example, the firefox process is running as PID 2750. Executing the perf report command produces a screen like this, listing the various symbols in decreasing order of their overhead:
🌐
Opensource.com
opensource.com › article › 18 › 7 › fun-perf-and-python
How to analyze your system with perf and Python | Opensource.com
Similar to the top command, which displays (at a regular update interval) the processes using the most CPU time, perf top will display the functions using the most CPU time among all processes on the system, a nice leap in granularity.
🌐
Linux Man Pages
man7.org › linux › man-pages › man1 › perf-stat.1.html
perf-stat(1) - Linux manual page
Reads and reports stat data from perf data file. -i file, --input file Input file name. --per-socket Aggregate counts per processor socket for system-wide mode measurements. --per-die Aggregate counts per processor die for system-wide mode measurements. --per-cluster Aggregate counts perf processor cluster for system-wide mode measurements.
🌐
Progress Customer Community
community.progress.com › s › article › using-perf-to-understand-performance
Using perf to understand performance - Progress Community
perf works by sampling the process, rather than pausing it, and so is more lightweight than pstack, and it gives a statistical view of the process execution.
🌐
Red Hat
docs.redhat.com › en › documentation › red_hat_enterprise_linux › 8 › html › monitoring_and_managing_system_status_and_performance › recording-and-analyzing-performance-profiles-with-perf_monitoring-and-managing-system-status-and-performance
Chapter 21. Recording and analyzing performance profiles with perf | Monitoring and managing system status and performance | Red Hat Enterprise Linux | 8 | Red Hat Documentation
If you do not specify a command for perf record to record during, it will record until you manually stop the process by pressing Ctrl+C. You can attach perf record to specific processes by passing the -p option followed by one or more process IDs. You can run perf record without root access, however, doing so will only sample performance data in the user space.