xref: /openbmc/linux/tools/perf/Documentation/callchain-overhead-calculation.txt (revision e5451c8f8330e03ad3cfa16048b4daf961af434f)
1*dd309207SNamhyung KimOverhead calculation
2*dd309207SNamhyung Kim--------------------
3*dd309207SNamhyung KimThe overhead can be shown in two columns as 'Children' and 'Self' when
4*dd309207SNamhyung Kimperf collects callchains.  The 'self' overhead is simply calculated by
5*dd309207SNamhyung Kimadding all period values of the entry - usually a function (symbol).
6*dd309207SNamhyung KimThis is the value that perf shows traditionally and sum of all the
7*dd309207SNamhyung Kim'self' overhead values should be 100%.
8*dd309207SNamhyung Kim
9*dd309207SNamhyung KimThe 'children' overhead is calculated by adding all period values of
10*dd309207SNamhyung Kimthe child functions so that it can show the total overhead of the
11*dd309207SNamhyung Kimhigher level functions even if they don't directly execute much.
12*dd309207SNamhyung Kim'Children' here means functions that are called from another (parent)
13*dd309207SNamhyung Kimfunction.
14*dd309207SNamhyung Kim
15*dd309207SNamhyung KimIt might be confusing that the sum of all the 'children' overhead
16*dd309207SNamhyung Kimvalues exceeds 100% since each of them is already an accumulation of
17*dd309207SNamhyung Kim'self' overhead of its child functions.  But with this enabled, users
18*dd309207SNamhyung Kimcan find which function has the most overhead even if samples are
19*dd309207SNamhyung Kimspread over the children.
20*dd309207SNamhyung Kim
21*dd309207SNamhyung KimConsider the following example; there are three functions like below.
22*dd309207SNamhyung Kim
23*dd309207SNamhyung Kim-----------------------
24*dd309207SNamhyung Kimvoid foo(void) {
25*dd309207SNamhyung Kim    /* do something */
26*dd309207SNamhyung Kim}
27*dd309207SNamhyung Kim
28*dd309207SNamhyung Kimvoid bar(void) {
29*dd309207SNamhyung Kim    /* do something */
30*dd309207SNamhyung Kim    foo();
31*dd309207SNamhyung Kim}
32*dd309207SNamhyung Kim
33*dd309207SNamhyung Kimint main(void) {
34*dd309207SNamhyung Kim    bar()
35*dd309207SNamhyung Kim    return 0;
36*dd309207SNamhyung Kim}
37*dd309207SNamhyung Kim-----------------------
38*dd309207SNamhyung Kim
39*dd309207SNamhyung KimIn this case 'foo' is a child of 'bar', and 'bar' is an immediate
40*dd309207SNamhyung Kimchild of 'main' so 'foo' also is a child of 'main'.  In other words,
41*dd309207SNamhyung Kim'main' is a parent of 'foo' and 'bar', and 'bar' is a parent of 'foo'.
42*dd309207SNamhyung Kim
43*dd309207SNamhyung KimSuppose all samples are recorded in 'foo' and 'bar' only.  When it's
44*dd309207SNamhyung Kimrecorded with callchains the output will show something like below
45*dd309207SNamhyung Kimin the usual (self-overhead-only) output of perf report:
46*dd309207SNamhyung Kim
47*dd309207SNamhyung Kim----------------------------------
48*dd309207SNamhyung KimOverhead  Symbol
49*dd309207SNamhyung Kim........  .....................
50*dd309207SNamhyung Kim  60.00%  foo
51*dd309207SNamhyung Kim          |
52*dd309207SNamhyung Kim          --- foo
53*dd309207SNamhyung Kim              bar
54*dd309207SNamhyung Kim              main
55*dd309207SNamhyung Kim              __libc_start_main
56*dd309207SNamhyung Kim
57*dd309207SNamhyung Kim  40.00%  bar
58*dd309207SNamhyung Kim          |
59*dd309207SNamhyung Kim          --- bar
60*dd309207SNamhyung Kim              main
61*dd309207SNamhyung Kim              __libc_start_main
62*dd309207SNamhyung Kim----------------------------------
63*dd309207SNamhyung Kim
64*dd309207SNamhyung KimWhen the --children option is enabled, the 'self' overhead values of
65*dd309207SNamhyung Kimchild functions (i.e. 'foo' and 'bar') are added to the parents to
66*dd309207SNamhyung Kimcalculate the 'children' overhead.  In this case the report could be
67*dd309207SNamhyung Kimdisplayed as:
68*dd309207SNamhyung Kim
69*dd309207SNamhyung Kim-------------------------------------------
70*dd309207SNamhyung KimChildren      Self  Symbol
71*dd309207SNamhyung Kim........  ........  ....................
72*dd309207SNamhyung Kim 100.00%     0.00%  __libc_start_main
73*dd309207SNamhyung Kim          |
74*dd309207SNamhyung Kim          --- __libc_start_main
75*dd309207SNamhyung Kim
76*dd309207SNamhyung Kim 100.00%     0.00%  main
77*dd309207SNamhyung Kim          |
78*dd309207SNamhyung Kim          --- main
79*dd309207SNamhyung Kim              __libc_start_main
80*dd309207SNamhyung Kim
81*dd309207SNamhyung Kim 100.00%    40.00%  bar
82*dd309207SNamhyung Kim          |
83*dd309207SNamhyung Kim          --- bar
84*dd309207SNamhyung Kim              main
85*dd309207SNamhyung Kim              __libc_start_main
86*dd309207SNamhyung Kim
87*dd309207SNamhyung Kim  60.00%    60.00%  foo
88*dd309207SNamhyung Kim          |
89*dd309207SNamhyung Kim          --- foo
90*dd309207SNamhyung Kim              bar
91*dd309207SNamhyung Kim              main
92*dd309207SNamhyung Kim              __libc_start_main
93*dd309207SNamhyung Kim-------------------------------------------
94*dd309207SNamhyung Kim
95*dd309207SNamhyung KimIn the above output, the 'self' overhead of 'foo' (60%) was add to the
96*dd309207SNamhyung Kim'children' overhead of 'bar', 'main' and '\_\_libc_start_main'.
97*dd309207SNamhyung KimLikewise, the 'self' overhead of 'bar' (40%) was added to the
98*dd309207SNamhyung Kim'children' overhead of 'main' and '\_\_libc_start_main'.
99*dd309207SNamhyung Kim
100*dd309207SNamhyung KimSo '\_\_libc_start_main' and 'main' are shown first since they have
101*dd309207SNamhyung Kimsame (100%) 'children' overhead (even though they have zero 'self'
102*dd309207SNamhyung Kimoverhead) and they are the parents of 'foo' and 'bar'.
103*dd309207SNamhyung Kim
104*dd309207SNamhyung KimSince v3.16 the 'children' overhead is shown by default and the output
105*dd309207SNamhyung Kimis sorted by its values. The 'children' overhead is disabled by
106*dd309207SNamhyung Kimspecifying --no-children option on the command line or by adding
107*dd309207SNamhyung Kim'report.children = false' or 'top.children = false' in the perf config
108*dd309207SNamhyung Kimfile.
109