callchain-overhead-calculation.txt 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. Overhead calculation
  2. --------------------
  3. The CPU overhead can be shown in two columns as 'Children' and 'Self'
  4. when perf collects callchains (and corresponding 'Wall' columns for
  5. wall-clock overhead). The 'self' overhead is simply calculated by
  6. adding all period values of the entry - usually a function (symbol).
  7. This is the value that perf shows traditionally and sum of all the
  8. 'self' overhead values should be 100%.
  9. The 'children' overhead is calculated by adding all period values of
  10. the child functions so that it can show the total overhead of the
  11. higher level functions even if they don't directly execute much.
  12. 'Children' here means functions that are called from another (parent)
  13. function.
  14. It might be confusing that the sum of all the 'children' overhead
  15. values exceeds 100% since each of them is already an accumulation of
  16. 'self' overhead of its child functions. But with this enabled, users
  17. can find which function has the most overhead even if samples are
  18. spread over the children.
  19. Consider the following example; there are three functions like below.
  20. -----------------------
  21. void foo(void) {
  22. /* do something */
  23. }
  24. void bar(void) {
  25. /* do something */
  26. foo();
  27. }
  28. int main(void) {
  29. bar()
  30. return 0;
  31. }
  32. -----------------------
  33. In this case 'foo' is a child of 'bar', and 'bar' is an immediate
  34. child of 'main' so 'foo' also is a child of 'main'. In other words,
  35. 'main' is a parent of 'foo' and 'bar', and 'bar' is a parent of 'foo'.
  36. Suppose all samples are recorded in 'foo' and 'bar' only. When it's
  37. recorded with callchains the output will show something like below
  38. in the usual (self-overhead-only) output of perf report:
  39. ----------------------------------
  40. Overhead Symbol
  41. ........ .....................
  42. 60.00% foo
  43. |
  44. --- foo
  45. bar
  46. main
  47. __libc_start_main
  48. 40.00% bar
  49. |
  50. --- bar
  51. main
  52. __libc_start_main
  53. ----------------------------------
  54. When the --children option is enabled, the 'self' overhead values of
  55. child functions (i.e. 'foo' and 'bar') are added to the parents to
  56. calculate the 'children' overhead. In this case the report could be
  57. displayed as:
  58. -------------------------------------------
  59. Children Self Symbol
  60. ........ ........ ....................
  61. 100.00% 0.00% __libc_start_main
  62. |
  63. --- __libc_start_main
  64. 100.00% 0.00% main
  65. |
  66. --- main
  67. __libc_start_main
  68. 100.00% 40.00% bar
  69. |
  70. --- bar
  71. main
  72. __libc_start_main
  73. 60.00% 60.00% foo
  74. |
  75. --- foo
  76. bar
  77. main
  78. __libc_start_main
  79. -------------------------------------------
  80. In the above output, the 'self' overhead of 'foo' (60%) was add to the
  81. 'children' overhead of 'bar', 'main' and '\_\_libc_start_main'.
  82. Likewise, the 'self' overhead of 'bar' (40%) was added to the
  83. 'children' overhead of 'main' and '\_\_libc_start_main'.
  84. So '\_\_libc_start_main' and 'main' are shown first since they have
  85. same (100%) 'children' overhead (even though they have zero 'self'
  86. overhead) and they are the parents of 'foo' and 'bar'.
  87. Since v3.16 the 'children' overhead is shown by default and the output
  88. is sorted by its values. The 'children' overhead is disabled by
  89. specifying --no-children option on the command line or by adding
  90. 'report.children = false' or 'top.children = false' in the perf config
  91. file.