'\" t
.\"     Title: perf-top
.\"    Author: [see the "AUTHOR(S)" section]
.\" Generator: Asciidoctor 2.0.23
.\"      Date: 2025-04-10
.\"    Manual: perf Manual
.\"    Source: perf
.\"  Language: English
.\"
.TH "PERF\-TOP" "1" "2025-04-10" "perf" "perf Manual"
.ie \n(.g .ds Aq \(aq
.el       .ds Aq '
.ss \n[.ss] 0
.nh
.ad l
.de URL
\fI\\$2\fP <\\$1>\\$3
..
.als MTO URL
.if \n[.g] \{\
.  mso www.tmac
.  am URL
.    ad l
.  .
.  am MTO
.    ad l
.  .
.  LINKSTYLE blue R < >
.\}
.SH "NAME"
perf-top \- System profiling tool.
.SH "SYNOPSIS"
.sp
.nf
\fIperf top\fP [\-e <EVENT> | \-\-event=EVENT] [<options>]
.fi
.br
.SH "DESCRIPTION"
.sp
This command generates and displays a performance counter profile in real time.
.SH "OPTIONS"
.sp
\-a, \-\-all\-cpus
.RS 4
System\-wide collection.  (default)
.RE
.sp
\-c <count>, \-\-count=<count>
.RS 4
Event period to sample.
.RE
.sp
\-C <cpu\-list>, \-\-cpu=<cpu>
.RS 4
Monitor only on the list of CPUs provided. Multiple CPUs can be provided as a
comma\-separated list with no space: 0,1. Ranges of CPUs are specified with \-: 0\-2.
Default is to monitor all CPUS.
.RE
.sp
\-d <seconds>, \-\-delay=<seconds>
.RS 4
Number of seconds to delay between refreshes.
.RE
.sp
\-e <event>, \-\-event=<event>
.RS 4
Select the PMU event. Selection can be a symbolic event name
(use \fIperf list\fP to list all events) or a raw PMU event in the form
of rN where N is a hexadecimal value that represents the raw register
encoding with the layout of the event control registers as described
by entries in /sys/bus/event_source/devices/cpu/format/*.
.RE
.sp
\-\-filter=<filter>
.RS 4
Event filter.  This option should follow an event selector (\-e). For
syntax see perf\-record(1).
.RE
.sp
\-E <entries>, \-\-entries=<entries>
.RS 4
Display this many functions.
.RE
.sp
\-f <count>, \-\-count\-filter=<count>
.RS 4
Only display functions with more events than this.
.RE
.sp
\-\-group\-sort\-idx
.RS 4
Sort the output by the event at the index n in group. If n is invalid,
sort by the first event. It can support multiple groups with different
amount of events. WARNING: This should be used on grouped events.
.RE
.sp
\-F <freq>, \-\-freq=<freq>
.RS 4
Profile at this frequency. Use \fImax\fP to use the currently maximum
allowed frequency, i.e. the value in the kernel.perf_event_max_sample_rate
sysctl.
.RE
.sp
\-i, \-\-inherit
.RS 4
Child tasks do not inherit counters.
.RE
.sp
\-k <path>, \-\-vmlinux=<path>
.RS 4
Path to vmlinux.  Required for annotation functionality.
.RE
.sp
\-\-ignore\-vmlinux
.RS 4
Ignore vmlinux files.
.RE
.sp
\-\-kallsyms=<file>
.RS 4
kallsyms pathname
.RE
.sp
\-m <pages>, \-\-mmap\-pages=<pages>
.RS 4
Number of mmap data pages (must be a power of two) or size
specification in bytes with appended unit character \- B/K/M/G.
The size is rounded up to the nearest power\-of\-two page value.
.RE
.sp
\-p <pid>, \-\-pid=<pid>
.RS 4
Profile events on existing Process ID (comma separated list).
.RE
.sp
\-t <tid>, \-\-tid=<tid>
.RS 4
Profile events on existing thread ID (comma separated list).
.RE
.sp
\-u, \-\-uid=
.RS 4
Record events in threads owned by uid. Name or number.
.RE
.sp
\-r <priority>, \-\-realtime=<priority>
.RS 4
Collect data with this RT SCHED_FIFO priority.
.RE
.sp
\-\-sym\-annotate=<symbol>
.RS 4
Annotate this symbol.
.RE
.sp
\-K, \-\-hide_kernel_symbols
.RS 4
Hide kernel symbols.
.RE
.sp
\-U, \-\-hide_user_symbols
.RS 4
Hide user symbols.
.RE
.sp
\-\-demangle\-kernel
.RS 4
Demangle kernel symbols.
.RE
.sp
\-D, \-\-dump\-symtab
.RS 4
Dump the symbol table used for profiling.
.RE
.sp
\-v, \-\-verbose
.RS 4
Be more verbose (show counter open errors, etc).
.RE
.sp
\-z, \-\-zero
.RS 4
Zero history across display updates.
.RE
.sp
\-s, \-\-sort
.RS 4
Sort by key(s): pid, comm, dso, symbol, parent, srcline, weight,
local_weight, abort, in_tx, transaction, overhead, sample, period.
Please see description of \-\-sort in the perf\-report man page.
.RE
.sp
\-\-fields=
.RS 4
Specify output field \- multiple keys can be specified in CSV format.
Following fields are available:
overhead, overhead_sys, overhead_us, overhead_children, sample and period.
Also it can contain any sort key(s).
.sp
.if n .RS 4
.nf
.fam C
By default, every sort keys not specified in \-\-field will be appended
automatically.
.fam
.fi
.if n .RE
.RE
.sp
\-n, \-\-show\-nr\-samples
.RS 4
Show a column with the number of samples.
.RE
.sp
\-\-show\-total\-period
.RS 4
Show a column with the sum of periods.
.RE
.sp
\-\-dsos
.RS 4
Only consider symbols in these dsos.  This option will affect the
percentage of the overhead column.  See \-\-percentage for more info.
.RE
.sp
\-\-comms
.RS 4
Only consider symbols in these comms.  This option will affect the
percentage of the overhead column.  See \-\-percentage for more info.
.RE
.sp
\-\-symbols
.RS 4
Only consider these symbols.  This option will affect the
percentage of the overhead column.  See \-\-percentage for more info.
.RE
.sp
\-M, \-\-disassembler\-style=
.RS 4
Set disassembler style for objdump.
.RE
.sp
\-\-addr2line=<path>
.RS 4
Path to addr2line binary.
.RE
.sp
\-\-objdump=<path>
.RS 4
Path to objdump binary.
.RE
.sp
\-\-prefix=PREFIX, \-\-prefix\-strip=N
.RS 4
Remove first N entries from source file path names in executables
and add PREFIX. This allows to display source code compiled on systems
with different file system layout.
.RE
.sp
\-\-source
.RS 4
Interleave source code with assembly code. Enabled by default,
disable with \-\-no\-source.
.RE
.sp
\-\-asm\-raw
.RS 4
Show raw instruction encoding of assembly instructions.
.RE
.sp
\-g
.RS 4
Enables call\-graph (stack chain/backtrace) recording.
.RE
.sp
\-\-call\-graph [mode,type,min[,limit],order[,key][,branch]]
.RS 4
Setup and enable call\-graph (stack chain/backtrace) recording,
implies \-g.  See \f(CR\-\-call\-graph\fP section in perf\-record and
perf\-report man pages for details.
.RE
.sp
\-\-children
.RS 4
Accumulate callchain of children to parent entry so that then can
show up in the output.  The output will have a new "Children" column
and will be sorted on the data.  It requires \-g/\-\-call\-graph option
enabled.  See the \(oqoverhead calculation\(cq section for more details.
Enabled by default, disable with \-\-no\-children.
.RE
.sp
\-\-max\-stack
.RS 4
Set the stack depth limit when parsing the callchain, anything
beyond the specified depth will be ignored. This is a trade\-off
between information loss and faster processing especially for
workloads that can have a very long callchain stack.
.sp
.if n .RS 4
.nf
.fam C
Default: /proc/sys/kernel/perf_event_max_stack when present, 127 otherwise.
.fam
.fi
.if n .RE
.RE
.sp
\-\-ignore\-callees=<regex>
.RS 4
Ignore callees of the function(s) matching the given regex.
This has the effect of collecting the callers of each such
function into one place in the call\-graph tree.
.RE
.sp
\-\-percent\-limit
.RS 4
Do not show entries which have an overhead under that percent.
(Default: 0).
.RE
.sp
\-\-percentage
.RS 4
Determine how to display the overhead percentage of filtered entries.
Filters can be applied by \-\-comms, \-\-dsos and/or \-\-symbols options and
Zoom operations on the TUI (thread, dso, etc).
.sp
.if n .RS 4
.nf
.fam C
"relative" means it\*(Aqs relative to filtered entries only so that the
sum of shown entries will be always 100%. "absolute" means it retains
the original value before and after the filter is applied.
.fam
.fi
.if n .RE
.RE
.sp
\-w, \-\-column\-widths=<width[,width...]>
.RS 4
Force each column width to the provided list, for large terminal
readability.  0 means no limit (default behavior).
.RE
.sp
\-\-proc\-map\-timeout
.RS 4
When processing pre\-existing threads /proc/XXX/mmap, it may take
a long time, because the file may be huge. A time out is needed
in such cases.
This option sets the time out limit. The default value is 500 ms.
.RE
.sp
\-b, \-\-branch\-any
.RS 4
Enable taken branch stack sampling. Any type of taken branch may be sampled.
This is a shortcut for \-\-branch\-filter any. See \-\-branch\-filter for more infos.
.RE
.sp
\-j, \-\-branch\-filter
.RS 4
Enable taken branch stack sampling. Each sample captures a series of consecutive
taken branches. The number of branches captured with each sample depends on the
underlying hardware, the type of branches of interest, and the executed code.
It is possible to select the types of branches captured by enabling filters.
For a full list of modifiers please see the perf record manpage.
.sp
.if n .RS 4
.nf
.fam C
The option requires at least one branch type among any, any_call, any_ret, ind_call, cond.
The privilege levels may be omitted, in which case, the privilege levels of the associated
event are applied to the branch filter. Both kernel (k) and hypervisor (hv) privilege
levels are subject to permissions.\&  When sampling on multiple events, branch stack sampling
is enabled for all the sampling events. The sampled branch type is the same for all events.
The various filters must be specified as a comma separated list: \-\-branch\-filter any_ret,u,k
Note that this feature may not be available on all processors.
.fam
.fi
.if n .RE
.RE
.sp
\-\-branch\-history
.RS 4
Add the addresses of sampled taken branches to the callstack.
This allows to examine the path the program took to each sample.
.RE
.sp
\-\-raw\-trace
.RS 4
When displaying traceevent output, do not use print fmt or plugins.
.RE
.sp
\-H, \-\-hierarchy
.RS 4
Enable hierarchical output.  In the hierarchy mode, each sort key groups
samples based on the criteria and then sub\-divide it using the lower
level sort key.
.sp
.if n .RS 4
.nf
.fam C
For example, in normal output:
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
perf report \-s dso,sym
#
# Overhead\&  Shared Object\&      Symbol
# ........\&  .................\&  ...........
    50.00%\&  [kernel.kallsyms]\&  [k] kfunc1
    20.00%\&  perf\&               [.] foo
    15.00%\&  [kernel.kallsyms]\&  [k] kfunc2
    10.00%\&  perf\&               [.] bar
     5.00%\&  libc.so\&            [.] libcall
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
In hierarchy output:
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
perf report \-s dso,sym \-\-hierarchy
#
#\&   Overhead\&  Shared Object / Symbol
# ..........\&  ......................
    65.00%\&    [kernel.kallsyms]
      50.00%\&    [k] kfunc1
      15.00%\&    [k] kfunc2
    30.00%\&    perf
      20.00%\&    [.] foo
      10.00%\&    [.] bar
     5.00%\&    libc.so
       5.00%\&    [.] libcall
.fam
.fi
.if n .RE
.RE
.sp
\-\-overwrite
.RS 4
Enable this to use just the most recent records, which helps in high core count
machines such as Knights Landing/Mill, but right now is disabled by default as
the pausing used in this technique is leading to loss of metadata events such
as PERF_RECORD_MMAP which makes \fIperf top\fP unable to resolve samples, leading
to lots of unknown samples appearing on the UI. Enable this if you are in such
machines and profiling a workload that doesn\(cqt creates short lived threads and/or
doesn\(cqt uses many executable mmap operations. Work is being planed to solve
this situation, till then, this will remain disabled by default.
.RE
.sp
\-\-force
.RS 4
Don\(cqt do ownership validation.
.RE
.sp
\-\-num\-thread\-synthesize
.RS 4
The number of threads to run when synthesizing events for existing processes.
By default, the number of threads equals to the number of online CPUs.
.RE
.sp
\-\-namespaces
.RS 4
Record events of type PERF_RECORD_NAMESPACES and display it with the
\fIcgroup_id\fP sort key.
.RE
.sp
\-G name, \-\-cgroup name
.RS 4
monitor only in the container (cgroup) called "name". This option is available only
in per\-cpu mode. The cgroup filesystem must be mounted. All threads belonging to
container "name" are monitored when they run on the monitored CPUs. Multiple cgroups
can be provided. Each cgroup is applied to the corresponding event, i.e., first cgroup
to first event, second cgroup to second event and so on. It is possible to provide
an empty cgroup (monitor all the time) using, e.g., \-G foo,,bar. Cgroups must have
corresponding events, i.e., they always refer to events defined earlier on the command
line. If the user wants to track multiple events for a specific cgroup, the user can
use \fI\-e e1 \-e e2 \-G foo,foo\fP or just use \fI\-e e1 \-e e2 \-G foo\fP.
.RE
.sp
\-\-all\-cgroups
.RS 4
Record events of type PERF_RECORD_CGROUP and display it with the
\fIcgroup\fP sort key.
.RE
.sp
\-\-switch\-on EVENT_NAME
.RS 4
Only consider events after this event is found.
.sp
.if n .RS 4
.nf
.fam C
E.g.:
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
Find out where broadcast packets are handled
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
perf probe \-L icmp_rcv
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
Insert a probe there:
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
perf probe icmp_rcv:59
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
Start perf top and ask it to only consider the cycles events when a
       broadcast packet arrives This will show a menu with two entries and
       will start counting when a broadcast packet arrives:
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
perf top \-e cycles,probe:icmp_rcv \-\-switch\-on=probe:icmp_rcv
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
Alternatively one can ask for a group and then two overhead columns
       will appear, the first for cycles and the second for the switch\-on event.
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
perf top \-e \*(Aq{cycles,probe:icmp_rcv}\*(Aq \-\-switch\-on=probe:icmp_rcv
.fam
.fi
.if n .RE
.sp
.if n .RS 4
.nf
.fam C
This may be interesting to measure a workload only after some initialization
phase is over, i.e. insert a perf probe at that point and use the above
examples replacing probe:icmp_rcv with the just\-after\-init probe.
.fam
.fi
.if n .RE
.RE
.sp
\-\-switch\-off EVENT_NAME
.RS 4
Stop considering events after this event is found.
.RE
.sp
\-\-show\-on\-off\-events
.RS 4
Show the \-\-switch\-on/off events too. This has no effect in \fIperf top\fP now
but probably we\(cqll make the default not to show the switch\-on/off events
on the \-\-group mode and if there is only one event besides the off/on ones,
go straight to the histogram browser, just like \fIperf top\fP with no events
explicitly specified does.
.RE
.sp
\-\-stitch\-lbr
.RS 4
Show callgraph with stitched LBRs, which may have more complete
callgraph. The option must be used with \-\-call\-graph lbr recording.
Disabled by default. In common cases with call stack overflows,
it can recreate better call stacks than the default lbr call stack
output. But this approach is not foolproof. There can be cases
where it creates incorrect call stacks from incorrect matches.
The known limitations include exception handing such as
setjmp/longjmp will have calls/returns not match.
.RE
.SH "INTERACTIVE PROMPTING KEYS"
.sp
[d]
.RS 4
Display refresh delay.
.RE
.sp
[e]
.RS 4
Number of entries to display.
.RE
.sp
[E]
.RS 4
Event to display when multiple counters are active.
.RE
.sp
[f]
.RS 4
Profile display filter (>= hit count).
.RE
.sp
[F]
.RS 4
Annotation display filter (>= % of total).
.RE
.sp
[s]
.RS 4
Annotate symbol.
.RE
.sp
[S]
.RS 4
Stop annotation, return to full profile display.
.RE
.sp
[K]
.RS 4
Hide kernel symbols.
.RE
.sp
[U]
.RS 4
Hide user symbols.
.RE
.sp
[z]
.RS 4
Toggle event count zeroing across display updates.
.RE
.sp
[qQ]
.RS 4
Quit.
.RE
.sp
Pressing any unmapped key displays a menu, and prompts for input.
.SH "OVERHEAD CALCULATION"
.sp
The overhead can be shown in two columns as \fIChildren\fP and \fISelf\fP when
perf collects callchains.  The \fIself\fP overhead is simply calculated by
adding all period values of the entry \- usually a function (symbol).
This is the value that perf shows traditionally and sum of all the
\fIself\fP overhead values should be 100%.
.sp
The \fIchildren\fP overhead is calculated by adding all period values of
the child functions so that it can show the total overhead of the
higher level functions even if they don\(cqt directly execute much.
\fIChildren\fP here means functions that are called from another (parent)
function.
.sp
It might be confusing that the sum of all the \fIchildren\fP overhead
values exceeds 100% since each of them is already an accumulation of
\fIself\fP overhead of its child functions.  But with this enabled, users
can find which function has the most overhead even if samples are
spread over the children.
.sp
Consider the following example; there are three functions like below.
.sp
.if n .RS 4
.nf
.fam C
void foo(void) {
    /* do something */
}

void bar(void) {
    /* do something */
    foo();
}

int main(void) {
    bar()
    return 0;
}
.fam
.fi
.if n .RE
.sp
In this case \fIfoo\fP is a child of \fIbar\fP, and \fIbar\fP is an immediate
child of \fImain\fP so \fIfoo\fP also is a child of \fImain\fP.  In other words,
\fImain\fP is a parent of \fIfoo\fP and \fIbar\fP, and \fIbar\fP is a parent of \fIfoo\fP.
.sp
Suppose all samples are recorded in \fIfoo\fP and \fIbar\fP only.  When it\(cqs
recorded with callchains the output will show something like below
in the usual (self\-overhead\-only) output of perf report:
.sp
.if n .RS 4
.nf
.fam C
Overhead\&  Symbol
\&........\&  .....................
  60.00%\&  foo
          |
          \-\-\- foo
              bar
              main
              __libc_start_main

  40.00%\&  bar
          |
          \-\-\- bar
              main
              __libc_start_main
.fam
.fi
.if n .RE
.sp
When the \-\-children option is enabled, the \fIself\fP overhead values of
child functions (i.e. \fIfoo\fP and \fIbar\fP) are added to the parents to
calculate the \fIchildren\fP overhead.  In this case the report could be
displayed as:
.sp
.if n .RS 4
.nf
.fam C
Children\&      Self\&  Symbol
\&........\&  ........\&  ....................
 100.00%\&     0.00%\&  __libc_start_main
          |
          \-\-\- __libc_start_main

 100.00%\&     0.00%\&  main
          |
          \-\-\- main
              __libc_start_main

 100.00%\&    40.00%\&  bar
          |
          \-\-\- bar
              main
              __libc_start_main

  60.00%\&    60.00%\&  foo
          |
          \-\-\- foo
              bar
              main
              __libc_start_main
.fam
.fi
.if n .RE
.sp
In the above output, the \fIself\fP overhead of \fIfoo\fP (60%) was add to the
\fIchildren\fP overhead of \fIbar\fP, \fImain\fP and \fI_\(rs_libc_start_main\fP.
Likewise, the \fIself\fP overhead of \fIbar\fP (40%) was added to the
\fIchildren\fP overhead of \fImain\fP and \fI\(rs_\(rs_libc_start_main\fP.
.sp
So \fI\(rs_\(rs_libc_start_main\fP and \fImain\fP are shown first since they have
same (100%) \fIchildren\fP overhead (even though they have zero \fIself\fP
overhead) and they are the parents of \fIfoo\fP and \fIbar\fP.
.sp
Since v3.16 the \fIchildren\fP overhead is shown by default and the output
is sorted by its values. The \fIchildren\fP overhead is disabled by
specifying \-\-no\-children option on the command line or by adding
\fIreport.children = false\fP or \fItop.children = false\fP in the perf config
file.
.SH "SEE ALSO"
.sp
perf\-stat(1), perf\-list(1), perf\-report(1)