{"id":27648,"date":"2025-05-06T19:11:12","date_gmt":"2025-05-06T19:11:12","guid":{"rendered":"https:\/\/linux.how2shout.com\/?p=27648"},"modified":"2025-05-06T19:11:22","modified_gmt":"2025-05-06T19:11:22","slug":"what-is-perf_event-in-linux-linux-performance-monitoring","status":"publish","type":"post","link":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/","title":{"rendered":"What is perf_event in Linux? Linux Performance Monitoring"},"content":{"rendered":"\n<p>You might have an application on your Linux system running slower than expected, or need to diagnose mysterious performance issues. That&#8217;s where Linux&#8217;s perf_event subsystem comes in\u2014a powerful yet often underutilized performance monitoring tool built right into the kernel.<\/p>\n\n\n\n<p>This Linux guide is where I will discuss everything you need to know about perf_event\u2014from basic concepts to advanced usage scenarios. Whether you&#8217;re a systems administrator, developer, or just a curious Linux enthusiast, you&#8217;ll discover how to use pref_event to gain incredible insights into your system&#8217;s performance.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-what-exactly-is-perf-event\">What exactly is perf_event?<\/h2>\n\n\n\n<p>perf_event (sometimes called perf_events or perf tools, originally known as Performance Counters for Linux) is a powerful performance analysis subsystem built into the Linux kernel since version 2.6.31, released in 2009. It provides a unified interface to various performance monitoring sources.<\/p>\n\n\n\n<p>Think of <strong>perf_event<\/strong> as Linux&#8217;s internal fitness tracker\u2014constantly monitoring vital signs across your system and providing a way to access that data. Unlike external monitoring tools that estimate performance,<strong> perf_event taps directly into the kernel and hardware<\/strong>, giving you precise, low-level insights with minimal overhead.<\/p>\n\n\n\n<p>What makes <strong>perf_event special<\/strong> is its comprehensive approach. Rather than focusing on just one aspect of system performance, it offers a unified interface to collect data from multiple sources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Hardware events<\/strong>: CPU cycles, instructions, cache misses<\/li>\n\n\n\n<li><strong>Software events<\/strong>: Page faults, context switches, CPU migrations<\/li>\n\n\n\n<li><strong>Kernel tracepoints<\/strong>: Predefined points in the kernel code<\/li>\n\n\n\n<li><strong>Dynamic tracing<\/strong>: Custom probes you insert anywhere in kernel or user code<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-why-should-you-care-about-perf-event\">Why Should You Care About perf_event?<\/h2>\n\n\n\n<p>Now we know what perf_event is in Linux systems, but you might wonder, &#8220;Why should I learn about perf_event when there are plenty of monitoring tools available?&#8221; The answer is simple: <strong>power and precision.<\/strong><\/p>\n\n\n\n<p>When you need to answer questions like &#8220;Why is this specific application slow?&#8221; or &#8220;What&#8217;s causing these mysterious latency spikes?&#8221;, generic monitoring tools often fall short. They might tell you <em>that<\/em> something is wrong, but not <em>why<\/em> or <em>where<\/em>.<\/p>\n\n\n\n<p><strong>With perf_event, you can:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Pinpoint exactly where CPU cycles are being spent<\/li>\n\n\n\n<li>Identify specific functions causing performance bottlenecks<\/li>\n\n\n\n<li>Monitor detailed system behaviors like disk I\/O patterns and network activity<\/li>\n\n\n\n<li>Correlate different performance events to understand cause-and-effect relationships<\/li>\n<\/ul>\n\n\n\n<p>I&#8217;ve personally used perf_event to solve performance mysteries that stumped an entire team\u2014like discovering a poorly optimized function that was causing cache misses and slowing down the entire application. The insights you gain from perf_event can transform the way you think about performance tuning.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-the-perf-command-your-gateway-to-perf-event\">The perf Command: Your Gateway to perf_event<\/h2>\n\n\n\n<p><strong>While perf_event is the kernel subsystem<\/strong>, most users interact with it through the<strong> perf command-line tool, <\/strong>which provides a user-friendly interface to the perf_event functionality.<\/p>\n\n\n\n<p>The <strong>perf tool <\/strong>is accessible from the command line and provides various subcommands for different performance analysis tasks.<\/p>\n\n\n\n<p><strong>Let&#8217;s look at some of the most useful perf subcommands:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>perf stat<\/strong>: Collects and summarizes performance counter statistics<\/li>\n\n\n\n<li><strong>perf record<\/strong>: Captures detailed samples for later analysis<\/li>\n\n\n\n<li><strong>perf report<\/strong>: Analyzes and displays the data collected by perf record<\/li>\n\n\n\n<li><strong>perf top<\/strong>: Shows real-time performance counter profile<\/li>\n\n\n\n<li><strong>perf trace<\/strong>: Traces system calls (similar to strace but with lower overhead)<\/li>\n\n\n\n<li><strong>perf script<\/strong>: Outputs trace data in a scriptable format<\/li>\n<\/ul>\n\n\n\n<p>These commands form the foundation of your performance analysis toolkit. As you become more familiar with <span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\"><strong>Perf, <\/strong>you&#8217;ll <strong>develop your\u00a0<\/strong>workflow b<\/span>y combining these tools to diagnose issues quickly.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-getting-started-installing-perf\">Getting Started: Installing perf<\/h2>\n\n\n\n<p>Before diving into<strong> perf_event<\/strong>, you&#8217;ll need to install the <strong>perf tool.<\/strong> On most Linux distributions, it&#8217;s part of the linux-tools package.<\/p>\n\n\n\n<p><strong>On Ubuntu\/Debian systems:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo apt install linux-tools-common linux-tools-generic<\/code><\/pre>\n\n\n\n<p><strong>On Fedora\/RHEL\/CentOS:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo yum install perf<\/code><\/pre>\n\n\n\n<p><strong>Once installed, verify it&#8217;s working:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">perf --version<\/code><\/pre>\n\n\n\n<p>If you see a version number, you&#8217;re ready to start exploring!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-perf-stat-your-first-step-into-performance-monitoring\">Perf Stat: Your First Step into Performance Monitoring<\/h2>\n\n\n\n<p>Let&#8217;s start with the most straightforward and most useful <strong>perf <\/strong>command\u2014<code>perf stat<\/code>. This command measures key performance counters for a specified command or time period.<\/p>\n\n\n\n<p><strong>For example<\/strong>, to measure performance <strong>statistics <\/strong>while running the <code>gzip<\/code> command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">perf stat gzip largefile<\/code><\/pre>\n\n\n\n<p>This will output something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"> Performance counter stats for 'gzip largefile':\n\n      1,920.15 msec  task-clock                #    0.991 CPUs utilized          \n             13      context-switches          #    0.007 K\/sec                  \n              0      cpu-migrations            #    0.000 K\/sec                  \n            258      page-faults               #    0.134 K\/sec                  \n     5,649,595,479     cles                    #    2.942 GHz                    \n     8,625,207,199   instructions              #    1.53  insn per cycle         \n     1,488,797,176   branches                  #    775.351 M\/sec                \n        53,395,139   branch-misses             #    3.59% of all branches        \n\n       1.936842598 seconds time elapsed<\/code><\/pre>\n\n\n\n<p>Even this simple output provides valuable insights:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1.53 instructions per cycle<\/strong>: This value indicates how efficiently the CPU is executing instructions. Higher is generally better.<\/li>\n\n\n\n<li><strong>3.59% branch misses<\/strong>: Shows how often the CPU&#8217;s branch prediction is wrong, which can impact performance.<\/li>\n\n\n\n<li><strong>Context switches and migrations<\/strong>: Reveals how often the task is being moved between CPU cores.<\/li>\n<\/ul>\n\n\n\n<p>With just this quick command, I can immediately see if my program is CPU-bound, memory-bound, or suffering from excessive context switching.<\/p>\n\n\n\n<p>If you get the following error while running the perf stat command:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">Error:\nAccess to performance monitoring and observability operations is limited.\nConsider adjusting \/proc\/sys\/kernel\/perf_event_paranoid setting to open\naccess to performance monitoring and observability operations for processes\nwithout CAP_PERFMON, CAP_SYS_PTRACE or CAP_SYS_ADMIN Linux capability.\nMore information can be found at 'Perf events and tool security' document:\nhttps:\/\/www.kernel.org\/doc\/html\/latest\/admin-guide\/perf-security.html\nperf_event_paranoid setting is 4:\n  -1: Allow use of (almost) all events by all users\n      Ignore mlock limit after perf_event_mlock_kb without CAP_IPC_LOCK\n>= 0: Disallow raw and ftrace function tracepoint access\n>= 1: Disallow CPU event access\n>= 2: Disallow kernel profiling\nTo make the adjusted perf_event_paranoid setting permanent preserve it\nin \/etc\/sysctl.conf (e.g. kernel.perf_event_paranoid = &lt;setting>)<\/code><\/pre>\n\n\n\n<p>Then to solve it: <strong>Fix: Lower the <code>perf_event_paranoid<\/code> Value<\/strong><\/p>\n\n\n\n<p>To allow non-root users (or even root in some cases) to use <code>perf<\/code>, you need to change the <strong><code>perf_event_paranoid<\/code><\/strong> setting.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Temporary Fix (until reboot):<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo sysctl -w kernel.perf_event_paranoid=1<\/code><\/pre>\n\n\n\n<p>Or, to allow full access:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo sysctl -w kernel.perf_event_paranoid=-1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 Permanent Fix:<\/h3>\n\n\n\n<p><strong>Open the sysctl config: <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo nano \/etc\/sysctl.conf<\/code><\/pre>\n\n\n\n<p><strong>Add this line at the end of the file and save it:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">kernel.perf_event_paranoid = -1<\/code><\/pre>\n\n\n\n<p><strong>Apply the changes: <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo sysctl -p<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-perf-record-amp-report-capturing-and-analyzing-performance-data\">Perf Record &amp; Report: Capturing and Analyzing Performance Data<\/h2>\n\n\n\n<p>While perf stat gives you a high-level overview, <code>perf record<\/code> and <code>perf report<\/code> let you dive deeper by sampling what your system is doing over time.<\/p>\n\n\n\n<p>The basic workflow is to use perf record to capture performance data and then analyze it with perf report. This powerful combination allows you to see exactly where your system is spending time, down to the specific functions.<\/p>\n\n\n\n<p><strong>Let&#8217;s see it in action:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"># Sample CPU stack traces at 99 Hz for 30 seconds\nperf record -F 99 -a -g -- sleep 30\n\n# Analyze the collected data\nperf report<\/code><\/pre>\n\n\n\n<p>The <code>-F 99<\/code> option sets the sampling frequency to <strong>99 <\/strong>Hz (samples per second), <code>-a<\/code> tells perf to monitor all CPUs, and <code>-g<\/code> enables call graph recording so you can see complete stack traces.<\/p>\n\n\n\n<p><strong>Why 99 Hz instead of a round number like 100<\/strong>? It&#8217;s a clever trick to avoid accidentally synchronizing with periodic system activities, which could skew your results.<\/p>\n\n\n\n<p>When you run <code>perf report<\/code>, you&#8217;ll see something like:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"534\" src=\"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2025\/05\/Analyze-the-collected-data-using-perf-report-command-1024x534.jpg\" alt=\"Analyze the collected data using perf report command\" class=\"wp-image-27651\"\/><\/figure>\n\n\n\n<p>This shows the functions where your CPU time is being spent, sorted by &#8220;<strong>overhead<\/strong>&#8221; (the percentage of samples captured in that function). The beauty of this approach is that you&#8217;re seeing real-world usage, not theoretical bottlenecks.<\/p>\n\n\n\n<p>I often describe perf record\/report as &#8220;putting your system under a microscope&#8221;\u2014it reveals details you simply can&#8217;t see with higher-level tools.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-advanced-perf-usage-tracing-specific-events\">Advanced Perf Usage: Tracing Specific Events<\/h2>\n\n\n\n<p><strong>perf_events <\/strong>can trace a wide range of events, including hardware events from CPU performance counters, software events based on kernel counters, kernel tracepoints, user-level tracepoints, and dynamic events using kprobes and uprobes.<\/p>\n\n\n\n<p>Here are some examples of more targeted perf commands:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-tracing-system-calls\">Tracing System Calls<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"># Count all system calls made by a command\nperf stat -e 'syscalls:sys_enter_*' command\n\n# Trace specific system calls with stack traces\nperf record -e 'syscalls:sys_enter_read' -ag<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-analyzing-disk-i-o\">Analyzing Disk I\/O<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"># Trace all block I\/O events\nperf record -e block:* -a\n\n# Track disk I\/O latency\nperf record -e block:block_rq_issue -e block:block_rq_complete -a<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-monitoring-network-activity\">Monitoring Network Activity<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"># Trace outbound TCP connections\nperf record -e syscalls:sys_enter_connect -ag\n\n# Track socket buffer consumption\nperf record -e 'skb:consume_skb' -ag<\/code><\/pre>\n\n\n\n<p>Each of these commands provides visibility into a different aspect of system behavior. The key is understanding what you&#8217;re looking for and choosing the appropriate events to trace.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-dynamic-tracing\">Dynamic Tracing <\/h2>\n\n\n\n<p>Dynamic tracing allows you to create custom instrumentation points anywhere in the kernel (using kprobes) or user-level applications (using uprobes). This capability lets you analyze what&#8217;s happening at very specific points in the code.<\/p>\n\n\n\n<p>For example, to trace a specific kernel function:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"># Add a dynamic probe to the tcp_sendmsg function\nperf probe --add tcp_sendmsg\n\n# Record traces of this function\nperf record -e probe:tcp_sendmsg -ag\n\n# Remove the probe when done\nperf probe --del tcp_sendmsg<\/code><\/pre>\n\n\n\n<p>If you have debug symbols installed, you can even probe specific lines within functions or access function arguments:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"># Show available variables in the tcp_sendmsg function\nperf probe -V tcp_sendmsg\n\n# Add a probe that captures the 'size' argument\nperf probe --add 'tcp_sendmsg size'<\/code><\/pre>\n\n\n\n<p>This level of flexibility is what makes perf_event such a powerful tool for performance debugging\u2014you can look at exactly what matters for your specific problem.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-real-world-example-diagnosing-a-performance-bottleneck\">Real-World Example: Diagnosing a Performance Bottleneck<\/h2>\n\n\n\n<p>Let&#8217;s explore a real-world scenario where perf_event can save the day. Imagine you&#8217;re running a web server that suddenly experiences high latency. Traditional monitoring shows high CPU usage but doesn&#8217;t tell you why.<\/p>\n\n\n\n<p><strong>Here&#8217;s how I&#8217;d approach this with perf:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>First, get a high-level view: <code>perf top -p $(pgrep -f \"web-server\")<\/code> This shows me real-time usage. Let&#8217;s say I notice high activity in SSL\/TLS functions.<\/li>\n\n\n\n<li>Next, I&#8217;d do a more detailed recording: <code>perf record -F 99 -p $(pgrep -f \"web-server\") -g -- sleep 60<\/code><\/li>\n\n\n\n<li>Analyze the results: <code>perf report --sort comm,dso,symbol<\/code> This might reveal that most time is spent in a specific encryption function.<\/li>\n\n\n\n<li>To confirm my suspicion, I could trace SSL library calls: <code>perf record -e probe:ssl_read -e probe:ssl_write -p $(pgrep -f \"web-server\")<\/code><\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-performance-visualization-with-flame-graphs\">Performance Visualization with Flame Graphs<\/h2>\n\n\n\n<p>While the text output of perf commands is informative, visualizing performance data can make patterns much more apparent. One of the most powerful visualization techniques for <strong>perf <\/strong>data is the <strong>flame graph<\/strong>.<\/p>\n\n\n\n<p><strong>Flame graphs<\/strong> display stack traces in a way that makes it immediately obvious where CPU time is being spent. Each rectangle represents a function in the stack, with the width proportional to how often it appears in the samples.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Example to create a flame graph:<\/h3>\n\n\n\n<p><strong>Download the FlameGraph tools: <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">git clone https:\/\/github.com\/brendangregg\/FlameGraph.git<\/code><\/pre>\n\n\n\n<p><strong>Collect stack traces with perf:<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">perf record -F 99 -a -g -- sleep 30<\/code><\/pre>\n\n\n\n<p><strong>Generate the flame graph: <\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">perf script | FlameGraph\/stackcollapse-perf.pl | FlameGraph\/flamegraph.pl > profile.svg<\/code><\/pre>\n\n\n\n<p>The<strong> resulting SVG file can be opened in any web browser.<\/strong> Functions consuming the most CPU time will be the widest bars, making bottlenecks visually obvious.<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" loading=\"lazy\" decoding=\"async\" width=\"896\" height=\"691\" src=\"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2025\/05\/Generate-the-flame-graph-using-perf-command.jpg\" alt=\"Generate the flame graph using perf command\" class=\"wp-image-27653\"\/><\/figure>\n\n\n\n<p>I&#8217;ve found flame graphs to be incredibly effective for communicating performance issues to team members who might not be familiar with performance analysis. A picture truly is worth a thousand perf reports!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-challenges-and-considerations-when-using-perf-event\">Challenges and Considerations When Using perf_event<\/h2>\n\n\n\n<p>While perf_event is incredibly powerful, it&#8217;s not without challenges:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-security-and-permissions\">Security and Permissions<\/h3>\n\n\n\n<p><strong>perf_events <\/strong>has significant security implications because it can potentially expose sensitive information. Linux implements security controls based on process credentials, dividing them into privileged (<strong>root<\/strong>) and unprivileged processes.<\/p>\n\n\n\n<p>By default,<strong> Linux restricts certain perf_event operations to privileged users.<\/strong> You can check the current settings:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">cat \/proc\/sys\/kernel\/perf_event_paranoid<\/code><\/pre>\n\n\n\n<p>Higher values impose more restrictions. You can temporarily lower this for testing, but be careful about security implications:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\">sudo sysctl kernel.perf_event_paranoid=1<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-overhead-considerations\">Overhead Considerations<\/h3>\n\n\n\n<p>While perf is designed to be lightweight, tracing can still introduce overhead. This is especially true when:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Using high sampling frequencies (e.g., <code>-F 1000<\/code> instead of <code>-F 99<\/code>)<\/li>\n\n\n\n<li>Tracing very frequent events like context switches or memory allocations<\/li>\n\n\n\n<li>Enabling stack traces (-g) for high-frequency events<\/li>\n<\/ul>\n\n\n\n<p>Always be mindful of the overhead, especially on production systems. Start with targeted, low-frequency tracing and increase only as needed.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-kernel-and-hardware-dependencies\">Kernel and Hardware Dependencies<\/h3>\n\n\n\n<p>Some perf features depend on:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Specific kernel configuration options<\/li>\n\n\n\n<li>CPU hardware capabilities<\/li>\n\n\n\n<li>Debug symbols availability<\/li>\n<\/ul>\n\n\n\n<p>These dependencies can limit what&#8217;s possible on some systems, especially in virtualized environments where hardware access may be restricted.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-beyond-basics-that-is-worth-exploring\">Beyond Basics &#8211; That Is Worth Exploring<\/h2>\n\n\n\n<p>As you become more comfortable with <strong>perf_event,<\/strong> here are some advanced topics worth exploring:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-ebpf-integration\">eBPF Integration<\/h3>\n\n\n\n<p>In newer Linux kernels (4.4+), perf has enhanced BPF support. This makes perf tracing programmable, transforming it from a mere counting and sampling tool to a fully programmable in-kernel tracer.<\/p>\n\n\n\n<p>BPF programs can filter events in kernel space, drastically reducing overhead for complex analyses.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-scheduler-analysis-with-perf-sched\">Scheduler Analysis with perf sched<\/h3>\n\n\n\n<p>The <code>perf sched<\/code> subcommand provides specialized tools for analyzing the kernel&#8217;s CPU scheduler behavior:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"># Record scheduler events\nperf sched record -- sleep 1\n\n# Analyze scheduler latencies\nperf sched latency<\/code><\/pre>\n\n\n\n<p>This is invaluable for diagnosing CPU scheduling issues and latency problems.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-hardware-cache-events\">Hardware Cache Events<\/h3>\n\n\n\n<p>Modern CPUs have extensive performance monitoring capabilities for their cache hierarchies:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code lang=\"bash\" class=\"language-bash\"># Analyze Level 1 data cache behavior\nperf stat -e L1-dcache-loads,L1-dcache-load-misses command<\/code><\/pre>\n\n\n\n<p>Understanding cache behavior is crucial for optimizing high-performance applications.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-faqs-about-perf-event\">FAQs About perf_event<\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1746556677613\"><strong class=\"schema-faq-question\">How does perf_event differ from other performance tools like top or htop?<\/strong> <p class=\"schema-faq-answer\">While tools like top provide a high-level system overview, perf_event gives you much deeper insights by accessing hardware performance counters and kernel tracepoints. Top shows you <em>which<\/em> processes are using resources; perf shows you <em>why<\/em> and <em>how<\/em> they&#8217;re using those resources.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1746556693592\"><strong class=\"schema-faq-question\">Is there a GUI for perf_event?<\/strong> <p class=\"schema-faq-answer\">While perf is primarily a command-line tool, there are several ways to visualize its data:<br\/>The built-in <code>perf report<\/code> TUI (Text User Interface)<br\/>Flame graphs (as discussed earlier)<br\/>External tools like <a href=\"https:\/\/github.com\/KDAB\/hotspot\">hotspot<\/a> or Intel VTune that can import perf data<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1746556722546\"><strong class=\"schema-faq-question\">Can perf_event monitor containers or virtual machines?<\/strong> <p class=\"schema-faq-answer\">Yes, but with some limitations. You can use perf to monitor processes inside containers on the same host. For virtual machines, you can use perf inside the VM to monitor guest activity, but monitoring the VM from the host requires special configuration.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1746556736120\"><strong class=\"schema-faq-question\">Does perf_event work on all Linux distributions?<\/strong> <p class=\"schema-faq-answer\">The core functionality works on all modern Linux distributions, but availability of specific features depends on:<br\/><br\/>&#8211; Kernel version and configuration<br\/>&#8211; Distribution-specific packages<br\/>&#8211; Hardware capabilities<br\/><br\/>Major distributions like Ubuntu, Fedora, and RHEL all include perf tools packages.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1746557867629\"><strong class=\"schema-faq-question\">How much overhead does perf_event introduce?<\/strong> <p class=\"schema-faq-answer\">It depends on how you use it. Simple counting with <code>perf stat<\/code> introduces minimal overhead (typically &lt;1%). Sampling with <code>perf record -F 99<\/code> might add 1-3% overhead. Heavy tracing of frequent events can introduce more significant overhead, potentially up to 10% or more.<\/p> <\/div> <\/div>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-conclusion-system-s-performance-with-perf-event\">Conclusion: System&#8217;s Performance with perf_event<\/h2>\n\n\n\n<p>Linux&#8217;s perf_event subsystem provides a powerful window into what&#8217;s really happening on your system, from the hardware to the application code.<\/p>\n\n\n\n<p>Whether you&#8217;re trying to optimize a high-performance application, diagnose a perplexing performance issue, or better understand your Linux system, perf_event is an invaluable tool.<\/p>\n\n\n\n<p>I encourage you to start small: try <code>perf stat<\/code> on a command you use regularly, or run <code>perf top<\/code> to see what&#8217;s happening on your system right now. As you get comfortable, gradually explore the more advanced features. Before long, you&#8217;ll wonder how you ever managed without this powerful tool.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>You might have an application on your Linux system running slower than expected, or need to diagnose mysterious performance issues. That&#8217;s where Linux&#8217;s perf_event subsystem comes in\u2014a powerful yet often underutilized performance monitoring tool built right into the kernel. This Linux guide is where I will discuss everything you need to know about perf_event\u2014from basic [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":27656,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_sitemap_exclude":false,"_sitemap_priority":"","_sitemap_frequency":"","_mbp_gutenberg_autopost":false,"footnotes":""},"categories":[4],"tags":[2293,1245,28,227,1267,31],"class_list":{"0":"post-27648","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-linux","8":"tag-command-line","9":"tag-commands","10":"tag-linux","11":"tag-linux-monitoring-tool","12":"tag-tools","13":"tag-tutorial"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.9 (Yoast SEO v27.5) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>What is perf_event in Linux? Linux Performance Monitoring - LinuxShout<\/title>\n<meta name=\"description\" content=\"Get Linux system insights with perf_event\u2014the kernel tool for diagnosing bottlenecks, tracing system calls, and optimizing application performance.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"What is perf_event in Linux? Linux Performance Monitoring\" \/>\n<meta property=\"og:description\" content=\"Get Linux system insights with perf_event\u2014the kernel tool for diagnosing bottlenecks, tracing system calls, and optimizing application performance.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/\" \/>\n<meta property=\"og:site_name\" content=\"LinuxShout\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/how2shout\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-06T19:11:12+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-06T19:11:22+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2025\/05\/What-is-perf_event-in-Linux.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1487\" \/>\n\t<meta property=\"og:image:height\" content=\"839\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Heyan Maurya\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@h2smedia\" \/>\n<meta name=\"twitter:site\" content=\"@h2smedia\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Heyan Maurya\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"TechArticle\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/\"},\"author\":{\"name\":\"Heyan Maurya\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#\\\/schema\\\/person\\\/102d73e20384ea409022d5bafddc0f72\"},\"headline\":\"What is perf_event in Linux? Linux Performance Monitoring\",\"datePublished\":\"2025-05-06T19:11:12+00:00\",\"dateModified\":\"2025-05-06T19:11:22+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/\"},\"wordCount\":2122,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linux.how2shout.com\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/What-is-perf_event-in-Linux.jpg\",\"keywords\":[\"command line\",\"commands\",\"Linux\",\"Linux monitoring tool\",\"tools\",\"tutorial\"],\"articleSection\":[\"Linux\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#respond\"]}],\"copyrightYear\":\"2025\",\"copyrightHolder\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#organization\"}},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/\",\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/\",\"name\":\"What is perf_event in Linux? Linux Performance Monitoring - LinuxShout\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/linux.how2shout.com\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/What-is-perf_event-in-Linux.jpg\",\"datePublished\":\"2025-05-06T19:11:12+00:00\",\"dateModified\":\"2025-05-06T19:11:22+00:00\",\"description\":\"Get Linux system insights with perf_event\u2014the kernel tool for diagnosing bottlenecks, tracing system calls, and optimizing application performance.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556677613\"},{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556693592\"},{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556722546\"},{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556736120\"},{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746557867629\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#primaryimage\",\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/What-is-perf_event-in-Linux.jpg\",\"contentUrl\":\"https:\\\/\\\/linux.how2shout.com\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/What-is-perf_event-in-Linux.jpg\",\"width\":1487,\"height\":839,\"caption\":\"Linux perf_event command interface showing CPU profiling results with flame graph visualization\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/linux.how2shout.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"What is perf_event in Linux? Linux Performance Monitoring\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#website\",\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/\",\"name\":\"LinuxShout\",\"description\":\"Find the open source solutions\",\"publisher\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#organization\"},\"alternateName\":\"Linux how2shout\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/linux.how2shout.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#organization\",\"name\":\"LinuxShout\",\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Linux-Shout-Logo.png\",\"contentUrl\":\"https:\\\/\\\/linux.how2shout.com\\\/wp-content\\\/uploads\\\/2020\\\/06\\\/Linux-Shout-Logo.png\",\"width\":503,\"height\":349,\"caption\":\"LinuxShout\"},\"image\":{\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/how2shout\",\"https:\\\/\\\/x.com\\\/h2smedia\",\"https:\\\/\\\/instagram.com\\\/h2smedia\",\"https:\\\/\\\/www.linkedin.com\\\/company\\\/h2smedia\\\/\",\"https:\\\/\\\/www.pinterest.com\\\/how2shout\",\"https:\\\/\\\/youtube.com\\\/h2smedia\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/#\\\/schema\\\/person\\\/102d73e20384ea409022d5bafddc0f72\",\"name\":\"Heyan Maurya\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b07b375c19891b0589da722cb1e3dff333ec63dd8467afc114611044e87cfe9a?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b07b375c19891b0589da722cb1e3dff333ec63dd8467afc114611044e87cfe9a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/b07b375c19891b0589da722cb1e3dff333ec63dd8467afc114611044e87cfe9a?s=96&d=mm&r=g\",\"caption\":\"Heyan Maurya\"},\"description\":\"I have a keen interest in all kinds of technologies, from consumer-tech to enterprise solutions. However, I am still trying to learn Linux and whatever the problems I face, trying to give solutions for the same, here...\",\"sameAs\":[\"https:\\\/\\\/www.how2shout.com\\\/\"],\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/author\\\/heyan\\\/\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556677613\",\"position\":1,\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556677613\",\"name\":\"How does perf_event differ from other performance tools like top or htop?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"While tools like top provide a high-level system overview, perf_event gives you much deeper insights by accessing hardware performance counters and kernel tracepoints. Top shows you <em>which<\\\/em> processes are using resources; perf shows you <em>why<\\\/em> and <em>how<\\\/em> they're using those resources.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556693592\",\"position\":2,\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556693592\",\"name\":\"Is there a GUI for perf_event?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"While perf is primarily a command-line tool, there are several ways to visualize its data:<br\\\/>The built-in perf report TUI (Text User Interface)<br\\\/>Flame graphs (as discussed earlier)<br\\\/>External tools like <a href=\\\"https:\\\/\\\/github.com\\\/KDAB\\\/hotspot\\\">hotspot<\\\/a> or Intel VTune that can import perf data\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556722546\",\"position\":3,\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556722546\",\"name\":\"Can perf_event monitor containers or virtual machines?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes, but with some limitations. You can use perf to monitor processes inside containers on the same host. For virtual machines, you can use perf inside the VM to monitor guest activity, but monitoring the VM from the host requires special configuration.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556736120\",\"position\":4,\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746556736120\",\"name\":\"Does perf_event work on all Linux distributions?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"The core functionality works on all modern Linux distributions, but availability of specific features depends on:<br\\\/><br\\\/>- Kernel version and configuration<br\\\/>- Distribution-specific packages<br\\\/>- Hardware capabilities<br\\\/><br\\\/>Major distributions like Ubuntu, Fedora, and RHEL all include perf tools packages.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746557867629\",\"position\":5,\"url\":\"https:\\\/\\\/linux.how2shout.com\\\/what-is-perf_event-in-linux-linux-performance-monitoring\\\/#faq-question-1746557867629\",\"name\":\"How much overhead does perf_event introduce?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"It depends on how you use it. Simple counting with perf stat introduces minimal overhead (typically &lt;1%). Sampling with perf record -F 99 might add 1-3% overhead. Heavy tracing of frequent events can introduce more significant overhead, potentially up to 10% or more.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"What is perf_event in Linux? Linux Performance Monitoring - LinuxShout","description":"Get Linux system insights with perf_event\u2014the kernel tool for diagnosing bottlenecks, tracing system calls, and optimizing application performance.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/","og_locale":"en_US","og_type":"article","og_title":"What is perf_event in Linux? Linux Performance Monitoring","og_description":"Get Linux system insights with perf_event\u2014the kernel tool for diagnosing bottlenecks, tracing system calls, and optimizing application performance.","og_url":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/","og_site_name":"LinuxShout","article_publisher":"https:\/\/www.facebook.com\/how2shout","article_published_time":"2025-05-06T19:11:12+00:00","article_modified_time":"2025-05-06T19:11:22+00:00","og_image":[{"width":1487,"height":839,"url":"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2025\/05\/What-is-perf_event-in-Linux.jpg","type":"image\/jpeg"}],"author":"Heyan Maurya","twitter_card":"summary_large_image","twitter_creator":"@h2smedia","twitter_site":"@h2smedia","twitter_misc":{"Written by":"Heyan Maurya","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"TechArticle","@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#article","isPartOf":{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/"},"author":{"name":"Heyan Maurya","@id":"https:\/\/linux.how2shout.com\/#\/schema\/person\/102d73e20384ea409022d5bafddc0f72"},"headline":"What is perf_event in Linux? Linux Performance Monitoring","datePublished":"2025-05-06T19:11:12+00:00","dateModified":"2025-05-06T19:11:22+00:00","mainEntityOfPage":{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/"},"wordCount":2122,"commentCount":0,"publisher":{"@id":"https:\/\/linux.how2shout.com\/#organization"},"image":{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#primaryimage"},"thumbnailUrl":"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2025\/05\/What-is-perf_event-in-Linux.jpg","keywords":["command line","commands","Linux","Linux monitoring tool","tools","tutorial"],"articleSection":["Linux"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#respond"]}],"copyrightYear":"2025","copyrightHolder":{"@id":"https:\/\/linux.how2shout.com\/#organization"}},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/","url":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/","name":"What is perf_event in Linux? Linux Performance Monitoring - LinuxShout","isPartOf":{"@id":"https:\/\/linux.how2shout.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#primaryimage"},"image":{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#primaryimage"},"thumbnailUrl":"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2025\/05\/What-is-perf_event-in-Linux.jpg","datePublished":"2025-05-06T19:11:12+00:00","dateModified":"2025-05-06T19:11:22+00:00","description":"Get Linux system insights with perf_event\u2014the kernel tool for diagnosing bottlenecks, tracing system calls, and optimizing application performance.","breadcrumb":{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556677613"},{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556693592"},{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556722546"},{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556736120"},{"@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746557867629"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#primaryimage","url":"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2025\/05\/What-is-perf_event-in-Linux.jpg","contentUrl":"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2025\/05\/What-is-perf_event-in-Linux.jpg","width":1487,"height":839,"caption":"Linux perf_event command interface showing CPU profiling results with flame graph visualization"},{"@type":"BreadcrumbList","@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/linux.how2shout.com\/"},{"@type":"ListItem","position":2,"name":"What is perf_event in Linux? Linux Performance Monitoring"}]},{"@type":"WebSite","@id":"https:\/\/linux.how2shout.com\/#website","url":"https:\/\/linux.how2shout.com\/","name":"LinuxShout","description":"Find the open source solutions","publisher":{"@id":"https:\/\/linux.how2shout.com\/#organization"},"alternateName":"Linux how2shout","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/linux.how2shout.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/linux.how2shout.com\/#organization","name":"LinuxShout","url":"https:\/\/linux.how2shout.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/linux.how2shout.com\/#\/schema\/logo\/image\/","url":"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2020\/06\/Linux-Shout-Logo.png","contentUrl":"https:\/\/linux.how2shout.com\/wp-content\/uploads\/2020\/06\/Linux-Shout-Logo.png","width":503,"height":349,"caption":"LinuxShout"},"image":{"@id":"https:\/\/linux.how2shout.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/how2shout","https:\/\/x.com\/h2smedia","https:\/\/instagram.com\/h2smedia","https:\/\/www.linkedin.com\/company\/h2smedia\/","https:\/\/www.pinterest.com\/how2shout","https:\/\/youtube.com\/h2smedia"]},{"@type":"Person","@id":"https:\/\/linux.how2shout.com\/#\/schema\/person\/102d73e20384ea409022d5bafddc0f72","name":"Heyan Maurya","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/b07b375c19891b0589da722cb1e3dff333ec63dd8467afc114611044e87cfe9a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/b07b375c19891b0589da722cb1e3dff333ec63dd8467afc114611044e87cfe9a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b07b375c19891b0589da722cb1e3dff333ec63dd8467afc114611044e87cfe9a?s=96&d=mm&r=g","caption":"Heyan Maurya"},"description":"I have a keen interest in all kinds of technologies, from consumer-tech to enterprise solutions. However, I am still trying to learn Linux and whatever the problems I face, trying to give solutions for the same, here...","sameAs":["https:\/\/www.how2shout.com\/"],"url":"https:\/\/linux.how2shout.com\/author\/heyan\/"},{"@type":"Question","@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556677613","position":1,"url":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556677613","name":"How does perf_event differ from other performance tools like top or htop?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"While tools like top provide a high-level system overview, perf_event gives you much deeper insights by accessing hardware performance counters and kernel tracepoints. Top shows you <em>which<\/em> processes are using resources; perf shows you <em>why<\/em> and <em>how<\/em> they're using those resources.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556693592","position":2,"url":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556693592","name":"Is there a GUI for perf_event?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"While perf is primarily a command-line tool, there are several ways to visualize its data:<br\/>The built-in perf report TUI (Text User Interface)<br\/>Flame graphs (as discussed earlier)<br\/>External tools like <a href=\"https:\/\/github.com\/KDAB\/hotspot\">hotspot<\/a> or Intel VTune that can import perf data","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556722546","position":3,"url":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556722546","name":"Can perf_event monitor containers or virtual machines?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes, but with some limitations. You can use perf to monitor processes inside containers on the same host. For virtual machines, you can use perf inside the VM to monitor guest activity, but monitoring the VM from the host requires special configuration.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556736120","position":4,"url":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746556736120","name":"Does perf_event work on all Linux distributions?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"The core functionality works on all modern Linux distributions, but availability of specific features depends on:<br\/><br\/>- Kernel version and configuration<br\/>- Distribution-specific packages<br\/>- Hardware capabilities<br\/><br\/>Major distributions like Ubuntu, Fedora, and RHEL all include perf tools packages.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746557867629","position":5,"url":"https:\/\/linux.how2shout.com\/what-is-perf_event-in-linux-linux-performance-monitoring\/#faq-question-1746557867629","name":"How much overhead does perf_event introduce?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"It depends on how you use it. Simple counting with perf stat introduces minimal overhead (typically &lt;1%). Sampling with perf record -F 99 might add 1-3% overhead. Heavy tracing of frequent events can introduce more significant overhead, potentially up to 10% or more.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/posts\/27648","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/comments?post=27648"}],"version-history":[{"count":5,"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/posts\/27648\/revisions"}],"predecessor-version":[{"id":27660,"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/posts\/27648\/revisions\/27660"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/media\/27656"}],"wp:attachment":[{"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/media?parent=27648"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/categories?post=27648"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/linux.how2shout.com\/wp-json\/wp\/v2\/tags?post=27648"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}