Path: blob/master/tools/perf/Documentation/callchain-overhead-calculation.txt
26282 views
Overhead calculation1--------------------2The CPU overhead can be shown in two columns as 'Children' and 'Self'3when perf collects callchains (and corresponding 'Wall' columns for4wall-clock overhead). The 'self' overhead is simply calculated by5adding all period values of the entry - usually a function (symbol).6This is the value that perf shows traditionally and sum of all the7'self' overhead values should be 100%.89The 'children' overhead is calculated by adding all period values of10the child functions so that it can show the total overhead of the11higher level functions even if they don't directly execute much.12'Children' here means functions that are called from another (parent)13function.1415It might be confusing that the sum of all the 'children' overhead16values exceeds 100% since each of them is already an accumulation of17'self' overhead of its child functions. But with this enabled, users18can find which function has the most overhead even if samples are19spread over the children.2021Consider the following example; there are three functions like below.2223-----------------------24void foo(void) {25/* do something */26}2728void bar(void) {29/* do something */30foo();31}3233int main(void) {34bar()35return 0;36}37-----------------------3839In this case 'foo' is a child of 'bar', and 'bar' is an immediate40child of 'main' so 'foo' also is a child of 'main'. In other words,41'main' is a parent of 'foo' and 'bar', and 'bar' is a parent of 'foo'.4243Suppose all samples are recorded in 'foo' and 'bar' only. When it's44recorded with callchains the output will show something like below45in the usual (self-overhead-only) output of perf report:4647----------------------------------48Overhead Symbol49........ .....................5060.00% foo51|52--- foo53bar54main55__libc_start_main565740.00% bar58|59--- bar60main61__libc_start_main62----------------------------------6364When the --children option is enabled, the 'self' overhead values of65child functions (i.e. 'foo' and 'bar') are added to the parents to66calculate the 'children' overhead. In this case the report could be67displayed as:6869-------------------------------------------70Children Self Symbol71........ ........ ....................72100.00% 0.00% __libc_start_main73|74--- __libc_start_main7576100.00% 0.00% main77|78--- main79__libc_start_main8081100.00% 40.00% bar82|83--- bar84main85__libc_start_main868760.00% 60.00% foo88|89--- foo90bar91main92__libc_start_main93-------------------------------------------9495In the above output, the 'self' overhead of 'foo' (60%) was add to the96'children' overhead of 'bar', 'main' and '\_\_libc_start_main'.97Likewise, the 'self' overhead of 'bar' (40%) was added to the98'children' overhead of 'main' and '\_\_libc_start_main'.99100So '\_\_libc_start_main' and 'main' are shown first since they have101same (100%) 'children' overhead (even though they have zero 'self'102overhead) and they are the parents of 'foo' and 'bar'.103104Since v3.16 the 'children' overhead is shown by default and the output105is sorted by its values. The 'children' overhead is disabled by106specifying --no-children option on the command line or by adding107'report.children = false' or 'top.children = false' in the perf config108file.109110111