{"id":5234,"date":"2020-03-19T21:54:48","date_gmt":"2020-03-19T18:54:48","guid":{"rendered":"https:\/\/kifarunix.com\/?p=5234"},"modified":"2020-03-19T21:54:50","modified_gmt":"2020-03-19T18:54:50","slug":"installing-perf-performance-analysis-tool-on-centos-8","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/installing-perf-performance-analysis-tool-on-centos-8\/","title":{"rendered":"Installing Perf Performance Analysis Tool on CentOS 8"},"content":{"rendered":"\n<p>In this guide, we are going to learn on installing Perf Performance Analysis Tool on CentOS 8. Perf aka <code><strong>perf_events<\/strong><\/code> aka <code><strong>perf tools<\/strong><\/code> is a powerful performance counters monitoring tool for Linux systems that gathers data about hardware events such as instructions executed, branches mispredicted or cache-misses suffered.<\/p>\n\n\n\n<p>It also provides very low overhead profiling of applications to trace dynamic control flow and identify hotspots, per task, per CPU and per-workload counters, sampling and source code event annotation, dynamic creation of tracepoints using the kprobes and uprobes frameworks, for kernel and userspace dynamic tracing respectively.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Installing Perf Performance Analysis Tool on CentOS 8<\/h2>\n\n\n\n<p>Perf provide a userspace controlling utility called <code><strong>perf<\/strong><\/code>. You need to install this Perf userland utility in order to be able to use Perf on command line.<\/p>\n\n\n\n<p>Perf is available on the default CentOS 8 repos through the <code>perf<\/code> package<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf info perf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Available Packages\nName         : perf\nVersion      : 4.18.0\nRelease      : 147.5.1.el8_1\nArchitecture : x86_64\nSize         : 3.4 M\nSource       : kernel-4.18.0-147.5.1.el8_1.src.rpm\nRepository   : BaseOS\nSummary      : Performance monitoring for the Linux kernel\nURL          : http:\/\/www.kernel.org\/\nLicense      : GPLv2\nDescription  : This package contains the perf tool, which enables performance monitoring\n             : of the Linux kernel.<\/code><\/pre>\n\n\n\n<p>Run system update.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf update<\/code><\/pre>\n\n\n\n<p>Install Perf on CentOS 8<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>dnf install perf<\/code><\/pre>\n\n\n\n<p>The basic command line Syntax of perf utility is;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf [--version] [--help] [OPTIONS] COMMAND [ARGS]<\/code><\/pre>\n\n\n\n<p>The most common perf sub-commands include;<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><code>stat<\/code>: runs a command and gathers performance counter statistics from it.<\/li><li><code>top<\/code>: generates and displays a performance counter profile in real time.<\/li><li><code>record<\/code>: runs a command and gathers a performance counter profile from it. The gathered data is saved into\u00a0<code>perf.data<\/code>\u00a0without displaying anything.<\/li><li><code>report<\/code>: It reads\u00a0<code>perf.data<\/code>\u00a0to display the performance counter profile information recorded via perf record sub-command.<\/li><li><code>list<\/code>: displays the symbolic event types which can be selected in the various perf commands with the -e option.<\/li><li><code>trace<\/code>: Just like strace, perf trace sub-command shows various system calls being executed by a particular thread or process and the signals it receives.<\/li><li><code>annotate<\/code>: Perf annotate command displays a report file and an annotated version of the executed code.<\/li><\/ul>\n\n\n\n<p>If you just type perf command on the terminal, you should be able to see quite a number of subcommands;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>perf\n\n usage: perf &#91;--version] &#91;--help] &#91;OPTIONS] COMMAND &#91;ARGS]\n\n The most commonly used perf commands are:\n   annotate        Read perf.data (created by perf record) and display annotated code\n   archive         Create archive with object files with build-ids found in perf.data file\n   bench           General framework for benchmark suites\n   buildid-cache   Manage build-id cache.\n   buildid-list    List the buildids in a perf.data file\n   c2c             Shared Data C2C\/HITM Analyzer.\n   config          Get and set variables in a configuration file.\n   data            Data file related processing\n   diff            Read perf.data files and display the differential profile\n   evlist          List the event names in a perf.data file\n   ftrace          simple wrapper for kernel's ftrace functionality\n   inject          Filter to augment the events stream with additional information\n   kallsyms        Searches running kernel for symbols\n   kmem            Tool to trace\/measure kernel memory properties\n   kvm             Tool to trace\/measure kvm guest os\n   list            List all symbolic event types\n   lock            Analyze lock events\n   mem             Profile memory accesses\n   record          Run a command and record its profile into perf.data\n   report          Read perf.data (created by perf record) and display the profile\n   sched           Tool to trace\/measure scheduler properties (latencies)\n   script          Read perf.data (created by perf record) and display trace output\n   stat            Run a command and gather performance counter statistics\n   test            Runs sanity tests.\n   timechart       Tool to visualize total system behavior during a workload\n   top             System profiling tool.\n   version         display the version of perf binary\n   probe           Define new dynamic tracepoints\n   trace           strace inspired tool<\/code><\/pre>\n\n\n\n<p>To obtain help about a specific sub-command, just execute;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf help SUB-COMMAND<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Example Usage of Perf on CentOS 8<\/h3>\n\n\n\n<p>Next, let us go over a few example usage of perf command on CentOS 8 and similar derivatives.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Gather Command Performance Counter statistics<\/h4>\n\n\n\n<p>The stat sub-command of perf utility enables you to run a command and gather its performance counter statistics<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf stat ls<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>con  file  file1\n\n Performance counter stats for 'ls':\n\n              1.72 msec task-clock                #    0.827 CPUs utilized          \n                 0      context-switches          #    0.000 K\/sec                  \n                 0      cpu-migrations            #    0.000 K\/sec                  \n               108      page-faults               #    0.063 M\/sec                  \n   &lt;not supported>      cycles                                                      \n   &lt;not supported>      instructions                                                \n   &lt;not supported>      branches                                                    \n   &lt;not supported>      branch-misses                                               \n\n       0.002075544 seconds time elapsed\n\n       0.002106000 seconds user\n       0.000000000 seconds sys<\/code><\/pre>\n\n\n\n<p>Read more on <code><strong>man perf-stat<\/strong><\/code>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Display Live Performance Counter Profile<\/h4>\n\n\n\n<p>perf-top is a system profiling tool used to generate and display a performance counter profile in real time. This can be achieved using the <code><strong>perf top<\/strong><\/code> command.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf top<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Samples: 29  of event 'cpu-clock', 4000 Hz, Event count (approx.): 7250000 lost: 0\/0 drop: 0\/0                                                         \nOverhead  Shared Object  Symbol                                                                                                                         \n  34.48%  &#91;kernel]      &#91;k] e1000_watchdog\n  13.79%  &#91;kernel]      &#91;k] _raw_spin_unlock_irqrestore\n   6.90%  &#91;kernel]      &#91;k] format_decode\n   6.90%  &#91;kernel]      &#91;k] vsnprintf\n   3.45%  &#91;kernel]      &#91;k] __x86_indirect_thunk_rax\n   3.45%  &#91;kernel]      &#91;k] __x86_indirect_thunk_rdx\n   3.45%  &#91;kernel]      &#91;k] kallsyms_expand_symbol.constprop.1\n   3.45%  &#91;kernel]      &#91;k] mem_cgroup_throttle_swaprate\n   3.45%  &#91;kernel]      &#91;k] memcpy\n   3.45%  &#91;kernel]      &#91;k] number\n   3.45%  &#91;kernel]      &#91;k] update_iter\n   3.45%  libc-2.28.so  &#91;.] _IO_getdelim\n   3.45%  libc-2.28.so  &#91;.] __memmove_avx_unaligned\n   3.45%  perf          &#91;.] dso__next_symbol\n   3.45%  perf          &#91;.] rb_next\n...<\/code><\/pre>\n\n\n\n<p>Consult <strong><code>man perf-top<\/code><\/strong> to see more usage.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">List all symbolic event types<\/h4>\n\n\n\n<p>To list all symbolic event types using perf command;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf list<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>  alignment-faults                                   &#91;Software event]\n  bpf-output                                         &#91;Software event]\n  context-switches OR cs                             &#91;Software event]\n  cpu-clock                                          &#91;Software event]\n...\n  msr\/pperf\/                                         &#91;Kernel PMU event]\n  msr\/smi\/                                           &#91;Kernel PMU event]\n  msr\/tsc\/                                           &#91;Kernel PMU event]\n...\n  rNNN                                               &#91;Raw hardware event descriptor]\n  cpu\/t1=v1&#91;,t2=v2,t3 ...]\/modifier                  &#91;Raw hardware event descriptor]\n   (see 'man perf-list' on how to encode it)\n\n  mem:&lt;addr>&#91;\/len]&#91;:access]                          &#91;Hardware breakpoint]\n...<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Record Command Profile<\/h4>\n\n\n\n<p>To run a command and record its profile into perf.data;<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf record ls -ld \/etc<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>drwxr-xr-x. 78 root root 8192 Mar 19 20:32 \/etc\n&#91; perf record: Woken up 1 times to write data ]\n&#91; perf record: Captured and wrote 0.011 MB perf.data ]<\/code><\/pre>\n\n\n\n<p>The basic syntax and a comprehensive description of using perf record command is stated on\u00a0<code>man perf-record<\/code>.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf record -e cpu-clock -a -g -- sleep 3<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>&#91; perf record: Woken up 2 times to write data ]\n&#91; perf record: Captured and wrote 0.628 MB perf.data (4514 samples) ]<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Read perf.data and display the profile<\/h4>\n\n\n\n<p>To read the performance record, use the report sub-command. The command syntax is&nbsp;<code>perf report [-i &lt;file&gt; | --input=file]<\/code><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>perf report -i perf.data<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>Samples: 4K of event 'cpu-clock', Event count (approx.): 1128500000                                                                                    \n  Children      Self  Command          Shared Object      Symbol                                                                                       \n+   99.87%    99.87%  swapper          &#91;kernel.kallsyms]  &#91;k] mwait_idle\n+   99.87%     0.00%  swapper          &#91;kernel.kallsyms]  &#91;k] secondary_startup_64\n+   99.87%     0.00%  swapper          &#91;kernel.kallsyms]  &#91;k] start_kernel\n+   99.87%     0.00%  swapper          &#91;kernel.kallsyms]  &#91;k] cpu_startup_entry\n+   99.87%     0.00%  swapper          &#91;kernel.kallsyms]  &#91;k] do_idle\n     0.13%     0.00%  kworker\/0:3-eve  &#91;kernel.kallsyms]  &#91;k] ret_from_fork\n     0.13%     0.00%  kworker\/0:3-eve  &#91;kernel.kallsyms]  &#91;k] kthread\n     0.13%     0.00%  kworker\/0:3-eve  &#91;kernel.kallsyms]  &#91;k] worker_thread\n     0.13%     0.00%  kworker\/0:3-eve  &#91;kernel.kallsyms]  &#91;k] process_one_work\n     0.11%     0.09%  kworker\/0:3-eve  &#91;kernel.kallsyms]  &#91;k] e1000_watchdog\n...<\/code><\/pre>\n\n\n\n<p>Well, Perf tool is quite a comprehensive command and we can&#8217;t exhaust all if its usage in a simple introductory guide.<\/p>\n\n\n\n<p>To read more about Perf Performance Analysis Tool, check;<\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"Perf Wiki (opens in a new tab)\" href=\"https:\/\/perf.wiki.kernel.org\/index.php\/Main_Page\" target=\"_blank\">Perf Wiki<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"Linux Perf Examples (opens in a new tab)\" href=\"http:\/\/www.brendangregg.com\/perf.html\" target=\"_blank\">Linux Perf Examples<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\"Perf Events and tool security (opens in a new tab)\" href=\"https:\/\/www.kernel.org\/doc\/html\/latest\/admin-guide\/perf-security.html\" target=\"_blank\">Perf Events and tool security<\/a><\/p>\n\n\n\n<p>Want to install Perf on Ubuntu 18.04?<\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/installing-perf-performance-analysis-tool-on-ubuntu-18-04\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Installing Perf Performance Analysis Tool on Ubuntu 18.04<\/a><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Other Tutorials<\/h3>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/how-to-perform-system-security-auditing-with-lynis-on-ubuntu-18-04\/\" target=\"_blank\">How to Perform System Security Auditing with Lynis on Ubuntu 18.04<\/a><\/p>\n\n\n\n<p><a rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\" href=\"https:\/\/kifarunix.com\/install-and-setup-adiscon-loganalyzer-on-centos-8\/\" target=\"_blank\">Install and Setup Adiscon LogAnalyzer on CentOS 8<\/a><\/p>\n\n\n\n<p><a href=\"https:\/\/kifarunix.com\/restrict-sftp-user-access-to-specific-directories-in-linux\/\" target=\"_blank\" rel=\"noreferrer noopener\" aria-label=\" (opens in a new tab)\">Restrict SFTP User Access to Specific Directories in Linux<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we are going to learn on installing Perf Performance Analysis Tool on CentOS 8. Perf aka perf_events aka perf tools is a<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[49,1358],"tags":[1359,332,1360,1361],"class_list":["post-5234","post","type-post","status-publish","format-standard","hentry","category-command-cheatsheets","category-perf","tag-install-perf-centos-8","tag-perf","tag-perf-command-usage","tag-perf-examples","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5234"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=5234"}],"version-history":[{"count":1,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5234\/revisions"}],"predecessor-version":[{"id":5235,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/5234\/revisions\/5235"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=5234"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=5234"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=5234"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}