callchain-overhead-calculation.txt 3.3 KB

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